Managing processes on Ubuntu

The issue

I want to be able to have all the critical services start up in the event that the server is rebooted.

Init scripts

The first step is to write the init scripts, name it (we will call ours app) save it to the /etc/init.d/ directory and make it executable by root user. Below is an example of a really simple one that could do with allot more tweaks, but lets just get the concept first.

#!/bin/sh
case $1 in
        start)
                /home/user/folder/start_app.sh
        ;;
        stop)
                /home/user/folder/stop_app.sh
        ;;
        restart)
                /home/user/folder/restart_app.sh
        ;;
        *)
                echo "Useage sudo /etc/init.d/app2 {start|stop|restart}"
esac

Once you have create the init script run the following command to register your scripts for execution as your system changes run levels (single user, multi user, reboot etc).

sudo update-rc.d app defaults

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s