-
-
Save rsolomo/4022176 to your computer and use it in GitHub Desktop.
Node.js startup script for AWS EC2 Linux box
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
#!/bin/bash | |
# nodejs - Startup script for node.js server | |
# chkconfig: 35 85 15 | |
# description: node is an event-based web server. | |
# processname: node | |
# server: /path/to/your/node/file.js | |
# pidfile: /var/run/nodejs.pid | |
# | |
. /etc/rc.d/init.d/functions | |
OPTIONS=" /path/to/your/node/file.js" | |
LOGFILE=" /var/log/nodejs/nodejs.log" | |
SYSCONFIG="/etc/sysconfig/nodejs" | |
nodejs=${NODEJS-/usr/local/bin/node} | |
NODEJS_USER=ec2-user | |
NODEJS_GROUP=ec2-user | |
. "$SYSCONFIG" || true | |
start() | |
{ | |
echo -n $"Starting nodejs: " | |
daemon --user "$NODEJS_USER" "$nodejs $OPTIONS >> $LOGFILE &" | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/nodejs | |
} | |
stop() | |
{ | |
echo -n $"Stopping nodejs: " | |
killproc /usr/local/bin/node | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/nodejs | |
} | |
restart () { | |
stop | |
start | |
} | |
ulimit -n 12000 | |
RETVAL=0 | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart|reload|force-reload) | |
restart | |
;; | |
condrestart) | |
[ -f /var/lock/subsys/nodejs ] && restart || : | |
;; | |
status) | |
status $nodejs | |
RETVAL=$? | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" | |
RETVAL=1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment