#!/bin/sh # # Simple script to automatically start (and stop) the "foo" server. # Written 2004 by Wayne Pollock, Tampa Florida USA. PATH=/usr/bin LOCK=/var/lock/subsys/foo SERVER=/usr/sbin/foo if [ ! -x $SERVER ] then echo "Can't locate foo server!" exit -1 fi RC=0 # set return code case "$1" in 'start') echo -n 'Starting foo:' $SERVER # or $SERVER & RC=$? echo [ $RC -eq 0 ] && touch $LOCK return $RC ;; 'stop') echo -n 'Stopping foo: ' killall foo # killall - Linux version (*NOT* on Unix!) echo 'done' ;; *) echo "Usage: $0 { start | stop }" exit -1 esac ========================================================================== #! /bin/sh # # A more complete script for controlling a "foo" server. # Written 3/2004 by Wayne Pollock, Tampa Florida USA. # # The following "tag" lines are used by "chkconfig" and various GUI tools # to set the number for the "S" and "K" links, to display a description, # and to show the name of the process, etc.: # # This line tells tools which runlevels to start the service in by # default (can use a "-" here too for the system defaults), the S link # number to use, and the K link number to use. # # chkconfig: 35 99 19 # description: The foo protocol lets remote users access the foo \ # server, ... . # processname: foo # config: /etc/sysconfig/network # config: /etc/sysconfig/foo # pidfile: /var/run/foo.pid # Check that we are root ... so non-root users stop here [ `id -u` = 0 ] || exit 1 # Many services have configuratrion information that is needed # to supply proper command line arguments to the servers. Such # config files (typically in /etc/sysconfig) contain environment # variables, which are "sourced" into the current environment: # Get (source) config file(s): [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network [ -r /etc/sysconfig/foo ] && . /etc/sysconfig/foo # Redhat-like systems contain special shell functions (to display the # green "[ OK ]" or red "{ FAIL ]" messages used to actually start # (such as "daemon") and stop (such as "killproc") a service: # Get functions: . /etc/init.d/functions # Check that networking is up: if [ ${NETWORKING} = "no" ] ; then exit 0 fi # Set the default return value of the script to SUCCESS (0): RETVAL=0 # These shell functions are used to start and stop the server. Shell # functions are used because the code used to start a service is used # in several places (such as "restart" and "start"). Note the # use of the "daemon" shell function defined in /etc/init.d/functions: start() { echo -n $"Starting foo services: " daemon foo -pidfile /var/run/foo.pid "$EXTRAOPTIONS" RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/foo return $RETVAL } stop() { echo -n $"Stopping foo services: " killproc foo RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/foo return $RETVAL } reload(){ echo -n $"Reloading configuration: " killproc foo -HUP RETVAL=$? echo return $RETVAL } restart() { stop start } # See how we were called: case "$1" in start) start ;; stop) stop ;; status) status foo ;; reload) reload ;; restart) restart ;; condrestart) # Restart the server if not running, or do nothing: [ -f /var/lock/subsys/foo ] && restart || : ;; *) echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}" exit 1 ;; esac exit $?