Upstart, RCs Scripts, and Services

If you haven’t installed a new version of Linux lately, you might be in for a shock. There is no /etc/inittab configuration file in Ubuntu releases. Upstart, the replacement for the System V init program, is designed to meet the demands of the latest plug-and-play hotplug environments. During the boot process, Upstart is especially helpful with filesystems mounted on portable and network devices.

Upstart Service Scripts

Pay particular attention to the scripts in the /etc/event.d directory. Future Linux releases might see service scripts currently in the /etc/init.d directory move there to become a part of the Upstart system. One service script, the logging daemon, logd, was already moved there for the Hardy Heron release. The configuration file, /etc/event.d/logd, is straightforward. First, logging is stopped in runlevels 0, 1, and 6 with commands like this:

stop on runlevel 0

Next, log output, unless otherwise configured, is sent to the console:

console output

The /sbin/logd daemon is run by default. If it is stopped for any reason, it is restarted, as depicted by the respawn directive:

exec /sbin/logd
respawn

Upstart Scripts Replace /etc/inittab

If you remember the directives in the /etc/inittab configuration file, you’ll recognize the contents of the other files in the /etc/event.d directory. As the hardware advantages of Upstart are essentially transparent to most users, this section focuses on how Upstart provides equivalent functionality to /etc/inittab. The first line in a standard /etc/inittab file specifies the default runlevel. To review, for Debian-based distributions including Ubuntu, the default runlevel as signified by the
following directive is 2:

id:2:initdefault

The default runlevel is now configured with Upstart’s rc-default configuration file in the /etc/event.d directory. In essence, the script takes the default runlevel from /etc/inittab if the file exists and a directive like id:2:initdefault is included;   otherwise, it’s configured to set a runlevel of 2. Next, some scripts are run independent of runlevel, as configured by the following:

si::sysinit:/etc/init.d/rcS

This effectively runs all scripts in the /etc/rcS.d directory. These are all “start” scripts, as they start with a capital S. In other words, they’re started whenever Linux is booted. The same scripts are run through Upstart, courtesy of the  /etc/event.d/rcS script. The next directive from my old /etc/inittab specifies what needs to be done when Linux is booted into single-user mode, as specified by the recovery mode option described earlier in the GRUB configuration file. The S runlevel is synonymous with the single that appears in the GRUB configuration file, which starts single-user mode. The wait directive stays in the noted runlevel. The sulogin command, when invoked by the recovery mode option, boots and logs into the root account.

~~:S:wait:/sbin/sulogin

The equivalent Upstart functionality is available from the /etc/event.d/rcS-sulogin file, which invokes the sulogin command unless /etc/inittab exists on the system. These directives from /etc/inittab provide options; only one is run, based on the specified runlevel. For example, if the default runlevel is 2, the associated command runs the scripts in the /etc/rc2.d directory:

l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6

The equivalent Upstart script for runlevel 2 is /etc/event.d/rc2, which confirms the desired runlevel and then runs the following command:

exec /etc/init.d/rc 2

Linux systems are configured to accept the CTRL-ALT-DELETE key combination often associated with Microsoft systems. When the associated signal is received, the /etc/inittab file specifies the following directive, which starts the shutdown command in one second (-t1), limited by any existing rules specified in an /etc/shutdown.allow file (-a), if it exists, and reboots now (-r now).

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

In contrast, Upstart’s /etc/event.d/control-alt-delete file executes the following command, with fewer limitations. Of course, the command can be modified to suit your needs.

exec /sbin/shutdown -r now "Control-Alt-Delete pressed"

Many server systems are protected by Uninterruptable Power Supplies (UPS). When connected to a Linux system, they can send one of three signals to the system, which was interpreted by /etc/inittab with the following commands:

pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop

These options require the powstatd package, also known as the Configurable UPS Monitoring Daemon. It depends on the noted /etc/init.d/powerfail script as well as the /etc/ powstatd.conf configuration file. But as /sbin/powstatd is now a regular daemon controlled by the complementary /etc/init.d/powstatd script, it’s technically not part of Upstart. Linux systems typically include six consoles, also known as gettys. In /etc/inittab, they’re started with the following directives, where all six gettys are made available in runlevels 2 and 3.

1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3

4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

In the Upstart system, each of these gettys are started with ttyx files in the /etc/ event.d directory, where x represents the terminal number. While these files are more descriptive, they contain the same information. All six terminals are started in runlevels 2 and 3. When a user logs out of a terminal, the respawn directive regenerates that terminal with a new login screen. Communication in a text screen is plenty fast at 38400 bits per second.

Posted on: 22/12/2009








0 Comments
If you want to leave a comment please Login or Register