Skip to content

Instantly share code, notes, and snippets.

@ahonor
Created December 2, 2010 17:32
Show Gist options
  • Save ahonor/725714 to your computer and use it in GitHub Desktop.
Save ahonor/725714 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# rundeckd Startup script for the Launcher install of RunDeck
# paramaters:
# - env vars: [RDECK_BASE, RDECK_PORT, RDECK_JAR]
# - standard RDECK_PORT values: [http: 4440, https: 4434]
# RDECK_BASE must be set and exist
[ -z "$RDECK_BASE" -o ! -d "$RDECK_BASE" ] && {
echo "RDECK_BASE not set or does not exist" ;
exit 1 ;
}
# Source installation profile
. $RDECK_BASE/etc/profile
echo_success() {
echo "[OK]"
return 0
}
echo_failure() {
echo "[FAILED]"
return 1
}
prog="rundeckd"
launcher=${RDECK_JAR:=$RDECK_BASE/rundeck-launcher-1.0.0.jar}
rundeckd="${JAVA_HOME}/bin/java ${RDECK_JVM} -Dserver.http.port=${RDECK_PORT:=4440} -jar ${launcher}"
RETVAL=0
PID_FILE=$RDECK_BASE/var/run/rundeckd.pid
LOK_FILE=$RDECK_BASE/var/lock/subsys/$prog
[ -r "$launcher" ] || {
echo "RDECK_JAR not found: $launcher"
exit 1;
}
[ -w $RDECK_BASE/var ] || {
echo "RDECK_BASE dir not writable: $RDECK_BASE"
exit 1 ;
}
mkdir -p $RDECK_BASE/var/run
mkdir -p $RDECK_BASE/var/log
mkdir -p $RDECK_BASE/var/lock/subsys
start() {
RETVAL=0
printf "%s" "Starting $prog: "
[ -f $LOK_FILE -a -f $PID_FILE ] && {
echo_success; #already running
return $RETVAL
}
nohup $rundeckd 2>&1 >>$RDECK_BASE/var/log/service.log &
RETVAL=$?
PID=$!
echo $PID > $PID_FILE
if [ $RETVAL -eq 0 ]; then
touch $LOK_FILE
echo_success
else
echo_failure
fi
return $RETVAL
}
stop() {
RETVAL=0
printf "%s" "Stopping $prog: "
[ ! -f $PID_FILE ] && {
echo_success; #already stopped
return $RETVAL
}
PID=`cat $PID_FILE`
RETVAL=$?
[ -z "$PID" ] && {
echo_failure; #empty pid value"
return $RETVAL;
}
ps -p "$PID" >/dev/null 2>&1
if [ $? -eq 0 ]; then
kill $PID >/dev/null 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] || {
echo_failure; # could not kill process
return $RETVAL
}
fi
rm -f $PID_FILE; # Remove control files
rm -f $LOK_FILE
echo_success
return $RETVAL
}
status() {
RETVAL=0
printf "%s" "Status $prog: "
[ -f "$PID_FILE" ] || {
echo "$prog is stopped";
return $RETVAL;
}
PID=`cat $PID_FILE`
ps -p "$PID" >/dev/null
RETVAL=$?
[ $RETVAL -eq 0 ] && {
echo "$prog (pid $PID) is running"
} || {
echo "$prog dead but pid file exists"
}
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f $LOK_FILE ]; then
stop
start
fi
;;
status)
status $rundeckd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment