11

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.

  • 3
    This is highly distribution-dependent. Please add information about your distribution. – rozcietrzewiacz Aug 14 '11 at 0:02
8

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.

| improve this answer | |
4

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

| improve this answer | |
3

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.

| improve this answer | |
1

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

| improve this answer | |
1

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'.

| improve this answer | |

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