When Init puts the machine into the selected runlevel, certain services are started and stopped depending on the target runlevel. For instance, in the halt (0) or reboot (6) runlevels all system services should be stopped. In the single user / admin recovery (1) runlevel you may want to start something like the network interfaces, but not start the web server or database server. In Linux (or at least the distros that I've dealt with) this is accomplished using SysV style init scripts. In this scheme there is a shell script for each system service located in the directory "/etc/init.d" NOTE: this may vary from distro to distro, but only slightly. The information here should at least help you understand the concepts that will apply to all distros.

Lets take a look at "/etc/init.d/skeleton" which is the example init script provided with most distros. At the top you define things like the PATH variable for the environment for this service, a description, the executable file, the process id file, etc.. Next there is a section where you fill out what your service will do when it is told to start, stop, reload it's config file, restart, etc. This allows fine control over the specific needs of your service when these events occur. This script could be called directly from the command line like.

/etc/init.d/apache start
which will start the apache web server, but more commonly these scripts are called by Init and the SysV mechanism.