Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've got a few commands that I run in rc.local so they are run last in the startup sequence. I would like to know if there is a similar facility for undoing the results of those commands at shutdown, like an rc.shutdown. Ideally, it would be run before any of the other /etc/init.d scripts.

share|improve this question
3  
This is highly distribution-dependent. Please add information about your distribution. –  rozcietrzewiacz Aug 14 '11 at 0:02

5 Answers 5

up vote 8 down vote accepted

Not really (at least, to my knowledge).

If you've got SystemV style init scripts, you could create something along the lines of /etc/rc6.K00scriptname and /etc/rc0.d/K00scriptname, which should get executed prior to any of the other scripts in there.

share|improve this answer

ArchLinux does have a /etc/rc.local.shutdown file for this. I'm not sure about other distros

share|improve this answer

It is generally possible, but depends on the init-scripts system you have. If your distribution used a recent version of OpenRC (as Gentoo does), you could put any scripts in /etc/local.d/, call them <something>.stop and they would be run at system shutdown. For older versions, you'd have to put your commands inside local_stop() function in /etc/conf.d/local.

The order depends on the rc-system settings, but typically the local scripts are the last to run at startup and first to run at shutdown.

share|improve this answer

If you have upstart, you can catch the shutdown event and run a script when it is caught.

share|improve this answer

In Gentoo the "local" script does exactly what you ask for: It runs certain user specified commands upon 'start' and another set of commands upon 'stop'.

share|improve this answer

protected by Michael Mrozek Mar 8 '11 at 4:04

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.