diff --git a/Ubuntu-init.d-for-Haste-Server.md b/Ubuntu-init.d-for-Haste-Server.md index 14dd9f6..752230a 100644 --- a/Ubuntu-init.d-for-Haste-Server.md +++ b/Ubuntu-init.d-for-Haste-Server.md @@ -4,7 +4,7 @@ This is a basic init.d script for haste-server running on Ubuntu. This has been ### BEGIN INIT INFO # Provides: hasteserver - # Required-Start: $local_fs $network + # Required-Start: $local_fs $network $redis-server # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 @@ -15,80 +15,72 @@ This is a basic init.d script for haste-server running on Ubuntu. This has been . /lib/lsb/init-functions - # Change the value of "USER" to linux user name who runs - USER=root + # Change the value of "USER" to linux user name who runs Haste Server + USER=root; - # Change the value of "DAEMON" to Node.js process path - DAEMON="/usr/local/bin/node" + # Change the value of "DAEMON" to the Node.js process path + DAEMON="/usr/local/bin/node"; # Change the value of "ROOT_DIR" to hasteserver installation path - ROOT_DIR="/var/www/haste" + ROOT_DIR="/var/www/haste"; # Only change these variables if you intentionally modified Haste Server - SERVER="$ROOT_DIR/server.js" - LOG_FILE="/var/log/hasteserver/server.js.log" + SERVER="$ROOT_DIR/server.js"; + LOG_FILE="/var/log/hasteserver/server.js.log"; do_start() { - if [ ! -f "$LOCK_FILE" ] ; - then - echo `date` >> $LOG_FILE - echo " Starting Hastebin Server ...\n" | tee -a $LOG_FILE - cd $ROOT_DIR - nohup $DAEMON $SERVER >> $LOG_FILE 2>&1 & - RETVAL=$? - pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'` + echo `date` >> $LOG_FILE; + echo " Starting Hastebin Server ..." | tee -a $LOG_FILE; + cd $ROOT_DIR; + nohup $DAEMON $SERVER >> $LOG_FILE 2>&1 & + RETVAL=$?; + pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'`; + if [ ${RETVAL} -eq 0 ]; then - log_success_msg " Hastebin Server Started ($pid)" | tee -a $LOG_FILE + log_success_msg " Hastebin Server Started ($pid)" | tee -a $LOG_FILE; else - log_failure_msg " Hastebin Server failed with exit code ${RETVAL}" | tee -a $LOG_FILE - fi - #[ $RETVAL -eq 0 ] && sudo touch $LOCK_FILE | tee -a $LOG_FILE - else - echo "$SERVER is locked. LOCK_FILE: $LOCK_FILE" | tee -a $LOG_FILE - RETVAL=1 - fi + log_failure_msg " Hastebin Server failed with exit code ${RETVAL}" | tee -a $LOG_FILE; + fi; } do_stop() { - echo `date` >> $LOG_FILE - echo " Stopping Hastebin Server ..." | tee -a $LOG_FILE - pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'` + echo `date` >> $LOG_FILE; + echo " Stopping Hastebin Server ..." | tee -a $LOG_FILE; + pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'`; if [ -z "$pid" ]; then log_success_msg " Hastebin Server was not running\n" | tee -a $LOG_FILE; - exit else - echo " Terminating PID $pid ..." | tee -a $LOG_FILE - kill -9 $pid >> $LOG_FILE 2>&1 - RETVAL=$? + echo " Terminating PID $pid ..." | tee -a $LOG_FILE; + kill -9 $pid >> $LOG_FILE 2>&1; + RETVAL=$?; if [ ${RETVAL} -eq 0 ]; then log_success_msg " Hastebin Server has stopped\n" | tee -a $LOG_FILE; else log_failure_msg " ERROR: Hastebin Server failed to stop - PID $pid could not be terminated\n" | tee -a $LOG_FILE; - fi - fi + fi; + fi; } do_status() { - pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'` - node=`node -v` - if [ -z "$pid" ]; + pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'`; + node=`node -v`; + if [ -z "$pid" ]; then - log_failure_msg " Hastebin Server is not running" - echo " Location: $ROOT_DIR" - echo " Node.js: $node at $DAEMON" - echo " User: $USER" - exit + log_failure_msg " Hastebin Server is not running"; + echo " Location: $ROOT_DIR"; + echo " Node.js: $node at $DAEMON"; + echo " User: $USER"; else - log_success_msg "Hastebin Server is running" - echo " Location: $ROOT_DIR" - echo " Node.js: $node at $DAEMON" - echo " User: $USER" - echo " Process ID: $pid" - uptime=`ps -p "$pid" -o etime= | xargs` - echo " Uptime: $uptime" + log_success_msg "Hastebin Server is running"; + echo " Location: $ROOT_DIR"; + echo " Node.js: $node at $DAEMON"; + echo " User: $USER"; + echo " Process ID: $pid"; + uptime=`ps -p "$pid" -o etime= | xargs`; + echo " Uptime: $uptime"; fi } @@ -99,7 +91,7 @@ This is a basic init.d script for haste-server running on Ubuntu. This has been stop) do_stop ;; - status) + status) do_status ;; restart) @@ -109,7 +101,7 @@ This is a basic init.d script for haste-server running on Ubuntu. This has been *) echo "Usage: $0 {start|stop|status|restart}" exit 0 - ;; + ;; esac exit @@ -133,5 +125,5 @@ Now you should be able to use the commands: If you would like for Haste Server to start at boot, use the command: - sudo /usr/lib/insserv/insserv hasteserver + sudo update-rc.d hasteserver defaults