Open pieterb opened 11 years ago
We have some examples for this. For the handle service and the epic service. For the epic service it is: "/etc/init.d/epic"
#
#
configSelect="*" prog=rackup epicBinDir=/opt/jruby/bin/
createDir() { for i in ${epicRunDir} ${epicLogDir}; do [ -d "$i" ] || { mkdir -p $i chown -R $epicUser:$epicUser $i } done }
status() { if [ -f $epicPID ] && ps -ef | grep -P "\b$(<$epicPID)\b" | grep -q java; then state="Running" statusValue=0 else state="NOT Running" statusValue=1 fi
echo "Service : $prog: for user: $epicUser with config: $epicConfig : $state"
# return the status
return $statusValue
}
start() { [ -x $epicBinDir/$prog ] || exit 5 [ -f /etc/sysconfig/epic-server ] && . /etc/sysconfig/epic-server statusValue=0
# Start daemon.
echo -n "Starting : $prog: for user: $epicUser with config: $epicConfig : "
# check if server is already running
status > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Already started, NOT restarting"
statusValue=1
else
su - $epicUser -c "cd $epicConfig ; rackup --pid=$epicPID >>$epicLogDir/rackup.log 2>&1 & disown %1"
for i in {1..20} ; do
sleep 1
status > /dev/null 2>&1
if [ $? -eq 0 ]
then
break
fi
done
sleep 1
status > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo 'OK'
else
echo 'FAILED'
statusValue=1
fi
fi
}
stop() { statusValue=0
# Stop daemon.
echo -n "Stopping : $prog: for user: $epicUser with config: $epicConfig : "
# check if server is already running
status > /dev/null 2>&1
if [ $? -eq 1 ]
then
echo "Already stopped"
statusValue=1
else
kill $(<$epicPID)
sleep 2
status > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo 'FAILED'
statusValue=1
else
rm $epicPID > /dev/null 2>&1
echo 'OK'
fi
fi
}
###########################################################################
##########################################################################
if [ -n "$2" ] then configSelect="$2" fi
case "$1" in start)
for configuration in `find /etc/epic/${configSelect}.conf`; do
. $configuration
createDir
start
done
;;
stop)
for configuration in `find /etc/epic/${configSelect}.conf`; do
. $configuration
stop
done
;;
status)
for configuration in find /etc/epic/${configSelect}.conf
; do
. $configuration
status $prog
done
;;
restart)
for configuration in find /etc/epic/${configSelect}.conf
; do
. $configuration
stop
createDir
start
done
;;
*)
echo $"Usage: $0 {start|stop|status|restart} [config]"
exit 2
esac
It works with a config file: "/etc/epic/handle1_epic_v2_test_prod.conf"
#
epicUser=handle1 #
epicConfig=epic_v2_test_prod #
epicConfigDir=/home/${epicUser}/${epicConfig} #
epicLogDir=/var/log/${epicUser}/${epicConfig} #
epicRunDir=/var/run/${epicUser} #
epicPID=${epicRunDir}/${epicConfig}.pid
#
#
We could use a common startup script for running the webservice (calling rackup, deamonizing(?), storing a process ID etc.) This common startup script could then be invoked by the (more OS-specific) init-script.