Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: how to run scripts at shutdown - how does launchd shutdown a system?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to run scripts at shutdown - how does launchd shutdown a system?



On 1/10/07 22:42, Christoph Ewering wrote:

Hello Axel!

Am 01.10.2007 um 11:55 schrieb Axel Luttgens:

[...]

Could you show us a minimal sample script that reproduces the lack of entries in the log?


Okay, I wrote a really simple script that pings a host every 30 seconds and when it gets a signal it should send a final ping. When it receives the signal it writes into the log-file, but I get no ping answer logged. I think the interfaces are already down when my script wants to send the final ping.


Indeed, at shtutdown time, one never may assume that everything is still available.
But, in your case, there may be an additional cause for the lack of interactivity (log and/or network).


[...]
Okay here comes my little test-script and my plist-file (when I can not find a bug in my real work-script I am going to post it also):


[...]


Fine! Thanks for having taken the time to devise that script: it is always easier to reason on facts :-)

The problem could be with the sleep command: not being a builtin, it is executed as a child process. As a result, it is very likely that the TERM signal sent by launchd (assuming there is one) arrives during the sleep, so that its handling by your script may be delayed; if too long, the delay may then lead launchd to just kill your script (with a SIGKILL).

Could you try something around following variant:

   #!/bin/sh

   RUNFOREVER=1

   GOT_TERM=
   function on_term()
   {
       GOT_TERM='yep'
       [ $! -gt $$ ] && kill -TERM $!
   }

   trap on_term SIGTERM

   /bin/echo "starting up"

   while [ $RUNFOREVER ]; do
       /bin/sleep 30 &
       wait $!
       if [ $GOT_TERM ]; then
          /bin/echo "just got the signal to stop"
          /sbin/ping -c 1 target.host.net
          /bin/echo "ping done going to stop now"
          exit
       fi
       /sbin/ping -c 1 target.host.net
       /bin/echo "still working"
   done

[...]

As far as I can tell, your plist seems to be OK. I guess you have put it into /Library/LaunchDaemons?

HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macos-x-server mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >how to run scripts at shutdown - how does launchd shutdown a system? (From: Christoph Ewering <email@hidden>)
 >Re: how to run scripts at shutdown - how does launchd shutdown a system? (From: Axel Luttgens <email@hidden>)
 >Re: how to run scripts at shutdown - how does launchd shutdown a system? (From: Christoph Ewering <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.