Style Cleanup Required
Content Cleanup Required
Since Ubuntu 6.10 (Edgy Eft)
Since the introduction of Upstart some time in 2006, or more relevantly 9.10 Karmic where most of the system services were converted, the boot process changed somewhat. The following information is tested on 11.04 Natty:
Directories and Configs
/etc/init is where the upstart init configs live. While they are not scripts themselves, they essentially execute whatever is required to replace sysvinit scripts.
/etc/init.d is where all the traditional sysvinit scripts and the backward compatible scripts for upstart live. The backward compatible scripts basically run service myservice start instead of doing anything themselves. Some just show a notice to use the "service" command.
/etc/init/rc-sysinit.conf controls execution of traditional scripts added manually or with update-rc.d to traditional runlevels in /etc/rc*
/etc/default has configuration files allowing you to control the behaviour of both traditional sysvinit scripts and new upstart configs.
Please note that generally, you can use either traditional sysvinit scripts and the methods of working with them as well as the new upstart configs and the command: "service" interchangeably. It is however recommended you use the new upstart methods which are both forward and backward compatible.
Starting a Service
# Traditional: /etc/init.d/myservice start # Upstart service myservice start
Stopping a Service
# Traditional: /etc/init.d/myservice stop # Upstart service myservice stop
Getting a list of Services
# Traditional: ls /etc/init.d # Upstart: service --status-all
Note: Upstart method will show both traditional and upstart services.
Adding a Service to Default runlevels
# Traditional update-rc.d apache2 defaults
Upstart: there is no concept of runlevels, everything is event driven with dependencies. You would add an upstart config to /etc/init and potentially source a config file in /etc/default to allow users to override default behaviour.
Removing a Service from Default runlevels
# Traditional - Something along the lines of rm /etc/rc*/*myscript
Upstart: If no config is available in /etc/default, edit config in /etc/init
Other Upstart Commands
Controlling Services - interchangeable with the "service" command
initctl - can use in place of "service" with the commands bellow. Run initctl help.
start - start a service
stop - stop a service
reload - sends a SIGHUP signal to running process
restart - restarts a service without reloading its job config file
status - requests status of service
Rebooting and Powering off the system
halt - shutdown the system then power off
poweroff - shutdown the system then power off
reboot - reboot the system
shutdown - bring the system down
Misc Upstart Commands - you generally don't use these directly
init - Upstart process management daemon
runlevel - Backward compatibility with traditional runlevels
telinit - Backward compatibility with traditional runlevels
upstart-udev-bridge - Bridge between upstart and udev
Here is an example of a simple upstart job config: /etc/init/myservice.conf
# myservice - myservice job file description "my service description" author "Me <firstname.lastname@example.org>" # Stanzas # # Stanzas control when and how a process is started and stopped # See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn # When to start the service start on runlevel  # When to stop the service stop on runlevel  # Automatically restart process if crashed respawn # Essentially lets upstart know the process will detach itself to the background expect fork # Run before process pre-start script [ -d /var/run/myservice ] || mkdir -p /var/run/myservice echo "Put bash code here" end script # Start the process exec myprocess
initctl list shows new services straight away, service command might not!
Check /var/log/syslog, it will show clues as to what went wrong.
- All scripts default to running with errexit (set -e), so any non-zero exit status will cause errors. In pre-start, this means the service won't start.
- if you want to fire events from your legacy sysvinit scripts, for example postgres, you can add the following:
- 'initctl emit starting-postgresql’ in /etc/init.d/postgresql just before the service is started
- ‘initctl emit started-postgresql’ just after
- As well as ‘initctl emit stopping-postgresql’ and ‘initctl emit stopped-postgresql
- Then you can use ‘start on started-postgresql’ and ‘stop on stopping-postgresql’ in your job.
See Upstart Getting Started for more details about upstart.
[For more details about Ubuntu transitioning away from the sysv init system. See upstart.]
Traditional Sysvinit and Before Ubuntu 6.10
Init scripts are the scripts located in /etc/init.d. These scripts are part of the bootup sequence of Ubuntu. During boot, they are not called directly, but through a structure of symbolic links which manage the services which are to be started in a particular runlevel. The scripts which are symlinked from /etc/rcS.d are executed first. Then the scripts in /etc/rcN.d/ are executed, with N being the chosen runlevel (default 2).
The LSB specifies some scripts that are used for displaying the output of the initscripts. To change how the init script's startup is displayed look in to /lib/lsb/init-functions
Method: Deleting the rc*.d links
To deactivate a script (meaning that it will not be executed at bootup), remove the corresponding symlink from /etc/rc?.d. Do not use the update-rc.d command for this purpose! It is only used in package installation scripts, and not designed for this kind of runlevel management.
Some people on the mailinglist complained on boot-delays because of the NTP-Server sync. To remove this issue the following command:
sudo rm /etc/rcS.d/S51ntpdate
- To restore the links with the right S?? or K?? values you have to look up those values on another system or take a look at the deb-Package install scripts ...
Method: Use chmod to deactivate a service
A more straightforward way is to make the init script non-executable. You do that with the *chmod* command.
sudo chmod -x /etc/init.d/myscript
After this the service will no longer be able to run.
Reactivate the service with:
sudo chmod +x /etc/init.d/myscript
Now you'll get an error message at boot time saying that init can't execute /etc/init.d/myscript.
To avoid this error msgs you have to modify the /etc/init.d/rc and the /etc/init.d/ scripts a bit. To do this simply download and apply the following diffs.
cd /tmp wget http://www.ubuntulinux.org/wiki/rc.diff wget http://www.ubuntulinux.org/wiki/rcS.diff cd /etc/init.d sudo patch -p3 < /tmp/rc.diff sudo patch -p3 < /tmp/rcS.diff
Method: Use sysvconfig to deactivate a service
The SysvconfigHowTo explains the installation and use of the sysvconfig utility.
Installing custom init-scripts
To install your own script, copy it to /etc/init.d, and make it executable.
sudo cp myscript /etc/init.d sudo chmod +x /etc/init.d/myscript
To make the script run with the start argument at the end of the start sequence, and run with the stop argument at the beginning of the shutdown sequence:
sudo update-rc.d myscript defaults 98 02
98 and 02 are the start and stop sequence numbers respectively. Both are numbers between 00 and 99 and specify how early or late a service is started or killed. If a service is started late, it should be killed early and vice-versa. A good rule of thumb is to make the stop sequence number equal to 100 minus the start sequence number.
For more information on the usage of update-rc.d
List of init scripts
From EduardoSilva Sun Dec 5 19:28:02 +0000 2004 From: Eduardo Silva Date: Sun, 05 Dec 2004 19:28:02 +0000 Subject: Instead of removing the rc*.d links, move them Message-ID: <20041205192802+0000@https://www.ubuntulinux.org> Instead of removing, I create a directory in my home dir, where I placed all the links I removed from the /etc/rc*.d From GyorgyNemeth Sun Dec 26 13:39:38 +0000 2004 From: Gyorgy Nemeth Date: Sun, 26 Dec 2004 13:39:38 +0000 Subject: Instead of removing, renaming Message-ID: <20041226133938+0000@https://www.ubuntulinux.org> If I want to disable initscript temporarily, I simply rename it from Sxxname to sxxname (without capital) It doesn't start, and the starting order information remains From FabioMarzocca Sun Apr 17 16:32:45 +0100 2005 From: Fabio Marzocca Date: Sun, 17 Apr 2005 16:32:45 +0100 Subject: Message-ID: <20050417163245+0100@https://www.ubuntulinux.org> Why don't simply use rcconf?? (apt-get install rcconf) From Chia Thu Apr 21 03:41:09 +0100 2005 From: Chia Date: Thu, 21 Apr 2005 03:41:09 +0100 Subject: Message-ID: <email@example.com> Try sysv-rc-conf (text based) or ksysv (KDE based). sudo apt-get install sysv-rc-conf Try sysvconfig as well - it's also quite handy. From JoostRingoot Fri May 6 10:33:57 +0100 2005 From: Joost Ringoot Date: Fri, 06 May 2005 10:33:57 +0100 Subject: runlevel with networking and without graphical interface? Message-ID: <firstname.lastname@example.org> I would like to have a runlevel with basic networksupport (and services like ssh and sftp) but without the graphical interface. This is not implemented in /etc/init.d/rcS When I run: apt-get install rcconf I get the message that rcconf package could not be found. apt-get install sysv-rc-conf tells me that the package is not available although another package points to it I would like to put this runlevel in the (grub) bootmenu, so that I can choose it at boot and not need to chmod files. suggestions are welcome. From Chia Sat May 7 06:46:56 +0100 2005 From: Chia Date: Sat, 07 May 2005 06:46:56 +0100 Subject: Message-ID: <20050507064656+0100@https://www.ubuntulinux.org> To apt-get sysv-rc-conf, you need to enable universe in /etc/apt/sources.list ,for easy way to do it use synaptic -> settings -> repositories, or read the unofficial ubuntu starter guide at http://www.ubuntuguide.org/ . Also worth trying Boot-Up Manager: http://www.marzocca.net/linux/bum.html