Skip to content

Instantly share code, notes, and snippets.

@morphizer
Created October 23, 2012 03:28
Show Gist options
  • Select an option

  • Save morphizer/3936465 to your computer and use it in GitHub Desktop.

Select an option

Save morphizer/3936465 to your computer and use it in GitHub Desktop.

Revisions

  1. morphizer created this gist Oct 23, 2012.
    65 changes: 65 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    #!/bin/bash
    #
    # servicename Starts and stops a service
    #
    # chkconfig: 345 90 30
    # description: Example init script for older node.js application using spark
    #
    # processname: servicename

    ### BEGIN INIT INFO
    # Provides: servicename
    # Required-Start: $local_fs $network
    # Required-Stop: $local_fs
    # Default-Start: 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start the node.js server for servicename
    # Description:
    ### END INIT INFO

    # Source function library
    . /etc/init.d/functions

    SERVICENAME_BIN=/usr/local/project/bin/project
    lockfile=/var/lock/subsys/project
    logfile=/var/log/project/project.log

    start() {
    echo -n "Starting project: "
    [ -x $SERVICENAME_BIN ] || exit 5
    daemon --check project "$SERVICENAME_BIN >> $logfile &"
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $lockfile
    return $RETVAL
    }

    stop() {
    echo -n "Shutting down project: "
    killproc $SERVICENAME_BIN
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f $lockfile
    return $RETVAL
    }

    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    status)
    status $SERVICENAME_BIN
    ;;
    restart)
    stop
    start
    ;;
    *)
    echo "Usage: $0 {start|stop|status|restart}"
    exit 2
    ;;
    esac
    exit $?
    4 changes: 4 additions & 0 deletions project
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    #!/usr/local/bin/node

    process.chdir(__dirname + '/..');
    require('../node_modules/.bin/spark');