-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/kpdecker/forever into v0.5.x
- Loading branch information
Showing
3 changed files
with
176 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
# | ||
# initd-example Node init.d | ||
# | ||
# chkconfig: 345 80 20 | ||
# description: Node init.d example | ||
# processname: node | ||
# pidfile: /var/run/initd-example.pid | ||
# logfile: /var/log/initd-example.log | ||
# | ||
|
||
# Source function library. | ||
. /etc/init.d/functions | ||
|
||
NAME=initd-example # Unique name for the application | ||
PORT=1234 # Port (in this case the application uses process.env.PORT to set the port) | ||
INSTANCE_DIR=/var/www/$NAME # Location of the application source | ||
SOURCE_NAME=main.js # Name os the applcation entry point script | ||
|
||
user=apache | ||
pidfile=/var/run/$NAME.pid | ||
logfile=/var/log/$NAME.log | ||
forever_dir=/var/run/forever # Forever root directory. | ||
|
||
node=node | ||
forever=forever | ||
awk=awk | ||
sed=sed | ||
|
||
start() { | ||
echo "Starting $NAME node instance: " | ||
|
||
if [ "$id" = "" ]; then | ||
# Create the log and pid files, making sure that the target use has access to them | ||
touch $logfile | ||
chown $user $logfile | ||
|
||
touch $pidfile | ||
chown $user $pidfile | ||
|
||
# Launch the application | ||
daemon --user=$user \ | ||
env PORT=$PORT \ | ||
$forever start -p $forever_dir --pidfile $pidfile -l $logfile -a -d $INSTANCE_DIR $SOURCE_NAME | ||
RETVAL=$? | ||
else | ||
echo "Instance already running" | ||
RETVAL=0 | ||
fi | ||
} | ||
|
||
restart() { | ||
echo -n "Restarting $NAME node instance : " | ||
if [ "$id" != "" ]; then | ||
$forever restart -p $forever_dir $id | ||
RETVAL=$? | ||
else | ||
start | ||
fi | ||
} | ||
|
||
stop() { | ||
echo -n "Shutting down $NAME node instance : " | ||
if [ "$id" != "" ]; then | ||
$forever stop -p $forever_dir $id | ||
else | ||
echo "Instance is not running"; | ||
fi | ||
RETVAL=$? | ||
} | ||
|
||
getForeverId() { | ||
local pid=$(pidofproc -p $pidfile) | ||
$forever list -p $forever_dir | $sed -e 's/\x1b\[[0-9; ]*m//g' | $awk "\$4 == \"$pid]\" { gsub(/[\[\]]/, \"\", \$1); print \$1; }" | ||
} | ||
id=$(getForeverId) | ||
|
||
case "$1" in | ||
start) | ||
start | ||
;; | ||
stop) | ||
stop | ||
;; | ||
status) | ||
status -p ${pidfile} | ||
;; | ||
restart) | ||
restart | ||
;; | ||
*) | ||
echo "Usage: {start|stop|status|restart}" | ||
exit 1 | ||
;; | ||
esac | ||
exit $RETVAL |
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