Node.js forever handing via make

Tasks

  • start :: starts application using forever
  • stop :: stops application using forever
  • restart :: restart application using forever

    # This set's your local directory to to your NODE_PATH
    NODE_EXEC    = NODE_PATH=.:$(NODE_PATH)
    
    # This is for local (non `-g`) npm installs.
    # NODE_MODS    = ./node_modules/.bin
    
    # Some good `forever` options.
    FOREVER_OPTS = -p ./logs  \
                    -l server_out.log \
                    -o ./logs/server_out.log \
                    -e ./logs/server_err.log \
                    --append \
                    --plain \
                    --minUptime 1000 \
                    --spinSleepTime 1000
    
    start: setup/dirs
        # starting app in server mode
        $(NODE_EXEC) $(NODE_MODS)/forever $(FOREVER_OPTS) [email protected] server.js
    
    stop:
        # stopping app in server mode
        $(NODE_EXEC) $(NODE_MODS)/forever $(FOREVER_OPTS) [email protected] server.js
    
    restart: setup/dirs
        # restarting app in server mode
        $(NODE_EXEC) $(NODE_MODS)/forever $(FOREVER_OPTS) [email protected] server.js
    
    setup/dirs:
        # creating required directories for `forever`
        mkdir -p logs pids
    

Get the gist.