Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:42:57+00:00 2026-06-15T11:42:57+00:00

Basically what i want to accomplish, is some sort of script or method for

  • 0

Basically what i want to accomplish, is some sort of script or method for me to start a node.js socket server script, as a service.

This is to make it so that i don’t have to physically run ‘node server.js’ in SSH and have to sit there with it open.

Any help would be appreciated.

Thanks Scott

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:42:58+00:00Added an answer on June 15, 2026 at 11:42 am

    I don’t see anything criminal in wanting to use something different except forever. In my project i also avoid using this kind of tools and more rely on system capabilities. Since i also try to avoid running my application as root, i cannot use SystemV nor Upstart.

    And here comes mighty shell scripting! I have created few bash scripts that are doing simply tasks, such as process watchdog with ability to start, stop, restart and query status.

    Check this code. Feel free to modify it as you will. To use it — put your command there in COMMAND parameter. And execute ./path_to_script.sh -start. This will create watchdog process, which will start your node process and watch if it dies or not and if yes, it will restart it. It is far not ideal, so if anyone has something to fix, add, remove here, feel free to comment below.

    #!/bin/bash
    
    CURRENT_PATH=$(pwd)
    
    LOGFOLDER=$CURRENT_PATH"/logs/"
    PIDFOLDER=$CURRENT_PATH"/pid/"
    
    #PID file where the this script process ID is stored
    WATCHDOGPIDFILE=$PIDFOLDER"watchdog-admin.pid"
    #PID file where the node process ID is stored
    NODEPIDFILE=$PIDFOLDER"node-admin.pid"
    #Watchdog process error log file
    WATCHDOGLOGFILE=$LOGFOLDER"admin-watchdog-error.log"
    #Node process error log file
    NODELOGFILE=$LOGFOLDER"admin-error.log"
    #Command to be executed on daemon start
    COMMAND="node ./admin/app.js 1> /dev/null 2>> $NODELOGFILE"
    
    ARG_1=$1
    
    start() {
        if [ -e $NODEPIDFILE ]; then
            PID=$(cat $NODEPIDFILE)
            if [ $(ps -o pid | grep $PID) ]; then
                return;
            else
                touch $NODEPIDFILE
                nohup $COMMAND &
                echo $! > $NODEPIDFILE
            fi
        else
            touch $NODEPIDFILE
            nohup $COMMAND &
            echo $! > $NODEPIDFILE
        fi
    }
    
    stop() {
        if [ -e $NODEPIDFILE ]; then
            PID=$(cat $NODEPIDFILE)
            if [ $(ps -o pid | grep $PID) ]; then
                kill -9 $PID
            fi
            rm $NODEPIDFILE
        fi
    }
    
    stopdaemon() {
        stop
        rm $WATCHDOGPIDFILE
        exit 0
    }
    
    log() {
        echo $1 >> $WATCHDOGLOGFILE
    }
    
    keep_alive() {
        if [ -e $NODEPIDFILE ]; then
            PID=$(cat $NODEPIDFILE)
            if [ $(ps -o pid | grep $PID) ]; then
                return;
            else
                log "Jim, he is dead!! Trying ressurection spell..."
                start
            fi
        else
            start
        fi
    }
    
    case x${ARG_1} in
        x-start )
    
            echo "Starting daemon watchdog"
            nohup "$0" -daemon &> /dev/null &
    
        ;;
    
        x-daemon )
    
            if [ -e $WATCHDOGPIDFILE ]; then
                PID=$(cat $WATCHDOGPIDFILE)
                if [ $(ps -o pid | grep $PID) ]; then
                    exit 0;
                fi
            fi
    
            touch $WATCHDOGPIDFILE
    
            echo $$ > $WATCHDOGPIDFILE
    
            #trap the interruption or kill signal
            trap stopdaemon INT SIGINT TERM SIGTERM
    
            start
    
            while true; do
                keep_alive
                wait
                sleep 1
            done
    
        ;;
    
        x-stop )
    
            echo "Stopping daemon watchdog"
            PID=$(cat $WATCHDOGPIDFILE)
            kill $PID
    
        ;;
    
        x-status )
            #check if process is running and PID file exists, and report it back
        ;;
        x )
            echo "Usage {start|stop|status}"
    esac
    
    exit 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me describe the thing that I want to accomplish: I basically want to
I'm probably going to need some sort of jquery or JS to accomplish this,
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I basically want to make things easier by just looping LinkButtons instead of making
I basically want to open a browser window from Word using VBA that does
Hey guys. I have a method that gets called each second which I want
I have settings.php file that I want to keep some constants in, like my
what I want to accomplish is something like the one described in this this
Basically, I want to create an application, and when this application has update, I
What I want basically to acomplish is to schedule on a task_group new work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.