[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

init.d scripts for linux, updated runclient.sh



For general consumption, and to give back a little...

I'm running hobbit on several linux servers, most of them Red Hat or 
variants thereof. Following are the scripts I use to start/stop the hobbit 
server and client.

You'll need to modify the locations for pidfile and config in the script 
header comments, plus the values for BBUSER and BBINIT in the scripts 
themselves.

These are chkconfig friendly scripts. If you're using chkconfig, after 
creating the files you should:

# chkconfig --add hobbitd
# chkconfig hobbitd on
# chkconfig --list hobbitd

# chkconfig --add hobbitc
# chkconfig hobbitc on
# chkconfig --list hobbitc

Then you can use the 'service' command to control hobbit. See these 
commands for options:

# service hobbitd help

# service hobbitc help

I've also attached a modified runclient.sh that adds 'restart' and 
'status' options.

Henrik, please feel free to massage these as necessary (for example, so 
the configure/make commands fill in the necessary blanks) and include them 
in the snapshots/packages. In the code below I've use {UPPER_CASE} to 
indicate areas that need to be changed before use on a user's systems.



----------------------------------------
/etc/init.d/hobbitd
----------------------------------------
#!/bin/sh
#
# hobbitd - This script starts and stops the Hobbit server daemon
#
# chkconfig: - 87 13
#
# description: Hobbit system monitor server daemon.
# processname: hobbitd
# pidfile: /{PATH_TO_LOGS}/hobbit/hobbitlaunch.pid
# config: /{PATH_TO_HOBBIT}/server/etc/hobbitserver.cfg

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

BBUSER="{HOBBIT_USER}"
BBINIT="/{PATH_TO_HOBBIT}/server/hobbit.sh"

# Pass control off to the hobbit init script. Not perfect
# for every possible OS, but it does the job well enough.

/bin/su - $BBUSER -c "$BBINIT \"$1\""

#EOF(hobbitd)
----------------------------------------


----------------------------------------
/etc/init.d/hobbitc
----------------------------------------
#!/bin/sh
#
# hobbitc - This script starts and stops the Hobbit client daemon
#
# chkconfig: - 88 12
#
# description: Hobbit system monitor client daemon.
# processname: hobbitc
# pidfile: /{PATH_TO_CLIENT_LOGS}/hobbit/clientlaunch.pid
# config: /{PATH_TO_HOBBIT}/client/etc/clientlaunch.cfg

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

BBUSER="{HOBBIT_USER}"
BBINIT="/{PATH_TO_HOBBIT}/client/runclient.sh"

# Pass control off to the hobbit init script. Not perfect
# for every possible OS, but it does the job well enough.

/bin/su - $BBUSER -c "$BBINIT \"$1\""

#EOF(hobbitc)
----------------------------------------


----------------------------------------
{HOBBIT_HOME}/client/runclient.sh
----------------------------------------
#!/bin/sh
#----------------------------------------------------------------------------#
# Hobbit client bootup script.   #
#   #
# This invokes hobbitlaunch, which in turn runs the Hobbit client and any  
 #
# extensions configured.   #
#   #
# Copyright (C) 2005 Henrik Storner <henrik (at) hswn.dk>   #
#   #
# This program is released under the GNU General Public License (GPL),   #
# version 2. See the file "COPYING" for details.   #
#   #
#----------------------------------------------------------------------------#
#
# $Id: runclient.sh,v 1.4 2005/08/04 12:16:27 henrik Exp $

# Default settings for this client
MACHINEDOTS="`uname -n`"                        # This systems hostname
BBOSTYPE="`uname -s | tr '[A-Z]' '[a-z]'`"      # This systems operating 
system in lowercase

###
### mod(smith.js.8 (at) pg.com)20050821
###
### note: this was lifted from the server hobbit.sh script
case "`uname -s`" in
   "SunOS")
        ID=/usr/xpg4/bin/id
        ;;
   *)
        ID=id
        ;;
esac

if test `$ID -un` != {HOBBIT_USER}
then
        echo "Hobbit client must be started as the {HOBBIT_USER} user"
        exit 1
fi
###
### end(smith.js.8 (at) pg.com)20050821
###

# Commandline mods for the defaults
while test "$1" != ""
do
        case "$1" in
          --hostname=*)
                MACHINEDOTS="`echo $1 | sed -e's/--hostname=//'`"
                ;;
          --os=*)
                BBOSTYPE="`echo $1 | sed -e's/--os=//' | tr '[A-Z]' 
'[a-z]'`"
                ;;
          --help)
                echo "Usage: $0 [--hostname=CLIENTNAME] 
[--os=rhel3|linux22] start|stop"
                exit 0
                ;;
          start)
                CMD=$1
                ;;
          stop)
                CMD=$1
                ;;
###
### mod(smith.js.8 (at) pg.com)20050821
###
          restart)
                CMD=$1
                ;;
          status)
                CMD=$1
                ;;
###
### end(smith.js.8 (at) pg.com)20050821
###
        esac

        shift
done

OLDDIR="`pwd`"
cd "`dirname $0`"
HOBBITCLIENTHOME="`pwd`"
cd "$OLDDIR"

MACHINE="`echo $MACHINEDOTS | sed -e's/\./,/g'`"

export MACHINE MACHINEDOTS BBOSTYPE HOBBITCLIENTHOME

case "$CMD" in
  "start")
        if test ! -w $HOBBITCLIENTHOME/logs; then
                echo "Cannot write to the $HOBBITCLIENTHOME/logs 
directory"
                exit 1
        fi
        if test ! -w $HOBBITCLIENTHOME/tmp; then
                echo "Cannot write to the $HOBBITCLIENTHOME/tmp directory"
                exit 1
        fi

        $HOBBITCLIENTHOME/bin/hobbitlaunch 
--config=$HOBBITCLIENTHOME/etc/clientlaunch.cfg 
--log=$HOBBITCLIENTHOME/logs/clientlaunch.log 
--pidfile=$HOBBITCLIENTHOME/logs/clientlaunch.pid
        if test $? -eq 0; then
                echo "Hobbit client for $BBOSTYPE started on $MACHINEDOTS"
        else
                echo "Hobbit client startup failed"
        fi
        ;;

  "stop")
### mod(smith.js.8 (at) pg.com)20050821-one liner-change test from -f to -s
        #if test -f $HOBBITCLIENTHOME/logs/clientlaunch.pid; then
        if test -s $HOBBITCLIENTHOME/logs/clientlaunch.pid; then
                kill `cat $HOBBITCLIENTHOME/logs/clientlaunch.pid`
                echo "Hobbit client stopped"
        else
                echo "Hobbit client not running"
        fi
        ;;
###
### mod(smith.js.8 (at) pg.com)20050821
###
   "restart")
        if test -s $HOBBITCLIENTHOME/logs/clientlaunch.pid
        then
                $0 stop
                sleep 10
                $0 start
        else
                echo "Hobbit client does not appear to be running, 
starting it"
                $0 start
        fi
        ;;
   "status")
        if test -s $HOBBITCLIENTHOME/logs/clientlaunch.pid
        then
                kill -0 `cat $HOBBITCLIENTHOME/logs/clientlaunch.pid`
                if test $? -eq 0
                then
                        echo "Hobbit client (clientlaunch) running with 
PID `cat $HOBBITCLIENTHOME/logs/clientlaunch.pid`"
                else
                        echo "Hobbit client not running, removing stale 
PID file"
                        rm -f $HOBBITCLIENTHOME/logs/clientlaunch.pid
                fi
        else
                echo "Hobbit client (clientlaunch) does not appear to be 
running"
        fi
        ;;

   *)
        echo "Usage: $0 start|stop|restart|status"
        break;
###
### end(smith.js.8 (at) pg.com)20050821
###
esac

exit 0

#EOF(runclient.sh)