Skip to content
Agent/Uninstall the agent

Agent

Uninstall the agent

One command to take the agent off a host, and what it clears up.

One command takes the agent off a host and clears up after it. It works on Debian-based servers — Debian, Ubuntu, Linux Mint, Kali, Raspberry Pi OS (64-bit), and the like:

$curl -sSf https://monilogix.jpjapos.com/uninstall.sh | sh

On a terminal it shows you exactly what it is about to delete and waits for you to type yes. Piped into a shell with no terminal — Ansible, cloud-init, a loop over SSH — it goes ahead, because running it that way is itself the instruction.

This removes the agent key stored in /etc/monilogix/config.yaml. To keep it, so that reinstalling later picks the same key back up, use --keep-config.

What it removes

  • the monilogix-agent package, and with it the binary and the systemd unit — the package stops and disables the service itself before it goes
  • /etc/monilogix/config.yaml, and anything else left in /etc/monilogix
  • the monilogix-reader user and its group — the unprivileged account host access runs commands as
  • systemd drop-ins at /etc/systemd/system/monilogix-agent.service.d, and a dangling enable symlink if one was left behind

Why not just apt purge

You can, and most of the time it is enough. But apt purge is not quite a clean removal, in two ways that are both silent.

The package finishes by trying to remove /etc/monilogix with rmdir, which only works on an empty directory and whose failure is discarded. So if anything else is in there, the directory and its contents survive a purge that reported success. The file most likely to be in there is /etc/monilogix/.env.dpkg-bak: agents up to 0.1.0 kept database credentials in an .env beside the config, and when that file had been edited by hand, dpkg preserved it under that name rather than destroying an admin's work. Nothing has ever removed it since.

The second is the monilogix-reader account. The package removes it on purge, but treats a failure as a warning, and it never looks at the group separately from the user — so either can outlive the package. The script checks both, and says so when it cannot remove one.

It also tells you what it could not do, which is the part no sequence of commands does for you.

Keeping the config

--keep-config removes the package but leaves /etc/monilogix/config.yaml and the monilogix-reader user alone. That is an apt remove rather than a purge:

$curl -sSf https://monilogix.jpjapos.com/uninstall.sh | sh -s -- --keep-config

Reinstalling on that host later keeps the key that is already there and asks you nothing, which is what makes this the right choice for moving a box between agent releases or rebuilding around it.

A kept config is not a clean slate. If it carries host_access_enabled, installing a release older than 0.4.0 on that host afterwards is refused before anything is downloaded — that agent's parser does not know the setting and would install and then fail to start. See Flags and settings.

Options

As with the installer, options are passed through to the script with -s --, because piped to a shell they belong to sh rather than to curl.

OptionWhat it does
--keep-configRemove the package but keep the config file and the monilogix-reader user — apt-get remove rather than purge. Reinstalling later picks the same agent key back up, which also means the key stays on disk. Without this, everything goes.
-y
--yes
Do not ask for confirmation. Without it, and with a terminal to ask on, you are shown exactly what will be deleted and have to type yes. With no terminal the script goes ahead either way — piping it into a shell is the instruction.
--quietPrint progress but not the commands and their output. For fleet rollbacks and image builds, where nobody reads the log.
-v
--verbose
Trace every shell command as well (set -x), for when you are debugging the uninstaller itself.
--help
-h
Print the options and exit, changing nothing. Every error the uninstaller prints ends by suggesting it.

Reading it before you run it

This is the destructive one, and it runs as root. Download it, read it, then run it:

$curl -sSfO https://monilogix.jpjapos.com/uninstall.sh$less uninstall.sh$sh uninstall.sh

Doing it by hand

Nothing in the script is magic. This is the same work, in the order it does it:

$sudo apt purge -y monilogix-agent$sudo rm -f /etc/monilogix/.env.dpkg-bak /etc/monilogix/config.yaml.dpkg-*$sudo rm -rf /etc/systemd/system/monilogix-agent.service.d$sudo rmdir /etc/monilogix$sudo userdel monilogix-reader; sudo groupdel monilogix-reader$sudo systemctl daemon-reload

The rmdir will fail if anything unexpected is still in /etc/monilogix — look at what is there before reaching for rm -rf.

What uninstalling does not do

It does not delete your box. The script only ever touches the host it runs on: it never calls the Monilogix API and never uses the agent key. Your box stays in the dashboard and starts showing as not reporting. Deleting it there is what removes it and its stored metrics.

It does not clear the journal. journald has no way to delete one unit's logs, so whatever monilogix-agent wrote stays until the journal rotates on age or size, and journalctl -u monilogix-agent keeps finding it until then.

It leaves shared packages alone. The agent depends on ca-certificates, which almost everything else on a server also uses. Nothing here removes it, and there is no autoremove anywhere in the script.

Putting the agent back is one command — Install the agent. If what you actually want is a newer version, you do not need to uninstall anything first: Update the agent is the install command again.