# 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 devices information server
After=local-fs.target network.target nut-driver.target
# We don't Require drivers to be successfully started! This would be
# a change of behavior compared to init SysV, and could prevent from
# accessing successfully started, at least to audit a system.
Wants=nut-driver.target
# The `upsd` is a networked service (even if bound to a `localhost`)
# so it requires that the OS has some notion of networking already.
# 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 that NUT data server only starts after external networking
# is configured (usable IP addresses appear in the system) you can
# add a `/etc/systemd/system/nut-server.service.d/network.conf` with:
#   [Unit]
#   Requires=network-online.target
#   After=network-online.target
Requires=network.target
Before=nut-monitor.service
PartOf=nut.target

[Service]
EnvironmentFile=-/etc/nut/nut.conf
SyslogIdentifier=%N
# Note: foreground mode "-F" by default skips writing a PID file (and
# needs default Type=simple); we can use "-FF" here to create the file
# anyway, so that old "upsd -c reload" works rather than systemd action:
ExecStartPre=-/usr/bin/systemd-tmpfiles --create /usr/lib/tmpfiles.d/nut-common-tmpfiles.conf
ExecStart=/usr/bin/upsd -FF
ExecReload=/usr/bin/upsd -c reload -P $MAINPID
# No tracking for PIDFile path and service attribute here (it might not
# even exist).
# If "-FF" or background-daemon mode is used, so that PID file exists
# and "upsd -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=main

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