Advertisement
ZappeL

spawn-nodejs

Mar 20th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.79 KB | None | 0 0
  1. #!/sbin/runscript
  2. # Copyright 2013 Armas Spann
  3. # Distributed under the terms of the GNU General Public License v2
  4. # $Header: NeedsAnEyeOnIt $
  5.  
  6. PROGNAME=${SVCNAME#*.}
  7. SPAWNNJS=/usr/bin/node
  8. PIDPATH=/var/run/spawn-nodejs
  9. PIDFILE=${PIDPATH}/${PROGNAME}.pid
  10.  
  11. depend() {
  12.         need net mongodb
  13. }
  14.  
  15. start() {
  16.         if [ "${SVCNAME}" = "spawn-nodejs" ]; then
  17.                 eerror "You are not supposed to run this script directly. Create a symlink"
  18.                 eerror "for the nodejs application you want to run as well as a copy of the"
  19.                 eerror "configuration file and modify it appropriately like so..."
  20.                 eerror
  21.                 eerror "  ln -s spawn-nodejs /etc/init.d/spawn-nodejs.trac"
  22.                 eerror "  cp /etc/conf.d/spawn-nodejs /etc/conf.d/spawn-nodejs.trac"
  23.                 eerror "  `basename "${EDITOR}"` /etc/conf.d/spawn-nodejs.trac"
  24.                 eerror
  25.                 return 1
  26.         fi
  27.  
  28.         if [ -z "${NJS_PATH}" ]; then
  29.                 eerror "You need to specify which \$NJS_PATH"
  30.                 eerror "you want to start."
  31.                 eerror "Please adjust /etc/conf.d/spawn-nodejs.${PROGNAME}"
  32.                 return 1
  33.         fi
  34.  
  35.         ebegin "Starting nodejs application ${PROGNAME}"
  36.         checkpath -q -d -m 700 /var/run/spawn-nodejs
  37.  
  38.         env -i NODE_ENV=${NJS_MODE} /sbin/start-stop-daemon -u ${NJS_USER} -g ${NJS_GROUP} -mp ${PIDFILE} -bqS -x ${SPAWNNJS} -d ${NJS_PATH} -n ${PROGNAME} -- ${NJS_MAIN}
  39.         RETVAL=$?
  40.  
  41.         [ "${RETVAL}" != "0" ] && break
  42.         eend ${RETVAL}
  43. }
  44.  
  45. stop() {
  46.         local X RETVAL=0
  47.  
  48.         ebegin "Stopping nodejs application ${PROGNAME}"
  49.         start-stop-daemon --stop --pidfile ${PIDFILE} || \
  50.  
  51.         { RETVAL=$? && break ; }
  52.         eend ${RETVAL}
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement