A lightweight service manager that monitors itself using crond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
diamondburned d3b71cc437 Replace Jenkins with Drone 8 months ago
cronmon Better monitor.removeFile message 8 months ago
.drone.yml Replace Jenkins with Drone 8 months ago
LICENSE.md Initial commit - draft design 8 months ago
README.md Different mechanism, README update, mostly working 8 months ago
go.mod Removed unused code, fixed tests 8 months ago
go.sum Removed unused code, fixed tests 8 months ago
main.go Minor cleanup tweaks, log to stderr instead of stdout 8 months ago

README.md

cronmon

A lightweight service manager that monitors itself using crond. Designed to be used where a service manager is not available.

Differences vs. Other Monitors

  • Cron-based.
  • Simple service file syntax (there's none).
  • Easily statically compiled (CGO_ENABLED=0 go build).

For a detailed explanation of how cronmon works exactly, see its documentation.

Compatibility

Cronmon uses two features that makes it only work on Linux: (syscall.SysProcAttr).Pdeathsig and PR_SET_CHILD_SUBREAPER. The usage of these two features are documented in the above documentation.

Installation

  1. Install cronmon: go install git.unix.lgbt/diamondburned/cronmon.
  2. Edit crontab: crontab -e.
  3. Add cronmon into the cron file.

Cron File

A cron file can be generated by running cronmon cron. Below is a simple example:

# Start cronmon immediately on startup.
@reboot /tmp/cronmon
# Monitor cronmon's status every minute.
* * * * * /tmp/cronmon

This cron file will launch cronmon with the journal file pointing to ~/.config/cronmon/journal.json and the scripts (service) directory pointing to ~/.config/cronmon/scripts/.

Service File Example

$ # Shell script example.
$ cat <<'EOF' > ~/.cronmon/scripts/sysmetd.sh
#!/bin/sh
exec sysmet -flag "$shell_env" -listen unix:///tmp/a.sock
EOF
$ chmod +x ~/.cronmon/scripts/sysmetd.sh
$
$ # Executable example.
$ wget -O ~/.cronmon/scripts/example https://dodgy.site/executable
$ chmod +x ~/.cronmon/scripts/example

New service files will automatically be executed, and old service files that are updated will automatically restart the process. Removing a service file will stop the process. Removing the executable bit from a file (chmod -x) makes cronmon stop the process as well. Adding back the bit (chmod +x) makes it start the process again.