If you want to execute a script only at shutdown, you don't need:
# Required-Start: $remote_fs $syslog
You can leave this empty.
Each script has
Provides entry which defines names of other scripts that you can use in the
Required-Stop directives. The order is reversed in the two fields. If something has to start before the script, you have to put it into
Required-Start directive. But if the script has to stop before a certain service, the name of that service has to be placed in
So, in your example you want to run the script before apache and mysql termination at shutdown. All you have to do is to check the
Provides directive in appropriate init files.
$ cat /etc/init.d/apache2
# Provides: apache2
$ cat /etc/init.d/mysql
# Provides: mysql
Now you just add
mysql to your script under the
# Required-Stop: apache2 mysql
You can read more about the header of an init script here . There's also some info concerning facility names, for example the mentioned
$local_fs -- all local filesystems are mounted. All scripts that write
in /var/ need to depend on this, unless they already depend on
$network -- low level networking (ethernet card; may imply PCMCIA
$named -- daemons which may provide hostname resolution (if present)
are running. For example, daemons to query DNS, NIS+, or LDAP.
$portmap -- daemons providing SunRPC/ONCRPC portmapping service as
defined in RFC 1833 (if present) are running all remote
$remote_fs -- all filesystems are mounted. In some LSB run-time
environments, filesystems such as /usr may be remote. If the script
need a mounted /usr/, it needs to depend on $remote_fs. Scripts
depending on $remote_fs do not need to depend on $local_fs. During
shutdown, scripts that need to run before sendsigs kills all processes
should depend on $remote_fs.
$syslog -- system logger is operational
$time -- the system time has been set, for example by using a
network-based time program such as ntp or rdate, or via the hardware
Real Time Clock. Note that just depending on ntp will not result in an
accurate time just after ntp started. It usually takes minutes until
ntp actually adjusts the time. Also note that standard insserv.conf
just lists hwclock as $time.
$all -- facility supported by insserv to start a script after all the
other scripts, at the end of the boot sequence. This only work for
start ordering, not stop ordering. It is not possible to depend on a
script which depend on $all.
After you change a header in an init script, you have to run
update-rc.d and it will set the right order of all scripts based on their headers:
# update-rc.d script defaults