How to run a script on shut down

Ray Parrish crp at cmc.net
Wed Nov 26 19:57:58 UTC 2008


Erik Christiansen wrote:
> On Tue, Nov 25, 2008 at 09:17:10PM -0800, Ray Parrish wrote:
>   
>> ... but I don't know where to put a corresponding 
>> call to the stop monitoring script so it will run when I log off, or 
>> shut down. I'd really like to find out, as this script does the final 
>> log file clean up for the application so I have to run it manually 
>> before I log off or it won't clean up the log files.
>>
>> Anyone know how to do this?
>>     
>
> The traditional way is with a "Kill script" in /etc/rc.2. Why not rc.3?
> Well, though upstart doesn't care much about runlevels AFAIR, it's happy
> to put on a show of being in level 2, at least when we're in X:
>
> $ runlevel
> N 2
>
> Even with the new "upstart" event-based init system, the traditional
> /etc/rc?.d files are supported on 7.10. Assuming your ubuntu version,
> like mine, has /etc/rc2.d/S99rc.local , you could copy it to
> /etc/rc2.d/K10rc.local (given that such a file doesn't pre-exist)
>
> Now, simply insert your command in your nice new /etc/rc2.d/K10rc.local:
>
>     stop)
>          myscript and any options it takes         <-- Here
>         ;;
>
> That's it, if habit serves as memory.
>
> Why K10? That's to run it early, before e.g. your networking has been
> shut down.
>
>       ------------------ Optional extra reading ------------------ 
>
> Just checking that the newfangled upstart really does what we want, in
> its "telinit compatibility wrapper", we see in line 284 of
> /etc/init.d/rc :
>
>          startup stop $SCRIPTS
>
> will be iterated over your script on exiting runlevel 2, by line 262 :
>
>          for i in /etc/rc$runlevel.d/K$level*
>
> (And see /etc/event.d/rc2, which does an "exec /etc/init.d/rc 2")
>
> So we _can_ still do it the traditional way.
>
> Erik
>
>   
Thanks for your reply. I'll be doing a bit of studying to figure out 
what you've told me before I'll be able to do it, but I'm sure I'll 
figure it out from here with that information.

Later, Ray Parrish

-- 
http://www.rayslinks.com/ Web index of human reviewed links.
<http://www.rayslinks.com/Troubleshooting%20and%20fixing%20Windows.html>
Trouble shooting and Fixing Windows
http://www.writingsoftheschizophrenic.com My poetry in web pages





More information about the ubuntu-users mailing list