1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-12-26 03:57:00 +00:00

Initial commit and updated boot start command

moonman407 2017-01-01 19:54:30 -05:00
parent b827afb825
commit 10d9dabad3

@ -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
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}'`
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`
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
}
@ -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