Question: I have created a script to start a server (my first question). Now I want it to run on the system boot and start the defined server. What should I do to get this done? 

My findings tell me put this file in the `/etc/init.d` location, and it will execute when the system will boot. But I am not able to understand how the first argument on the startup will be `start`? Is this predefined somewhere to use `start` as `$1`? If I want to have a case `startall` that will start all the servers in the script, then what are the options I can manage?

My script is like this:

```
#!/bin/bash

case "$1" in
start)
     start
    ;;
stop)
    stop
    ;;

restart)
    $0 stop
    $0 start
    ;;
*)
    echo "usage: $0 (start|stop|restart)"
;;
esac

```

Answer: 
`/etc/init.d` is the script directory, in which the executable scripts appear. However, in order to run scripts in a particular order after your system starts, you need to add files to the `/etc/rc#.d` directory. Entries that appear here tell your system in what order and at what run level scripts in `/etc/init.d` should be run. The number after the rc indicates what run level the machine is running at, according to this chart:

<http://en.wikipedia.org/wiki/Runlevel>

So if you have:

```
/etc/init.d/importantscript

```

Then you need the (empty) files:

```
/etc/rc.d/rc3.d/S20importantscript
/etc/rc.d/rc6.d/K20importantscript

```

The S means start, and the K means kill. When your machine starts, the system will say "Ah, I'm running at RunLevel 3, let's pop over to rc3.d to see what scripts in '/etc/init.d' need to be run and in what order." In this case, the system will sort by 'S' and then the number after 'S' and will execute '/etc/init.d/importantscript start'. The 20 is just for ordering purposes... your script will run behind 'S19' and in front of 'S21'. You can create these files simply by doing:

`sudo touch /etc/rc.d/rc3.d/S20importantscript`

Here's a nice summary as well: <http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts>
The $1 is the command line argument that is passed to your script, it is one of start, stop or restart. In [openSUSE](http://en.wikipedia.org/wiki/OpenSUSE), I don't remember having an option to pass other arguments into the script when useing the runlevel editor thingy, so I think that these are probably the only ones you should use.

I don't use [CentOS](http://en.wikipedia.org/wiki/CentOS) myself, but it seems that the program to control what is started at which runlevel is [ntsysv](http://centos.org/modules/newbb/viewtopic.php?viewmode=flat&order=ASC&topic_id=12486&forum=37).