Create your own service in ubuntu

Create a service and set it to boot level at systems starts like how does apache2 service starts by default in ubuntu when  linux system boots

Usage you could create your own shell script that need to be used as service to start stop kill or whatever

Realtime examples are apache2,mysql, mongo, chrome,skype and every processes

 

Steps  

1. Switch to sudo user by

sudo su

2. Navigate to /etc/init.d

cd /etc/init.d

3. Create a file test

touch test

4. Edit the file by vi editor or vi or gedit

 vim test 

 or use gedit

 gedit test

5.  Paste this code in it

#!/bin/sh
### BEGIN INIT INFO
# Provides:          test
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     false
# Short-Description: Example init script
# Description:       Start/stop an example script
### END INIT INFO

DESC="test script"
NAME=test
#DAEMON=

do_start()
{
   echo "starting!";
}

do_stop()
{
   echo "stopping!"
}


case "$1" in
   start)
     do_start
     ;;
   stop)
     do_stop
     ;;
esac

exit 0

6.  Give executable permission to the file

chmod +x test

7. Now test whether its working by below

service test start

 

it will print "starting!" 

Thats it Working.


If you want to change the chkconfig, It is removed in ubuntu and now update-rc.d is equivalent to chkconfig

update-rc.d test defaults

update-rc.d test start 20 3 4 5

update-rc.d -f test  remove

Thats it !