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.

5 Answers
5

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.

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.