Use target for drivers in Linux systemd (updated) and SMF instances for drivers in new Solaris-like systems (and bring AIX initscript into better shape)#330
Conversation
7120d93 to
85344f3
Compare
|
@aquette pointed out a user-experience problem with this approach, which can be solved technically:
So indeed such an action might be done as an ExecStartPre= handler for example, or even as another unit to depend on (which might be more easily disabled or masked by the end-user, if not desired). |
|
@jimklimov , you probably want to look into generators at least for systemd instead of your man 7 systemd.generatorAlso, the recommended way to deal with the So in [Unit]
Requires=network-online.target
After=network-online.target |
|
@peterhoeg : Thanks for the hints, especially about https://www.freedesktop.org/software/systemd/man/systemd.generator.html However I am not sure it is a good match for this use-case, due to this:
One application of NUT in an internal project of ours is for embedded systems, and this regular re-generation and removal of files will cause needless wear on the flash storage. Also if But the script is already mostly there in this PR, I just expect to wrap it into a separate unit that may be enabled or disabled as the end-user would desire :) |
|
@jimklimov, the generators should not dump data under You can of course achieve the same with the |
|
@aquette : I revised the newly added script, adding a standard copyright header in particular - can you please review if it is OK this way? |
ae5fdf0 to
b323fe3
Compare
|
Rebased over today's master to take advantage of new Travis CI integration. |
7f89bb7 to
02f951c
Compare
6f7a4ea to
9c9530c
Compare
9c9530c to
2d0f3e0
Compare
|
This had to step beyond original system scope to ensure the solution core can reasonably adapt to different service frameworks. Then to ensure I can install it in those other systems :) Now this codebase should be at least testable, so please give it a go to check if it does what's intended, in the end :) |
|
Currently found caveats that might be solved later but require considerable effort:
|
|
Adding to my previous comment, it currently seems reasonable to provide the section-name conversion routines in NUT common code (e.g. config parser) so tools like upsdrvctl can be called to generate the base64 string, as well as all tools can interpret it as identification of a config section, local or remote monitored NUT device, etc. Also, service instances created and tracked by the enumeration script should include somewhere the copy or hash of configuration variables used when the service instance was created - e.g. if the driver or even port value was changed for the same-named section, we may have new dependencies to track for service management (destroy and recreate the nut-driver unit instance). |
199e854 to
86dd144
Compare
|
Rebased over current master branch state today |
86dd144 to
8df66ad
Compare
|
I've played with several package (re-)installation scenarios, finding ways to make the procedure robust. Hopefully struck the balance at least for Solaris-like systems (OpenIndiana actually). |
…s if key was found, or report an error if not
…ting out the section contents
aquette
left a comment
There was a problem hiding this comment.
Good to go for 2.7.5, with the minor fix on configure.ac/in
| @@ -139,21 +139,28 @@ setver: | |||
| @echo "Error: 'make setver' no longer exists." | |||
| @echo "Edit configure.in to set version number." | |||
…s of code consistently
…tions of existing sections currently
…or drivers in new Solaris-like systems (and bring AIX initscript into better shape) (networkupstools#330) * Use target for drivers in systemd This allows much better granularity and better monitoring in case of multiple UPSes. * nut-driver.target improvements suggested by @peterhoeg in PR#229 * systemd units dependencies revised and commented * nut-driver-enumerator.sh initial commit * nut-driver@.service.in : integrate comments from @peterhoeg about extending unit requirements * WIP : initial integration of nut-driver-enumerator.sh/service into makefiles etc. * nut-driver-enumerator.sh renamed into nut-driver-enumerator.sh.in as it has processable templates in code * nut-driver-enumerator.sh.in : add its own config-file support to set the variables used inside (if not via command-line env) * nut-driver-enumerator.sh.in : fix up the copyright header * Subject: Fix systemd service file for Debian From: Laurent Bigonville <bigon@debian.org> Forwarded: not-needed * nut-driver-enumerator.sh.in : complete the Solaris SMF support in the helper script * EXTRA_DIST the scripts/systemd/nut-driver.target (non-templated) file * nut-driver-enumerator.sh.in : updated comments (esp. about usage and exit-codes) and runtime messages * nut-driver-enumerator.service.in : define an actual service payload * nut-driver-enumerator.sh.in : refactor the logic of MAIN PROGRAM into smaller routines for readability * nut-driver-enumerator.sh.in : introduce routines to help define custom dependencies of particular drivers on other services * nut-driver-enumerator.sh.in : allow custom NUT_CONF_DIR from envvar, to facilitate testing * nut-server.service.in : typo fix in comments * nut-driver-enumerator.sh.in : support the concept of localhost networking dependencies, and define vars with lists of services to depend on * nut-driver-enumerator.sh.in : use proper FMRI:instance separator for SMF * nut-driver-enumerator.sh.in : added variables for dependency type on third-party service units * nut-driver-enumerator.sh.in : change upsconf_getDriverMedia() output from tab-separated to multiline; add upsconf_getMedia() and upsconf_debug() and upslist_debug() * nut-driver-enumerator.sh.in : refactor with upsconf_getValue() and cached pre-cooked ups.conf data; infrastructure to configure service dependencies when adding the service instance * Remove hardcoded dependencies on udev and network from provided systemd units; add comments about extending via drop-in files and that nut-driver-enumerator will do this for nut-drivers * nutshutdown.in : mark executable * nut-driver-enumerator.sh.in : complete the systemd drop-in support for custom dependencies for a driver * nut-driver-enumerator.sh.in : complete the SMF drop-in support for custom dependencies for a driver * nut-driver-enumerator.sh.in : comment-away upslist_debug() in default runs * WIP Adding Solaris SMF manifests for NUT * Sanitize Solaris SVR4 packaging rules * Sanitize Solaris packaging scripts some more * Add configure options for Solaris packaging variants * Sanitize Solaris packaging scripts some more - consider DESTDIR for installation root * Turn solaris preproto.pl into a template so it uses proper (configured) user/group strings * Makefile.am : ensure there is a DESTDIR set before packaging * Makefile.am : use $(MAKE) $(AM_MAKEFLAGS) instead of explicit "make" (mostly in packaging recipe) * makelocal.sh : commented and revised * Solaris/Makefile.am : put generated SVR4 package into builddir (not srcdir that may be readonly) to match other OS recipes * Makefile.am : ensure the DESTDIR is used for packaging purposes (when calling sub-makes) * Solaris/pkginfo.in : ARCH is CPU_TYPE, not OS_NAME * GitIgnore built Solaris/NUT*.local.gz product * GitIgnore built systemd files * GitIgnore _install_pkgprotodir * Makefile.am : ensure only the custom DESTDIR is used for packaging purposes * Makefile.am : convert the big packaging "if" into "case"; link steps with "&&"; retain DESTDIR if Solaris packaging fails; ensure the correct custom DESTDIR is absent before packaging (and after Solaris packaging) * Solaris/Makefile.am : Revise recipe-names and comments for Solaris packaging variants * Solaris/Makefile.am and *.xml.in : relocate SMF methods and manifests under NUT DATADIR to package compactly * Solaris-SMF : svc-nut.in svc-nut-client.in : use @RUN_AS_*@ and @PIDPATH@ vars instead of hardcoding * Solaris/Makefile.am : list helper scripts and installation scripts and data in variables and depend on them in packaging; chmod +x the scripts after copying over to proto area * GitIgnore config.cache * Remove Solaris/prepackage.py (unreferenced duplicate of precheck.py) * Solaris/nut.in : sanitize the default init-script * Solaris/Makefile.am : put init-scripts under NUT share (DATADIR) to package it compactly; copy to OS dirs in postinstall * Makefile.am .gitignore etc. relocate successfully built package files to abs_top_builddir * Change Aix/nut.init to a .in template * svc-nut.in svc-nut-client.in : consider nut.conf if available * Solaris/Makefile.am and SVR4 scripts : install augeas lenses as part of NUT package (in DATADIR at least) * configure.ac : comment about sysconfdir for NUT * Sanitize Aix/nut.init.in * More standardization of Solaris initscripts and SMF methods; use LD_LIBRARY_PATH to prefer NUT provided libs in case of conflicts (facilitate bundling with third-party packages) * Solaris/Makefile.am : add ability to "make check" something here, e.g. validate manifest XMLs * Solaris SMF XML manifests : fix "dependent" definitions, and add dependencies on required config files * configure.ac : fix a manually crafted "Checking for" into using AC_MSG routines * Solaris SVR4 packaging should now take care of SMF service registration/teardown * Solaris preremove.in postinstall.in : Usage of @datadir@ caused "${prefix}" strings to pop up - define the vars * Solaris scripts : use lower-cased @datadir@ in templates processed by configure * Solaris/preremove.in : fix FMRI pattern when removing package * Solaris/postinstall.in : fix SMF manifest dir * Solaris/postremove.in : fix verbose RM; wipe the /var/run/nut dir too * Solaris/preremove.in : fix commands when removing package * Solaris/postinstall.in : enable SMF services if configs are already available (esp. create nut-driver instances) * Solaris/preremove.in : fix commands when removing package * Solaris/postinstall.in : enable SMF services if configs are already available (esp. create nut-driver instances) - verbosity * Solaris/nut-driver-enumerator.xml.in : use a unique dependency name (avoid conflict in nut-driver instances chain of deps) * systemd and Solaris : fix up embedded ${prefix} in service files and SMF manifests after generation * systemd/README : add recent authors * Define a NUT_DATADIR and NUT_LIBEXECDIR with expanded path values to use in service manifests * Solaris : packaged service addition/removal more verbose * nut-driver-enumerator.xml.in nut-driver.xml.in : do not block startup of nut server * nut.xml.in : do not block startup of nut server due to failed nut-driver-enumerator * nut-driver-enumerator.sh.in : improve portability by using TAB char as is (not regex \t which gets misinterpreted by some tools) * nut-driver-enumerator.sh.in : comment the caveats * nut-driver-enumerator.sh.in : apcsmart is serial only * nut-driver-enumerator.sh.in : By default, update wrapping of devices into services... but keep the door open to other uses of the script * nut-driver-enumerator.sh.in : refactor a bit and add externally callable actions * Introduce upsdrvsvcctl with semantics similar to upsdrvctl, but managing stop/start of SMF or systemd unit instances * nut-driver-enumerator.sh.in : consider possible difference of device and service instance names * nut-driver-enumerator.sh.in : refactor md5 * nut-driver-enumerator.xml.in : add REFRESH action and do not die on RESTART * Mention nut-driver-enumerator and upsdrvsvcctl in (systemd/|Solaris/)README * upsdrvsvcctl.in : updated comments * upsdrvsvcctl.in : added a resync option * Rename Solaris SMF services to match systemd patterns and ease life for sysadmins * Add systemd nut.target to manage the bundle of NUT services * config-notes.txt : document the systemd and SMF support in NUT * nut.dict : update spellchecker * Solaris/Makefile.am : support copying where attrs can not be preserved * Solaris postinstall : report if services were not instantly enabled due to missing config files * upsdrvsvcctl.in : reformat prettily * nut-driver-enumerator.sh.in : wrap usage() * nut-driver-enumerator.sh.in : added --list-services-for-devices * nut-driver@.service.in : comment about aligning timeouts with ups.conf maxstartdelay * nut.xml.in : Revise comments * nut-driver-enumerator.sh.in : when amending service unit instance config for systemd, update the Description to state the NUT device section name * nut-driver-enumerator.sh.in : support common NUT_CONFPATH envvar * Add upsdrvsvcctl.txt manpage and references to upsdrvsvcctl in other docs * upsdrvsvcctl.txt manpage : refer to service management system logs * upsdrvsvcctl : support "list upsname" CLI action to help troubleshooting * upsdrvsvcctl : add handling for "shutdown" command * Docs about upsdrvsvcctl - clarify that it may not be preinstalled with non-SMF/non-systemd OS packages * Pass spellcheck for upsdrvsvcctl doc updates * Solaris packaging of nut-driver-enumerator.sh : deliver into libexecdir same as in Linux * Move nut-driver-enumerator.sh.in and upsdrvsvcctl.in into scripts/upsdrvsvcctl to share on par between Linux and Solaris (for starters) * Use @NUT_LIBEXECDIR@ for nut-driver-enumerator.sh * Introduce nut-driver-enumerator.path.in for systemd * nut-driver-enumerator.service.in : be part of nut.target, not common multi-user * Systemd services : be PartOf=nut.target to propagate service stops * postinstall.in : use NUT_DATADIR * nut-monitor.xml.in : depend on nut-server (if locally running) * nut.xml.in : fix path (use pre-eval-ed version) * nut-driver-enumerator.sh.in : add a way to print out just an instance suffix name * nut-driver-enumerator.sh.in : when printing full instance name, do not add stuff if the argument is already a full name * nut-driver-enumerator.sh.in : implement --get-device-for-service * nut-driver (systemd/SMF) : use "nut-driver-enumerator.sh --get-device-for-service" for current service instance name * nut.xml.in : this service is transient * upsdrvsvcctl.in : fix parameter passing * upsdrvsvcctl.in : "clear" the SMF service state when stopping/starting, just in case it was failed * nut-driver-enumerator.sh.in : restart upsd IFF the set of known-device mappings was changed * Revise and relax some dependencies for Solaris SMF services * nut-driver-enumerator.sh.in : info messages go to stderr; reply for request only goes to stdout * nut-driver-enumerator.sh.in : complete the upslist_equals() method * nut.xml.in : never fail on stop (if component services did not stop, it is their problem) * Solaris preremove.in SMF : clear sevices before stopping them, just in case * upsdrvsvcctl.in : post-process clearing of SMF service instances if any have failed * nut.xml.in : never fail on stop (if component services did not stop, it is their problem) * Solaris preremove.in SMF : remove nut before services it depends on * main.c upsdrvctl.c : make debug messages a bit more useful * Solaris preremove.in SMF : do not block stopping NUT driver services, but follow up with upsdrv(svc)ctl stop of everything * Solaris preremove.in SMF : sleep after stopping drivers before removing their services * Solaris preremove.in SMF : force-remove services of drivers * nut-driver.xml.in : rename a dependency to avoid conflicts * Solaris nut.xml.in : add a refresh action handler * Solaris postinstall.in SMF : first use nut-driver-enumerator.sh.in to just register the mappings, no autostarts * Solaris preremove.in SMF : stop drivers with common method (and use NUT_SBINDIR) before going one by one * Solaris postinstall.in SMF : start the drivers via upsdrvsvcctl after registering (so the mapping is stable) * Solaris postinstall.in preremove.in : NUT_SBINDIR => SBINDIR * Add manpage for nut-driver-enumerator[8] * Handle EXTRA_DIST of scripts/upsdrvsvcctl/ with their own Makefile * nut-driver-enumerator.txt : change to be more like other page sources * Spellcheck nut-driver-enumerator.txt * Add scripts/upsdrvsvcctl/README * Update gitignores * List new manpages upsdrvsvcctl nut-driver-enumerator in index * Add upsdrvsvcctl do scripts/Makefile.am SUBDIRS * upsdrvsvcctl.in nut-driver-enumerator.sh.in : Add a way to show configs per device * nut-driver-enumerator.sh.in : fix upsconf_getValue() to return success if key was found, or report an error if not * nut-driver-enumerator.sh.in : expose upsconf_getValue() as --show-device-config-value * nut-driver-enumerator.sh.in : NOTE on top about the choice of simplified shell * nut-driver-enumerator.sh.in : in upsconf_getSection() stop after printing out the section contents * nut-driver-enumerator.sh.in : refactor upsconf_getValue() to use upsconf_getSection() * nut-driver-enumerator.sh.in : update comment in header * nut-driver-enumerator.service.in : do not fail the systemd unit, it cannot restart * Fix references for configure.in to point to configure.ac nowadays * nut-driver-enumerator.sh.in : use fully-pathed SMF svccfg in all parts of code consistently * nut-driver-enumerator.sh.in : comment about not-detecting reconfigurations of existing sections currently
Includes #229 by @miska and some subsequent improvements.