How to Register Initialization Script for Managing Service in Linux Ubuntu 19.10 Operating System

Posted on


This article will focus on how to register a service in an operating system. Actually, every type of operating system has lots of service running on it. TIn Ubuntu, according to the information in this link, there are three types of main init system. Those are the ‘Systemd’, ‘Upstart’ and ‘SysV’. According to that link, Upstart init system was available just before the ‘systemd’. It was available in Ubuntu 9.10 to Ubuntu 14.10. Later on, it was later phased out paving way for systemd init in Ubuntu 15.04 and newer versions. Upstart makes use of config files for controlling services. These files exist under the /etc/init directory. These files consist of plain text sections organized in stanzas and each stanza describes a service and how it works.

More over, in this link which is also quoting from, Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running. The “init” or “system initialisation” process on Unix and Linux systems has process ID (PID) “1”. That is to say, it is the first process to start when the system boots (ignoring the initrd/initramfs). As the quote shows, Upstart is an “init” replacement for the traditional Unix “System V” “init” system. Upstart provides the same facilities as the traditional “init” system, but surpasses it in many ways.

Moreover, in this article, there will be a further explanation and description about the ‘Upstart’ init system.  The explanation will be in a specific part of the initialization script. It will focus on how to register the initialization script to manage the service.


Register initialization script file using Upstart init system

Below is the main pattern for registering or adding an initialization script mainly in Linux Ubuntu distribution operating system. For an addition, the process for registering or adding it as an example in this article, it is in Linux Ubuntu 19.10 operating system :

update-rc.d service defaults

The following is an example of the execution of the above command :

root@hostname:~# update-rc.d mysqld57 defaults

The effect of the above command execution is the service will be available in all run-level. There are several run-level in Upstart main init :
0 – Halt
1 – Single-user text mode
2 – Not used (user-definable)
3 – Full multi-user text mode
4 – Not used (user-definable)
5 – Full multi-user graphical mode (with an X-based login screen)
6 – Reboot

The above command will add a symbolic link to the directory of ‘/etc/rcrunlevel.d/[SK]NNname. Depend on the currently running level, it will add S or K. Moreover, the ‘NN’ will decide on the sequence of priority for executing the service. According to the manual page available for the above command, the ‘update-rc.d’, it is a command or tool to install and remove System-V style init script links.

Furthermore, in this link, there is a detail explanation about the ‘default’ option. In that link, if there is a ‘defaults’ parameter along with the update-rc.d command, it will make links to start the service in runlevels 2345 and to stop the service in runlevels 016. By default all the links will have sequence number 20, but this should be overridden if there are dependencies. For example if daemon B depends on A, then A must be started before B and B must be killed before A. The pattern number above, the NN arguments on the symbolic link file represent the sequence of it. In general, core daemons should start early and be killed late, whilst applications can start late and be killed early.

Leave a Reply