Is it possible to create a worklet to restart the Automox agent without throwing the agent service into a loop? The below code won’t stop exicuting a stop and start of the agent.
Evaluation:
Exit 1
Remediation:
Restart-Service amagent
Is it possible to create a worklet to restart the Automox agent without throwing the agent service into a loop? The below code won’t stop exicuting a stop and start of the agent.
Evaluation:
Exit 1
Remediation:
Restart-Service amagent
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 &
Thanks Jarod, I was worried about entering a black hole. Just looking to be able to restart an agent that was hung without end user involvement.
What are the symptoms of a “hung” agent that you consider responsive enough to accept this worklet? I read “hung” as an agent that refuses any/all commands.
Once in a while an end user device will hang in a scanning status and restarting the agent will reset the status and everything will be fine going forward. I wanted to avoid engaging the end user. Previously I have also contacted support for an unresponsive agent, but would like to attempt this as a first step.
Can I go a step farther, is there a way to restart the AUTOMOX Service via local GPO on Windows, and something else on Mac, to ensure the device service gets restarted/started weekly.
No account yet? Create an account
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.