AutomoxAutomox

Is it possible to create a worklet to restart the Automox agent

mscro
May 20, 2020 at 4:03 pm UTC

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

This discussion is archived and closed to replies. Continue it in the Automox Community Slack.

Discuss on Slack

Replies (5)

Jarod-AutomoxMay 20, 2020
#1

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 &

mscroMay 20, 2020
#2

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.

cgreggoMay 20, 2020
#3

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.

mscroMay 20, 2020
#4

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.

daniel.newmanJune 7, 2023
#5

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.