# 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]
# This unit starts early in system lifecycle to set up nut-driver instances.
# End-user may also restart this unit after editing ups.conf to automatically
# un-register or add new instances as appropriate.
Description=Network UPS Tools - enumeration of configure-file devices into systemd unit instances
After=local-fs.target
Before=nut-driver.target
PartOf=nut.target

[Service]
### Script needs privileges to restart units
#User=nut
#Group=nut
User=root
SyslogIdentifier=%N
# it is expected that the process has to exit before systemd starts follow-up
# units; it should not be a problem for those
Type=oneshot
# Currently systemd does not support restarting of oneshot services, and does
# not seem to guarantee that other services would only start after the script
# completes, for a non-oneshot case. The script itself handles restarting of
# nut-server which is the primary concerned dependency at the moment, so we
# don't want it to fail the unit (when it can't restart).
Environment=REPORT_RESTART_42=no
EnvironmentFile=-/etc/nut/nut.conf
ExecStartPre=-/usr/bin/systemd-tmpfiles --create /usr/lib/tmpfiles.d/nut-common-tmpfiles.conf
ExecStart=/usr/lib/nut/nut-driver-enumerator.sh
ExecReload=/usr/lib/nut/nut-driver-enumerator.sh

[Install]
WantedBy=nut.target
