Initial commit and updated boot start command
| @@ -4,7 +4,7 @@ This is a basic init.d script for haste-server running on Ubuntu. This has been | |||||||
|  |  | ||||||
| 	### BEGIN INIT INFO | 	### BEGIN INIT INFO | ||||||
| 	# Provides:          hasteserver | 	# Provides:          hasteserver | ||||||
| 	# Required-Start:    $local_fs $network | 	# Required-Start:    $local_fs $network $redis-server | ||||||
| 	# Required-Stop:     $local_fs | 	# Required-Stop:     $local_fs | ||||||
| 	# Default-Start:     2 3 4 5 | 	# Default-Start:     2 3 4 5 | ||||||
| 	# Default-Stop:      0 1 6 | 	# 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 | 	. /lib/lsb/init-functions | ||||||
|  |  | ||||||
| 	# Change the value of "USER" to linux user name who runs | 	# Change the value of "USER" to linux user name who runs Haste Server | ||||||
| 	USER=root | 	USER=root; | ||||||
|  |  | ||||||
| 	# Change the value of "DAEMON" to Node.js process path | 	# Change the value of "DAEMON" to the Node.js process path | ||||||
| 	DAEMON="/usr/local/bin/node" | 	DAEMON="/usr/local/bin/node"; | ||||||
| 	# Change the value of "ROOT_DIR" to hasteserver installation path | 	# 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 | 	# Only change these variables if you intentionally modified Haste Server | ||||||
| 	SERVER="$ROOT_DIR/server.js" | 	SERVER="$ROOT_DIR/server.js"; | ||||||
| 	LOG_FILE="/var/log/hasteserver/server.js.log" | 	LOG_FILE="/var/log/hasteserver/server.js.log"; | ||||||
|  |  | ||||||
| 	do_start() | 	do_start() | ||||||
| 	{ | 	{ | ||||||
| 			if [ ! -f "$LOCK_FILE" ] ; | 			echo `date` >> $LOG_FILE; | ||||||
| 		  then | 			echo " Starting Hastebin Server ..." | tee -a $LOG_FILE; | ||||||
| 			echo `date` >> $LOG_FILE | 			cd $ROOT_DIR; | ||||||
| 					echo " Starting Hastebin Server ...\n" | tee -a $LOG_FILE |  | ||||||
| 					cd $ROOT_DIR |  | ||||||
| 			nohup $DAEMON $SERVER >> $LOG_FILE 2>&1 & | 			nohup $DAEMON $SERVER >> $LOG_FILE 2>&1 & | ||||||
| 			RETVAL=$? | 			RETVAL=$?; | ||||||
| 			pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'` | 			pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'`; | ||||||
|  |  | ||||||
| 			if [ ${RETVAL} -eq 0 ]; | 			if [ ${RETVAL} -eq 0 ]; | ||||||
| 			  then | 			  then | ||||||
| 				log_success_msg " Hastebin Server Started ($pid)" | tee -a $LOG_FILE | 					log_success_msg " Hastebin Server Started ($pid)" | tee -a $LOG_FILE; | ||||||
| 			  else | 			  else | ||||||
| 				log_failure_msg " Hastebin Server failed with exit code ${RETVAL}" | tee -a $LOG_FILE | 					log_failure_msg " Hastebin Server failed with exit code ${RETVAL}" | tee -a $LOG_FILE; | ||||||
| 			  fi | 			  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 |  | ||||||
| 	} | 	} | ||||||
| 	do_stop() | 	do_stop() | ||||||
| 	{ | 	{ | ||||||
| 			echo `date` >> $LOG_FILE | 			echo `date` >> $LOG_FILE; | ||||||
| 		echo " Stopping Hastebin Server ..." | tee -a $LOG_FILE | 			echo " Stopping Hastebin Server ..." | tee -a $LOG_FILE; | ||||||
| 			pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'` | 			pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'`; | ||||||
| 			if [ -z "$pid" ]; | 			if [ -z "$pid" ]; | ||||||
| 			  then | 			  then | ||||||
| 				log_success_msg " Hastebin Server was not running\n" | tee -a $LOG_FILE; | 				log_success_msg " Hastebin Server was not running\n" | tee -a $LOG_FILE; | ||||||
| 				exit |  | ||||||
| 			  else | 			  else | ||||||
| 				echo " Terminating PID $pid ..." | tee -a $LOG_FILE | 				echo " Terminating PID $pid ..." | tee -a $LOG_FILE; | ||||||
| 					kill -9 $pid >> $LOG_FILE 2>&1 | 					kill -9 $pid >> $LOG_FILE 2>&1; | ||||||
| 				RETVAL=$? | 				RETVAL=$?; | ||||||
| 				if [ ${RETVAL} -eq 0 ]; | 				if [ ${RETVAL} -eq 0 ]; | ||||||
| 				  then | 				  then | ||||||
| 					log_success_msg " Hastebin Server has stopped\n" | tee -a $LOG_FILE; | 					log_success_msg " Hastebin Server has stopped\n" | tee -a $LOG_FILE; | ||||||
| 				  else | 				  else | ||||||
| 					log_failure_msg " ERROR: Hastebin Server failed to stop - PID $pid could not be terminated\n" | tee -a $LOG_FILE; | 					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() | 	do_status() | ||||||
| 	{ | 	{ | ||||||
| 		pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'` | 			pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'`; | ||||||
| 		node=`node -v` | 			node=`node -v`; | ||||||
| 			if [ -z "$pid" ]; | 			if [ -z "$pid" ]; | ||||||
| 			  then | 			  then | ||||||
| 				log_failure_msg " Hastebin Server is not running" | 				log_failure_msg " Hastebin Server is not running"; | ||||||
| 				echo " Location: $ROOT_DIR" | 				echo " Location: $ROOT_DIR"; | ||||||
| 				echo " Node.js: $node at $DAEMON" | 				echo " Node.js: $node at $DAEMON"; | ||||||
| 				echo " User: $USER" | 				echo " User: $USER"; | ||||||
| 				exit |  | ||||||
| 			  else | 			  else | ||||||
| 				log_success_msg "Hastebin Server is running" | 				log_success_msg "Hastebin Server is running"; | ||||||
| 				echo " Location: $ROOT_DIR" | 				echo " Location: $ROOT_DIR"; | ||||||
| 				echo " Node.js: $node at $DAEMON" | 				echo " Node.js: $node at $DAEMON"; | ||||||
| 				echo " User: $USER"			 | 				echo " User: $USER"; | ||||||
| 				echo " Process ID: $pid" | 				echo " Process ID: $pid"; | ||||||
| 				uptime=`ps -p "$pid" -o etime= | xargs` | 				uptime=`ps -p "$pid" -o etime= | xargs`; | ||||||
| 				echo " Uptime: $uptime" | 				echo " Uptime: $uptime"; | ||||||
| 			  fi | 			  fi | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -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: | 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 | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user