Weblog entry #4 for nicc777

Posted by nicc777 on Thu 12 Jan 2006 at 06:33
Tags: none.
Over at Linux.com there is an interesting article about "services, runlevels, and rc.d scripts".

This was rather interesting, but something I would like to add for us Debian admins is the start-stop-daemon(8).

With this little gem it is very easy to write your own startup scripts.

Here is my skeleton startup script:

#! /bin/sh

# /etc/init.d/jboss: start and stop the jboss daemon

SSD=/sbin/start-stop-daemon
ECHO=/bin/echo
TEST=/usr/bin/test
HOSTNAME=`/bin/hostname`
MYAPP=/path/to/app
MYAPPNAME=app

$TEST -x $MYAPP || exit 0

case "$1" in
  start)
        $ECHO -n "Starting $MYAPPNAME: $MYAPP"
        $SSD -c myusername --start -b --quiet -p /var/run/app.pid -m --exec /path/to/app
        $ECHO "."
        ;;
  stop)
        $ECHO -n "Stopping $MYAPPNAME: $MYAPP"
        $SSD --stop -p /var/run/app.pid
        $ECHO "."
        ;;

  *)
        $ECHO "Usage: /etc/init.d/$MYAPPNAME {start|stop)"
        exit 1
esac

exit 0
Have fun.

 

Comments on this Entry

Posted by Anonymous (154.5.xx.xx) on Thu 12 Jan 2006 at 09:24
Webmin automatically generates this skeleton script whenever you create a new Boot and Startup function - and you can set which runlevel the start and stop uses. Makes it all even simplier.

[ Parent | Reply to this comment ]

Posted by rikhenri (86.39.xx.xx) on Sat 14 Jan 2006 at 00:00
[ Send Message ]
Why not /var/run/$MYAPPNAME.pid
instead of /var/run/app.pid ?

[ Parent | Reply to this comment ]

Posted by tong (69.158.xx.xx) on Mon 16 Jan 2006 at 23:21
[ Send Message | View Weblogs ]
yes, and why not adding the green '[ok]' or red '[failed]' indicators? You see, the small script will grow BIG soon. I have to say for this particular job, RedHat is doing a good job of providing a universal tool and simple interface for writing one.

[ Parent | Reply to this comment ]

Posted by Anonymous (65.81.xx.xx) on Wed 25 Jan 2006 at 23:48
What is the command in redhat that you're referring to?

[ Parent | Reply to this comment ]

Posted by tong (64.231.xx.xx) on Thu 26 Jan 2006 at 03:30
[ Send Message | View Weblogs ]
checkinstall or something similar, I don't have redhat now, but I do remember you just need to "source" a system file, then only need to write code for your own part, and all the above common/detailed taskes will be taken care of.

[ Parent | Reply to this comment ]

Posted by Anonymous (82.105.xx.xx) on Thu 7 Jun 2007 at 09:51
My debian-kanotix has his own skel-file in '/etc/init.d':
http://paste.debian.net/29851

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search