# Network UPS Tools (NUT) systemd integration
# Copyright (C) 2011-2023 by NUT contirbutors
# Distributed under the terms of GPLv2+
# See https://networkupstools.org/
# and https://github.com/networkupstools/nut/

[Unit]
Description=Network UPS Tools - power device monitor and shutdown controller
# Note: do not mistake this historic misnomer for "NUT-Monitor" Python GUI client
After=local-fs.target network.target nut-server.service
# Note: We do not specify Requires nut-server.service because
# the `upsd` daemon(s) may be running on a different machine
# (connected to the UPSes) than the `upsmon` shutdown protector.
# The "Wants" directive would try to start the nut-server but
# would not abort if that attempt fails for whatever reason.
Wants=nut-server.service
# Extending the unit does not require *this* file to be edited, you
# can instead drop in an additional piece of configuration, e.g. to
# require the monitoring client to only start after external networking
# is configured (usable IP addresses appear in the system) you can
# add a `/etc/systemd/system/nut-monitor.service.d/network.conf` with:
#   [Unit]
#   Requires=network-online.target
#   After=network-online.target
PartOf=nut.target

[Service]
EnvironmentFile=-/etc/nut/nut.conf
SyslogIdentifier=%N
ExecStartPre=-/usr/bin/systemd-tmpfiles --create /usr/lib/tmpfiles.d/nut-common-tmpfiles.conf
ExecStart=/usr/bin/upsmon -F
ExecReload=/usr/bin/upsmon -c reload
PIDFile=/run/nut/upsmon.pid
# If "-FF" or background-daemon mode is used, so that PID file exists
# and "upsmon -c stop" in particular can be used from command-line or
# legacy scripts, it causes a clean and intentional exit of the daemon.
# Then systemd should not revive it - hence restart it only on failure:
Restart=on-failure
Type=notify
#WatchdogSec=240s
NotifyAccess=all

[Install]
WantedBy=nut.target
Alias=upsmon.service
