Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is my Node.JS webserver startup script for RedHat EL 6.

#!/bin/sh
# chkconfig:   345 01 01
# description: DeepFlow startup script

case $1 in
        start)
            echo "Starting DeepFlow"
            cd /home/admin/Desktop/DeepFlow/server
            ./bin/node js/server.js
            ;;
        stop)
            echo "Stopping DeepFlow"
            killall node
            ;;
esac

For some reason, when I manually type

            cd /home/admin/Desktop/DeepFlow/server
            ./bin/node js/server.js

everything works fine, but when I do service DeepFlow start I get a Node.JS error:

Starting DeepFlow

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: failed to connect to [localhost:27017]

What is the difference between manually typing the script lines in a terminal, and running the script with service?

share|improve this question

1 Answer 1

up vote -1 down vote accepted

Try using full pathnames.

NODE_BIN="/home/admin/Desktop/DeepFlow/server/bin/node"
SERVER_JS="/home/admin/Desktop/DeepFlow/server/js/server.js"
echo "Starting DeepFlow"
$NODE_BIN $SERVER_JS
;;

Also it would be good to check which user is starting the server. If it's run on startup, the owner will be 'root'.

share|improve this answer
    
Nope, didn't work. –  Randomblue Feb 18 '13 at 10:00
    
Do you have some library path in your env-variables? Maybe using export NODE_PATH="/home/admin/Desktop/DeepFlow/server/" would help. –  Kride Feb 18 '13 at 10:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.