Re: [systemd-devel] Trying to turn off a UPS with home-made service unit

2013-09-15 Thread Roger Price

On Wed Sep 11 10:45:48 PDT 2013 Lennart Poettering wrote:

So, it's a really bad idea to turn off UPS from userspace, simply 
because you will race against the kernel's fs sync() code, and you never 
know what will finish first: your UPS shutdown timeout or your fs 
sync(). Doing this from userspace is hence racy.


If you want to use a hack like this then at least do it via the 
/usr/lib/systemd/system-shutdown/ drop-in directory which is called very 
late during shutdown. It will shorten the race window, but not erase it, 
since the kernel will flush various buffers only after the reboot() 
system call is invoked.


Here is the effect on a simple openSUSE 12.3 test rig of replacing my 
home-made service unit /lib/systemd/system/ups-delayed-shutdown.service 
with a script in the /usr/lib/systemd/system-shutdown/ drop-in directory. 
I used the default UPS offdelay of 20 secs. The X's indicate the race 
window. (Sorry for the ascii art.)


1) My bad idea ups-delayed-shutdown.service

systemctl   system
poweroff halt
   | ||
   0   2 | 4   6   8  10  12  14  16  18  20  22  24  26  28  30  32 secs
 |   |
  upsdrvctl UPS
  shutdownshutdown

2) Replaced by script in /usr/lib/systemd/system-shutdown/

systemctl   system
poweroff halt
   | ||
   0   2   4   6   8 |10  12  14  16  18  20  22  24  26  28  30  32 secs
 |   |
 upsdrvctl  UPS
 shutdown shutdown

The script solution has the advantage of reducing the race window from 9 
to 3 secs.  Note that the same security can also be achieved by the 
service unit by setting offdelay = 26 in ups.conf.  My script is


   #! /bin/bash
   # Delayed turn off for the UPS unit.
   # Needed for automatic system restart when wall power returns.
   UPSDRVCTL_BIN=/usr/lib/ups/driver/upsdrvctl
   $UPSDRVCTL_BIN shutdown

I tried adding

   echo `date -I` `date +%T` $0 calls $UPSDRVCTL_BIN shutdown  
/var/log/UPS.log

to get a trace of the activity, but nothing is written in 
/var/log/UPS.log.


Roger
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Trying to turn off a UPS with home-made service unit

2013-08-10 Thread Roger Price
I am new to systemd and I am trying to power off a UPS unit using a 
home-made service unit /lib/systemd/system/ups-delayed-shutdown.service 
running on openSUSE 12.3.


   [Unit]
   Description=Initiate delayed UPS shutdown
   Before=umount.target

   [Service]
   Type=oneshot
   ExecStart=/usr/lib/ups/driver/upsdrvctl shutdown

   [Install]
   WantedBy=poweroff.target

I ran command systemctl --system reenable 
/lib/systemd/system/ups-delayed-shutdown.service to create the link to 
poweroff.target, but when the box is powered down, for example with 
command systemctl poweroff, my service unit does nothing.


Command systemctl list-units -t target --all does not list 
poweroff.target.  Does this mean that systemd does not recognize the 
poweroff target?  I tried replacing poweroff.target with final.target but 
this had no effect.


How should I go about debugging this?  I can find no equivalent of Bash's 
set -x to trace the operation of systemd on my unit.


Any help would be much appreciated.

Roger

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Trying to turn off a UPS with home-made service unit

2013-08-10 Thread Roger Price

On Sat, 10 Aug 2013, Andrey Borzenkov wrote:


Home made service should normally go into /etc/systemd.


I moved my service to /etc/systemd/system/


[Unit]

You need to add DefaultDependencies=no. Otherwise your service will
conflict with shutdown.target.


I added DefaultDependencies=no and my service works!


systemd --system --test --unit poweroff.target --log-level debug
can be used to see what would be started and why.


Thanks for your help!
Roger

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel