The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need to restart if the service is down

Discussion in 'General Discussion' started by shufil, Nov 28, 2014.

  1. shufil

    shufil Well-Known Member

    Joined:
    Mar 19, 2014
    Messages:
    71
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Hello friends.....


    I have a application using node.js , port number is 3001 and 3007 , some time application going to down,in this time
    lsof -i:3001 result is blank becouse service is not running ,so
    i have go to application folder and run this command - nohup node test_app.js & .

    So i create a bash script that will be check port or application working or not if down will run starting command , and added in crontab with run every minute , but its not working correctly ,

    #!/bin/bash
    #service=node

    if (( $(lsof -i:3007 | wc -l) > 0 ))
    then
    nohup node test_app.js &
    else
    echo "$service is running!!!"
    fi

    Please advice me how can i do this , is this possible any other way like install monitoring tool , i search some monitoring tooles like monits but its very confusing me , so plz help , plz share your experience .
     
  2. karlos.vanger

    karlos.vanger Member

    Joined:
    Jun 4, 2013
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
  3. shufil

    shufil Well-Known Member

    Joined:
    Mar 19, 2014
    Messages:
    71
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator

    Thanks for reply ,

    I just try this command as per following site

    #!/bin/bash
    #service monitoring
    /bin/netstat -tulpn | awk '{print $4}' | awk -F: '{print $4}' | grep ^3007$ > /dev/null 2>/dev/null
    a=$(echo $?)
    if test $a -ne 0
    then
    echo "node.js service down"
    nohup node test_app.js & > /dev/null 2>/dev/null
    else
    sleep 0
    fi

    so its correctly start application and give a massage that is " node.js service down ",
    so now application is running , then again i run the script so the same massage replicating ,
    its means application runing or down script working same .

    so can we use same script for if the application is running we no need to get any massage and no need to run
    nohup node test_app.js &. (restarting command).

    Plz advice me..
     
    #3 shufil, Nov 28, 2014
    Last edited: Nov 28, 2014
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    653
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Could you elaborate further on this statement? For instance, is the application running successfully or is it still failing?

    Thank you.
     
  5. shufil

    shufil Well-Known Member

    Joined:
    Mar 19, 2014
    Messages:
    71
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    If the application running or down the script output getting same , like if the node.js application running and we are try to run the script , so that time script output should be " its working fine " . no need to try restart or start again,

    but its application running or down the script try to start or restart application.
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    653
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You may want to consult with a developer or system administrator to assist you with your custom script if it's not accurately detecting if the service is running.

    Thank you.
     
  7. shufil

    shufil Well-Known Member

    Joined:
    Mar 19, 2014
    Messages:
    71
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Michael,

    This is normal web site , am using bash script for start a service if it down , that service port 3007 , but my bash script every time given same result , even service is working bash script will try to restart , that is my problem.

    also i noted last day i upgrade whm , after this user all crones not working , then i restart crone service and copy all crone jobs from user to root , but i think particular crone not working .
    00 3 * * * /bin/sh /path/mysql_backup.sh
    00 7 * * * /bin/sh /path/rtm.sh
    05 7 * * * /bin/sh /path/rtm2.sh
    02 * * * * /bin/sh /path/test.sh

    If any one have any idea about this plz help me .
     
Loading...

Share This Page