[{TableOfContents }]
\\

To add a new service on startup, you should add the necessary script to the directory {{__/etc/init.d/__}}.  Look at the pre-exisiting scripts for an example of what to do.

!!! Basic Example

{{{
#! /bin/sh
# /etc/init.d/foo
#

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

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script foo "
    echo "Could do more here"
    ;;
  stop)
    echo "Stopping script foo"
    echo "Could do more here"
    ;;
  *)
    echo "Usage: /etc/init.d/foo {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/foo
}}}

!! Symbolic Links

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

! Create

The simplest way of doing this is to use the Debian-specific command {{__update-rc.d__}}: 

{{{
root@shost:~$ update-rc.d foo defaults
 Adding system startup for /etc/init.d/foo ...
   /etc/rc0.d/K20foo -> ../init.d/foo
   /etc/rc1.d/K20foo -> ../init.d/foo
   /etc/rc6.d/K20foo -> ../init.d/foo
   /etc/rc2.d/S20foo -> ../init.d/foo
   /etc/rc3.d/S20foo -> ../init.d/foo
   /etc/rc4.d/S20foo -> ../init.d/foo
   /etc/rc5.d/S20foo -> ../init.d/foo
}}}

! Remove

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

{{{
root@host:/etc/rc2.d$ update-rc.d -f foo remove
update-rc.d: /etc/init.d/foo exists during rc.d purge (continuing)
 Removing any system startup links for /etc/init.d/foo ...
   /etc/rc0.d/K20foo
   /etc/rc1.d/K20foo
   /etc/rc2.d/S20foo
   /etc/rc3.d/S20foo
   /etc/rc4.d/S20foo
   /etc/rc5.d/S20foo
   /etc/rc6.d/K20foo
}}}

This will leave the script itself in place, just remove the links which cause it to be executed.

You can find more details of this command by running {{__man update-rc.d__}}.

----
[CategoryComputing.Linux] - [CategoryComputing.Linux.Shell]