Debian: How to run scripts at boot time

Personal notes to be always available for debian installations.

secure-coding-php

Here’s a very simple script which is divided into two parts, code which always runs, and code which runs when called with “start” or “stop”.

If you need something like a service to start at boot time, you need this.
Debian stores script needed to usually start, stop and restart in /etc/init.d/
Scripts contained have to be able to manage at least the start and stop parameters.
Following script is an example i use as template for any purpose.

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

# at least two cases (start and stop)
case "$1" in
start)
echo "Starting service... "
/usr/local/bin/yourservce -parameters
;;
stop)
echo "Stopping service"
kill -0 $PID 2> /dev/null
;;
*)
echo "Usage: /etc/init.d/template {start|stop}"
exit 1
;;
esac

exit 0

Anyway you can add several “cases” and options, take a look at you scripts in /etc/init.d directory.

Once you have your start/stop script, you add it let’s say at boot time, with the command

update-rc.d script_name defaults

(remember to chmod +x the file)

You can remove it with following command:

update-rc.d -f script_name remove

obviously thanks to http://www.debian-administration.org/articles/28 

(Visited 5,751 times, 1 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.