Run P2PMon as a service
Table of Contents
The same binary is run on every node; only the supervisor differs per OS.
In each case the license file (p2pmon.lic next to the binary, or pointed
to by P2PMON_LICENSE) must be in place before the service is started, and
the binary match should be confirmed with p2pmon fingerprint. Upgrades are
handled by the built-in binary auto-update — the daemon stages the new
versioned binary and execs into it, so no manual restart is needed.
Linux (systemd) #
/etc/systemd/system/p2pmon.service:
[Unit]
Description=P2PMon peer-to-peer infrastructure monitoring (Aidoneus Labs)
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=p2pmon
Group=p2pmon
ExecStart=/opt/p2pmon/p2pmon.Linux-x86_64
EnvironmentFile=-/etc/p2pmon/p2pmon.env
Restart=always
RestartSec=5
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
Enabled with systemctl enable --now p2pmon. The license file is secured
with install -o p2pmon -g p2pmon -m 600 p2pmon.lic /opt/p2pmon/p2pmon.lic;
optional P2PMON_* overrides are placed in /etc/p2pmon/p2pmon.env.
macOS (launchd) #
/Library/LaunchDaemons/com.aidoneuslabs.p2pmon.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.aidoneuslabs.p2pmon</string>
<key>ProgramArguments</key>
<array>
<string>/opt/p2pmon/p2pmon.Darwin-arm64</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>P2PMON_LICENSE</key>
<string>/opt/p2pmon/p2pmon.lic</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/var/log/p2pmon.log</string>
<key>StandardErrorPath</key>
<string>/var/log/p2pmon.log</string>
</dict>
</plist>
Loaded with launchctl bootstrap system /Library/LaunchDaemons/com.aidoneuslabs.p2pmon.plist.
FreeBSD (rc.d) #
/usr/local/etc/rc.d/p2pmon (executable), with p2pmon_enable="YES" added
to /etc/rc.conf:
#!/bin/sh
#
# PROVIDE: p2pmon
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="p2pmon"
rcvar="p2pmon_enable"
load_rc_config "$name"
: "${p2pmon_enable:=NO}"
: "${p2pmon_program:=/opt/p2pmon/p2pmon.FreeBSD-x86_64}"
: "${p2pmon_log:=/var/log/p2pmon.log}"
command="/usr/sbin/daemon"
command_args="-r -o ${p2pmon_log} -t p2pmon ${p2pmon_program}"
export ${p2pmon_env}
run_rc_command "$1"
Extra environment (e.g. P2PMON_LICENSE) is passed via p2pmon_env in
rc.conf. Supervision and restart are provided by daemon(8).
Windows (NSSM) #
NSSM is the recommended supervisor (install.bat):
set BINARY=C:\p2pmon\p2pmon.Windows-x86_64.exe
set LIC=C:\p2pmon\p2pmon.lic
nssm install p2pmon "%BINARY%"
nssm set p2pmon AppDirectory C:\p2pmon
nssm set p2pmon AppEnvironmentExtra P2PMON_LICENSE=%LIC%
nssm set p2pmon Start SERVICE_AUTO_START
nssm start p2pmon
Run in an elevated prompt with NSSM on PATH. Without third-party tools,
sc.exe create plus a Task Scheduler trigger can be used instead, with
poorer failure recovery.
Windows caveats documented for the release: a running .exe cannot be
renamed in place, so self-upgrade leaves the version-stamped file on disk
and executes it; shell user scripts need WSL (P2PMON_WSL_DISTRO), otherwise
scripts must be .bat/.ps1/.exe; syslog forwarding is a no-op.