# Network UPS Tools (NUT) systemd integration
# Copyright (C) 2025- by NUT contributors
# Distributed under the terms of GPLv2+
# See https://networkupstools.org/
# and https://github.com/networkupstools/nut/
#
# This file was adapted from systemd-udev-settle.service provided as part of
# systemd. The original service is no longer recommended for general use in
# recent distributions (does not guarantee reliable detection, and delays
# system readiness for log-in), but waiting for udev to settle its currently
# running operations has proven useful in some cases for NUT practice.
#
# Original file's terms:
#
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This service can dynamically be pulled-in by legacy services which
# cannot reliably cope with dynamic device configurations, and wrongfully
# expect a populated /dev during bootup.

[Unit]
Description=Wait for udev To Complete Device Initialization before USB-capable NUT drivers start
Documentation=man:systemd-udev-settle.service(8)
DefaultDependencies=no
Wants=systemd-udevd.service
After=systemd-udev-trigger.service
ConditionPathIsReadWrite=/sys

# Used when/if requested by specific nut-driver@.service instances.
# No auto-start or dependency otherwise.

[Service]
Type=oneshot
TimeoutSec=180
# We want to re-trigger this service during NUT driver restarts
# (maybe several at once) as we reconnect after e.g. USB bus reset,
# for changes in USB/Serial/... devices that may need permissions
# for NUT to be applied. So we do not want it to remain "active".
#RemainAfterExit=yes
ExecStart=udevadm settle
