On Thursday, May 12, 2011 16:00:14 Michal Hlavinka wrote:
> On Thursday, May 12, 2011 09:26:38 Arnaud Quette wrote:
> > Hi Michal,
> > 
> > first, I know understand where our "disagreement" comes from:
> > in Debian, we have a generic ups-monitor role provided by several
> > packages. the shutoff (final ups poweroff) hook is located in the
> > package's initscript, and is called from halt.
> > whereas, in RH/Fedora, you don't have this generic role (afaik), nor the
> > hook in the package's initscript.
> 
> in Fedora 14 (and older) the hook is in /etc/init.d/halt initscript. This no
> longer exists in Fedora 15+. I've asked systemd maintainer if they ported
> this hook from old initscript to systemd, because I was not able to find
> it.

they did not ported it to systemd, but we don't need them :)

> > which means that NUT initscript in RH only has to deal with
> > start/stop/restart, which are the standard conditions.
> > I'll have to think more about that, but for the time being, you may want
> > to progress with your previously mentioned approach (4).
> 
> I'm already working on it. I'll send it to the list, when it's ready, but
> just right now it's blocked by bug in systemd.

sketch version attached (files in root source directory, paths hardcoded and so 
on... it's just a sketch version)

I've tested it on my system, but just once, seems my apc ups is deffective, 
because it reports error code with uninteruptable beep (it fails its own 
battery test when battery is (almost) empty - after AC reconnected). This is 
new ups with new battery, so I'll retest it, but most probably I'll need to 
send it back to apc. Anyway, sw part was working fine.

upsmon nor upsd does not support "foreground mode", which is preffered
(see http://0pointer.de/public/systemd-man/daemon.html ) but it's not that big 
deal.

eh... seems I've forgot other comments... I'll have to write them down next 
time :)

...
...

> > As an obvious (and probably the most basic) example with NUT:
> > how will you handle the "poweroff" target of the NUT sysV init script?
> > 
> >       if upsmon -K >/dev/null 2>&1 ; then
> >       
> >         if upsdrvctl shutdown ; then

just do:

printf "#!/bin/sh\n upsmon -K >/dev/null 2>&1 && upsdrvctl shutdown" > 
/lib/systemd/system-shutdown/upsshutdown

and prepare for systemd's almighty grumbling :D There was some futile 
"discussion" about how wrong is this, but there is no other way doing this
diff -up trunk/configure.in.systemd trunk/configure.in
--- trunk/configure.in.systemd	2011-05-17 17:29:41.324531001 +0200
+++ trunk/configure.in	2011-05-17 17:29:59.179678460 +0200
@@ -26,6 +26,8 @@ dnl Use "./configure --enable-maintainer
 dnl in sync after SVN updates.
 AM_MAINTAINER_MODE
 
+dnl PKG_PROG_PKG_CONFIG
+
 dnl # the following is commented out, because the UPS_VERSION macro now
 dnl # resides in include/nut_version.h, which is generated by Makefile.am,
 dnl # rather than in include/config.h, which is generated by configure.  The
@@ -784,6 +786,31 @@ else
 fi
 AM_CONDITIONAL(WITH_PKG_CONFIG, test -n "${pkgconfigdir}")
 
+PKG_PROG_PKG_CONFIG
+systemdsystemunitdir=`$PKG_CONFIG --variable=systemdsystemunitdir systemd`
+AC_MSG_CHECKING(whether to install systemd files)
+AC_ARG_WITH([systemdsystemunitdir],
+	AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files (auto)]),
+[
+	case "${withval}" in
+	yes|auto)
+		;;
+	no)
+		systemdsystemunitdir=""
+		;;
+	*)
+		systemdsystemunitdir="${withval}"
+		;;
+	esac
+], [])
+if test -n "${systemdsystemunitdir}"; then
+	systemdsystemshutdowndir="/lib/systemd/system-shutdown"
+	AC_MSG_RESULT(using ${systemdsystemunitdir})
+else
+	AC_MSG_RESULT(no)
+fi
+AM_CONDITIONAL(HAVE_SYSTEMD, test "$systemdsystemunitdir" != "")
+
 AC_MSG_CHECKING(whether to install hotplug rules)
 AC_ARG_WITH(hotplug-dir,
 	AS_HELP_STRING([--with-hotplug-dir=PATH], [where to install hotplug rules (/etc/hotplug)]),
@@ -903,6 +930,8 @@ AC_SUBST(cgiexecdir)
 AC_SUBST(driverexecdir)
 AC_SUBST(htmldir)
 AC_SUBST(pkgconfigdir)
+AC_SUBST(systemdsystemunitdir)
+AC_SUBST(systemdsystemshutdowndir)
 AC_SUBST(hotplugdir)
 AC_SUBST(udevdir)
 
diff -up trunk/m4/nut_check_os.m4.systemd trunk/m4/nut_check_os.m4
--- trunk/m4/nut_check_os.m4.systemd	2011-05-17 17:28:58.555176955 +0200
+++ trunk/m4/nut_check_os.m4	2011-05-17 17:29:59.180678469 +0200
@@ -44,6 +44,7 @@ AC_DEFUN_ONCE([NUT_OS_FUNCTIONS],
 
 AC_DEFUN([NUT_CHECK_OS],
 [
+    m4_pattern_allow([^PKG_TARGET$])
     # Look for all possible source of OS name resolution
     # 1) we look for a LSB release info file
 	eval "dist_search_path=\"
diff -up trunk/Makefile.am.systemd trunk/Makefile.am
--- trunk/Makefile.am.systemd	2011-05-17 17:29:41.340531132 +0200
+++ trunk/Makefile.am	2011-05-17 17:29:59.180678469 +0200
@@ -52,6 +52,24 @@ website:
 	@echo "Not building website since 'asciidoc' was not found."
 endif !HAVE_ASCIIDOC
 
+if HAVE_SYSTEMD
+%.service: %.service.in
+	sed -e 's,@sbindir\@,$(sbindir),g' $< > $@
+
+upsshutdown: upsshutdown.in
+	sed -e 's,@sbindir\@,$(sbindir),g' $< > $@
+
+systemdsystemunit_DATA = \
+        ups-daemon.service \
+        ups-driver.service \
+        ups-monitor.service
+
+systemdsystemshutdown_PROGRAMS = upsshutdown
+
+else
+EXTRA_DIST += ups-daemon.service.in ups-driver.service.in ups-monitor.service.in upsshutdown
+endif
+
 # ----------------------------------------------------------------------
 # targets from old build system (pre-automake).
 # supported for a period of time for backward "compatibility".
diff -up trunk/ups-daemon.service.in.systemd trunk/ups-daemon.service.in
--- trunk/ups-daemon.service.in.systemd	2011-05-17 17:29:59.180678469 +0200
+++ trunk/ups-daemon.service.in	2011-05-17 17:29:59.181678477 +0200
@@ -0,0 +1,17 @@
+[Unit]
+Description=Network UPS Tools - UPS information server daemon
+After=local-fs.target network.target ups-driver.service
+Requires=ups-driver.service
+Before=ups-monitor.service
+
+#for options see: http://0pointer.de/public/systemd-man/systemd.service.html and http://0pointer.de/public/systemd-man/systemd.unit.html
+[Service]
+EnvironmentFile=/etc/sysconfig/ups
+# ^^^ just for -4 and -6 options
+ExecStart=/usr/sbin/upsd $UPSD_OPTIONS
+#kill only upsdrvctl without childs? if so, then set: KillMode=process
+Type=forking
+#upsd should support -f/--foreground , then we could use Type=simple, which is preffered, see http://0pointer.de/public/systemd-man/daemon.html
+
+[Install]
+WantedBy=multi-user.target
diff -up trunk/ups-driver.service.in.systemd trunk/ups-driver.service.in
--- trunk/ups-driver.service.in.systemd	2011-05-17 17:29:59.181678477 +0200
+++ trunk/ups-driver.service.in	2011-05-17 17:29:59.181678477 +0200
@@ -0,0 +1,13 @@
+[Unit]
+Description=Network UPS Tools - UPS information server
+After=local-fs.target network.target
+StopWhenUnneeded=yes
+
+[Service]
+ExecStart=/sbin/upsdrvctl start
+ExecStop=/sbin/upsdrvctl stop
+#kill only upsdrvctl without childs? if so, then set: KillMode=process
+Type=forking
+
+#[Install]
+#WantedBy=multi-user.target
diff -up trunk/ups-monitor.service.in.systemd trunk/ups-monitor.service.in
--- trunk/ups-monitor.service.in.systemd	2011-05-17 17:29:59.181678477 +0200
+++ trunk/ups-monitor.service.in	2011-05-17 17:29:59.181678477 +0200
@@ -0,0 +1,13 @@
+[Unit]
+Description=Network UPS Tools - UPS monitor
+After=local-fs.target network.target ups-daemon.service
+
+#for options see: http://0pointer.de/public/systemd-man/systemd.service.html and http://0pointer.de/public/systemd-man/systemd.unit.html
+[Service]
+ExecStart=/usr/sbin/upsmon
+PIDFile=/var/run/nut/upsmon.pid
+Type=forking
+#upsd should support -f/--foreground , then we could use Type=simple, which is preffered, see http://0pointer.de/public/systemd-man/daemon.html
+
+[Install]
+WantedBy=multi-user.target
diff -up trunk/upsshutdown.in.systemd trunk/upsshutdown.in
--- trunk/upsshutdown.in.systemd	2011-05-17 17:29:59.182678485 +0200
+++ trunk/upsshutdown.in	2011-05-17 17:29:59.182678485 +0200
@@ -0,0 +1,2 @@
+#!/bin/sh
+upsmon -K >/dev/null 2>&1 && upsdrvctl shutdown
_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev

Reply via email to