#!/bin/sh # # /etc/init.d/mds # # by Anton Hendriks, Metatude B.V. # # chkconfig: 345 95 07 # description: Metatude Dialogue Server # # Change the following values according to your installation: # The user on your machine that runs the mds: MDS_USER="mds" # The installation dir of the MDS: WORKDIR="/opt/mds" # Name of the program to start: PRG_NAME="mds" # Description: DESC="Metatude Dialogue Server" # Place were we save the process ID of the MDS: PIDFILE="/var/run/$PRG_NAME.pid" # Check how the script was called: case "$1" in start) echo -n "Starting $DESC: " # Check for an existing existing file with a process ID: if [ -f "$PIDFILE" ] then # If found, then read the content: PID=`cat $PIDFILE` # If the content is empty, just remove the file if [ -z $PID ] then rm -f $PIDFILE else # check if there is a process running that has the Process ID in the process id file: PID2=`ps hax | awk '{print $1}' | grep $PID` if [ -z $PID2 ] # If there is no such process, just remove the pidfile: then rm -f $PIDFILE else # If there is a process running, then the MDS is allready started, we exit this script: echo "$PRG_NAME allready running in background" exit 2 fi fi fi # If there was no file with a process ID, we do another check to see if the MDS was started previously: PID=`ps hw --User $MDS_USER | grep $PRG_NAME.lax | grep -v grep | awk 'NR==1 {print $1}'` if [ ! -z $PID ] # If there is a process java running under the MDS user, we assume it is the MDS, and we exit this script: then echo "$PRG_NAME allready running in foreground" exit 3 fi # If we come here we assume the MDS is NOT running, so we start it: # screen output (stdout and stderr) will be directed to a logfile, # We assume you put these values in the MDS.lax file # start the MDS: su $MDS_USER -c "$WORKDIR/$PRG_NAME" & # Wait a bit for the JVM to start sleep 2; # Capture the Process ID of the JVM that is running the MDS and put it in a file for future reference: ps hw --User $MDS_USER | grep $PRG_NAME.lax | grep -v grep | awk 'NR==1 {print $1}' > $PIDFILE echo $PRG_NAME # DONE! ;; stop) echo -n "Stopping $DESC: " # Check for a process id file, and check if it is not empty: if [ -f "$PIDFILE" ] then PID=`cat "$PIDFILE"` if [ -z $PID ] then rm -f $PIDFILE echo -n "Bogus Pidfile found" exit 5 else # If the Process ID file was not empty, we stop the MDS, kill $PID # Remove the Process ID file: rm -f $PIDFILE echo $PRG_NAME echo -n "" fi else echo -n "Pidfile not found" exit 4 fi # DONE! ;; restart) $0 stop sleep 1 $0 start # DONE! ;; *) echo "Usage: /etc/init.d/mds {start|stop|restart}" >&2 exit 1 ;; esac exit 0