Understanding Upstart


Starting with Edgy Eft (Ubuntu 6.10), the System V init was replaced with an event-driven process manager called Upstart. The location of the Upstart
configuration files varieswith the Ubuntu version. (It’s new, so you can expect it to move around until it becomes more standard.) Under Jaunty Jackalope (9.04), the configurations files are in /etc/event.d/.With Karmic Koala (9.10), they are under /etc/init/.

Each Upstart control file lists the runlevels where it should start and stop, which commands to execute, and the set of dependencies. Besides the
required command to run, Upstart supports optional pre- and post-command scripts. For example, a pre-script may prepare the environment, the command
(script or exec) starts the service, and post-script can clean up any unnecessary files after running the command.

Karmic’s dbus.conf file is a good example of a simple Upstart script. This file uses a pre-start script block to create the required directories and initialize the system. It runs a single command to start the service (exec dbus-daemon--system --fork), and then it runs a single command after starting the service.

# dbus - D-Bus system message bus
# The D-Bus system message bus allows system daemons and user
# applications
# to communicate.

description "D-Bus system message bus"

start on local-filesystems
stop on runlevel [06]

expect fork

pre-start script
mkdir -p /var/run/dbus
chown messagebus:messagebus /var/run/dbus
exec dbus-uuidgen --ensure
end script

exec dbus-daemon --system --fork

post-start exec kill -USR1 1

To control Upstart scripts, you can use the start, stop, and restart commands. In addition, the status command lets you know if a service is running. For example, the following commands exercise the cron daemon.

$ sudo stop cron # same as: sudo /etc/init.d/cron stop
cron stop/waiting
$ sudo status cron
cron stop/waiting
$ sudo start cron # same as: sudo /etc/init.d/cron start
cron start/running, process 30166
$ sudo status cron
cron start/running, process 30166
$ sudo restart cron # same as: sudo /etc/init.d/cron restart
cron start/running, process 30182
$ sudo status cron
cron start/running, process 30182

For backward compatibility, Upstart includes scripts that will run any init scripts located under the /etc/rc*.d/ directories. You do not need to
port scripts from init to Upstart, and you don’t need to worry about installing software that is not configured for using Upstart.

If the service is started with a single command, then use exec. More complex services can be started using a script block that contains the script to run.

Source of Information : Wiley Ubuntu Powerful Hacks And Customizations


Subscribe to Computing Tech

Enter your email address:

Delivered by FeedBurner

Add to Technorati Favorites Top Blogs