application autostart at boot time on ubuntu.

March 9th, 2010 by Jayson Leave a reply »

ubuntu supplied two ways to set a application autostart at boot time.

1. add the command at /etc/rc.local.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/usr/bin/memcached -m 64 -p 11211 -u nobody -l 192.168.1.148 -d
exit 0

2. add service script at /etc/init.d
as ubuntu based on Debian, there’re already many scripts inside /etc/init.d, you can take as an example. here is a very simple one,

#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always
touch /var/lock/blah

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
  stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;;
  *)
    echo "Usage: /etc/init.d/blah {start|stop}"
    exit 1
    ;;
esac

exit 0

Once you’ve saved your file into the correct location make sure that it’s executable by running “chmod 755 /etc/init.d/blah”.

Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.

The simplest way of doing this is to use the Debian-specific command update-rc.d:

root@skx:~# update-rc.d blah defaults

If you wish to remove the script from the startup sequence in the future run:

root@skx:/etc/rc2.d# update-rc.d -f  blah remove

Making scripts run at boot time with Debian

Advertisement

Leave a Reply

You must be logged in to post a comment.