Yes, it is possible (and I’ll make sure to give my default warning here, agent doing things to itself via worklets can be tricky - make sure it’s really what you want to do). The issue is that if you just send down the reboot command, the agent reboots itself before responding to the command (this is by design, so that we make sure we finish a command). To accomplish this you need to background the reboot command. For Windows, I’ve done this:
Start-Process powershell -Verb RunAs -ArgumentList { Start-Sleep -Seconds 5; Restart-Service amagent }
It backgrounds a short sleep followed by a restart, so the main command completes before the restart-service triggers. MacOS looks like
#!/bin/bash
( sleep 5; killall amagent; ) &
And linux can either be simpler or more complicated, depending on how thorough you want to be 🙂 The following checks for systemd and runs a backgrounded command
#!/bin/bash
if ps --no-headers -o comm 1 | grep --quiet systemd; then
systemd-run --on-active=5 systemctl restart amagent
else
sleep 5
service amagent restart
fi &