From 8e7ed805d6adb4152123187836c1e33d56b1f9d6 Mon Sep 17 00:00:00 2001 From: ambar seksena Date: Sat, 24 Aug 2013 12:20:22 -0700 Subject: [PATCH] Created init.d script for haste-server (markdown) --- init.d-script-for-haste-server.md | 85 +++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 init.d-script-for-haste-server.md diff --git a/init.d-script-for-haste-server.md b/init.d-script-for-haste-server.md new file mode 100644 index 0000000..5f7bace --- /dev/null +++ b/init.d-script-for-haste-server.md @@ -0,0 +1,85 @@ +This is a basic init.d script for haste-server. This has been tested on a CentOS 5.5 ec2 instance. + + + #!/bin/sh + # + # this script: /etc/init.d/hasteserver + # + # modified from: https://gist.github.com/nariyu/1211413 + # + # description: Node.js /var/www/hastebin/server.js + + + . /etc/rc.d/init.d/functions + + USER="ec2-user" + + DAEMON="/usr/local/bin/node" + ROOT_DIR="/var/www/hastebin" + + SERVER="$ROOT_DIR/server.js" + LOG_FILE="$ROOT_DIR/server.js.log" + + LOCK_FILE="/var/lock/subsys/node-server" + + do_start() + { + if [ ! -f "$LOCK_FILE" ] ; then + echo -e $"Starting $SERVER ...\n" + cd $ROOT_DIR + #runuser -l "$USER" -c "$DAEMON $SERVER >> $LOG_FILE &" && echo_success || echo_failure + nohup $DAEMON $SERVER & >> $LOG_FILE && echo_success || echo_failure + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && sudo touch $LOCK_FILE + else + echo "$SERVER is locked. LOCK_FILE: $LOCK_FILE" + RETVAL=1 + fi + } + do_stop() + { + echo $"Stopping nodejs $SERVER ..." + #pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'` + #kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure + pkill -f server.js + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && sudo rm -f $LOCK_FILE + } + + case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; + restart) + do_stop + do_start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + RETVAL=1 + esac + + exit $RETVAL + +Copy and paste it into `/etc/init.d/hasteserver` and then edit these variables in the script according to your installation of haste-server: +* USER +* DAEMON +* ROOT_DIR +* LOG_FILE + +Then `sudo chmod a+x /etc/init.d/hasteserver` + +Now you should be able to do `service hasteserver start` and `service hasteserver stop`. + +You can then use chkconfig to start hastebin automatically on every reboot like this: + + sudo chkconfig --add hasteserver + sudo chkconfig --level 345 hasteserver on + sudo chkconfig --list hasteserver + +