search by tags

for the user

adventures into the land of the command line

Upstart vs SysVinit

I’m used to using Red Hat and CentOS and have been using /etc/init.d for a while. But lately I’ve been using Ubuntu and came across upstart. I had some queries about the differences and came across this excellent answer from here which I’ve copy pasted:

/etc/init.d contains scripts used by the System V init tools (SysVinit). This is the traditional service management package for Linux, containing the init program (the first process that is run when the kernel has finished initializing, not counting initrd) as well as some infrastructure to start and stop services and configure them. Specifically, files in /etc/init.d are shell scripts that respond to start, stop, restart, and (when supported) reload commands to manage a particular service. These scripts can be invoked directly or (most commonly) via some other trigger (typically the presence of a symbolic link in /etc/rc?.d/).

/etc/init contains configuration files used by Upstart. Upstart is a young service management package championed by Ubuntu. Files in /etc/init are configuration files telling Upstart how and when to start, stop, reload the configuration, or query the status of a service. As of lucid, Ubuntu is transitioning from SysVinit to Upstart, which explains why many services come with SysVinit scripts even though Upstart configuration files are preferred. In fact, the SysVinit scripts are processed by a compatibility layer in Upstart.

.d in directory names typically indicates a directory containing many configuration files or scripts for a particular situation (e.g. /etc/apt/sources.list.d contains files that are concatenated to make a virtual sources.list; /etc/network/if-up.d contains scripts that are executed when a network interface is activated). This structure is usually used when each entry in the directory is provided by a different source, so that each package can deposit its own plug-in without having to parse a single configuration file to reference itself. In this case, it just happens that “init” is a logical name for the directory, SysVinit came first and used init.d, and Upstart used plain init for a directory with a similar purpose (it would have been more “mainstream”, and perhaps less arrogant, if they’d used /etc/upstart.d instead).

Of course now there’s systemctl, but I’ll get to that soon enough.

P.S. I just learnt that on an ubuntu system without chkconfig, to add things to autostart when there is a start script in /etc/init.d/ you can do this:

$ update-rc.d zabbix-agent defaults
 Adding system startup for /etc/init.d/zabbix-agent ...
   /etc/rc0.d/K20zabbix-agent -> ../init.d/zabbix-agent
   /etc/rc1.d/K20zabbix-agent -> ../init.d/zabbix-agent
   /etc/rc6.d/K20zabbix-agent -> ../init.d/zabbix-agent
   /etc/rc2.d/S20zabbix-agent -> ../init.d/zabbix-agent
   /etc/rc3.d/S20zabbix-agent -> ../init.d/zabbix-agent
   /etc/rc4.d/S20zabbix-agent -> ../init.d/zabbix-agent
   /etc/rc5.d/S20zabbix-agent -> ../init.d/zabbix-agent

To stop something from autostarting on boot

$ update-rc.d -f zabbix-agent remove

There’s not option to check the status unfortunately, so you can just add or remove and it’ll tell you if nothing needs to happen.

$ update-rc.d apache2 defaults
 System start/stop links for /etc/init.d/apache2 already exist.

$ update-rc.d mysqld defaults
update-rc.d: /etc/init.d/mysqld: file does not exist