First, you'll need an "init script". It is called so because it is a shell script most of the time, but can be anything which is executable, even a binary ELF file.
An init script should accept at least the "start" and the "stop" parameters. If the computer starts, the script will be called with the "start" argument, and when the computer stops, it will be called with the "stop" argument. (it is more difficult than this, but you don't need to care for now. If you do, read the man page of init(8))
A skeleton of an init script looks like this:
Code: Select all
#!/bin/bash
case "$1" in
start)
# Stuff to do upon startup
;;
stop)
# Stuff to do upon halt
;;
*)
echo "Use this way: $0 start|stop"
;;
esac
* The script must exit. The whole bootup process will hang if the script doesn't exit.
* The script must be executable.
* It should print some information, at least a "starting..." message and a "done" when it is finished. Should the script fail, it should definitely print some kind of error message.
* Test your script. Only put it into the /etc/init.d directory if it works from the command line.
* You may have certain environmental variables exported. If the script depends on these, export them from the script itself. For example, if you changed your PATH, the script won't see your PATH when the system boots up, altough it will work if you execute it by hand.
* The scipt must make sure not to do stupid things. For example, if the script called with "start" arguments twice, it should detect that there is nothing to do, and exit without changing anything. It is especially important when you try to manipulate interfaces, devices and the like.
If everything is fine, move your script to the /etc/init.d directory. This directory, by convention, holds the init scripts.
If the script is in place, issue the following command:
Code: Select all
update-rc.d (yourscript) defaults
If you want to remove a script from the bootup process, you can do it with this command:
Code: Select all
update-rc.d -f (yourscript) remove
update-rc.d(8)
init(8)
runlevel(8)