-   Debian (
-   -   run this command when the computer shutdown or reboot (

lindylex 11-16-2008 03:17 PM

run this command when the computer shutdown or reboot
I want to run this command when the computer shutdown or reboot.

alsactl store
Is there a file I can place this into to make it happen? I know how to automate things startings using "update-rc.d" but I don't know how to do it for runlevel 6 and runlevel 0.

Thanks, Lex

repo 11-16-2008 04:32 PM

Put your script in /etc/rc0.d (for halt) and /etc/rc6.d/ for reboot. Make sure script has executable permission

lindylex 11-17-2008 04:56 AM

This is how you should do it.


su [Enter your root password]
cd /etc/init.d

Inside of place this.


#LindyLex example to save the audio state.

echo "Saving Audio State."
alsactl store


chmod a+x /etc/init.d/
Now we tell it to execute when the computer is shutdown or rebooted. Yes that is a period at the end of the command don't forget it.


update-rc.d start 20 0 6 .
These are the meaning behind the numbers.

- 0 = halt
- 1 = single user
- 2 = CLI, multi-user, no net
- 3 = CLI, multi-user, networked
- 4 = open
- 5 = GUI, multi-user, networked
- 6 = reboot

The "20" you could use this for your script. You can learn more about the meaning of the number after you read about update-rc.d below.

You can learn more by reading the following, execute this in the terminal.


man update-rc.d

That is it.

Thanks Lindylex

makuyl 11-17-2008 02:29 PM

In a perfect world the above runlevels would apply, but ofcourse Debian has to be different here too :)
Last I looked it was:
- 0 = halt
- 1 = single user
- 2-5 = GUI, multi-user, networked (with runlevel 2 as default in /etc/inittab)
- 6 = reboot

restless 11-25-2008 05:31 PM

i would also change the 20 to a higher value.. maybe something right before or right after gdm or kdm.
the 20 defines in which order the S (start) or (K) kill scripts are started.

when a init enters a specific runlevel, then it will start with the K script with the lowest number, and after it ran all the K scripts, it will start with the S scripts with the lowest number.

To me saving the audio config state doesn't seem that important, and i'd prefer everything else to start first.

other than that, this is the way to go indeed.

All times are GMT -5. The time now is 06:53 PM.