Created
August 21, 2009 17:41
-
-
Save ideaoforder/172232 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
### BEGIN INIT INFO | |
# Provides: workling | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start/stop worklings | |
### END INIT INFO | |
# | |
# workling This init.d script is used to start worklings. | |
# It basically just calls the workling start/stop scripts. | |
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin" | |
set -e | |
. /lib/lsb/init-functions | |
ROOT="YOUR_WEB_APP" | |
PID=$ROOT"log/" | |
WORKLINGS=1 # number of worklings to create | |
test -f /etc/default/rcS && . /etc/default/rcS | |
LIST=$(echo $WORKLINGS | awk '{for (i=0;i<$1;i++) { print i; } }') | |
workling_stop() { | |
for W in $LIST; do | |
WORKLING=$PID"workling"$W".pid" | |
if [ -e $WORKLING ]; then | |
if kill `cat $WORKLING`; then | |
success=0 | |
else | |
success=1 | |
fi | |
#else | |
# log_failure_msg "Unable to find workling's PID. Please make sure that this workling is running, and pid file is in /var/run/starling.pid" | |
# return 1 | |
fi | |
done | |
return $success | |
} | |
workling_start() { | |
for W in $LIST; do | |
START_COMMAND=$ROOT"script/workling_client start" | |
$START_COMMAND | |
done | |
} | |
# Stupid hack to keep lintian happy. (Warrk! Stupidhack!). | |
case $1 in | |
start) | |
log_daemon_msg "Starting worklings" "huzzah!" | |
if workling_start; then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
stop) | |
log_daemon_msg "Stopping worklings" "BooYaa!" | |
if workling_stop; then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
restart) | |
log_daemon_msg "Restarting worklings" "HiYaa!" | |
if ! workling_stop; then | |
log_end_msg 1 || true | |
fi | |
sleep 2 | |
if workling_start; then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
*) | |
log_success_msg "Usage: /etc/init.d/workling {start|stop|restart}" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment