Search code examples
node.jssolarisstartupreboot

Run script on solaris start


When I fired svcs -a i got legacy_run 11:47:21 lrc:/etc/rc3_d/S99hrms_init_sh but when reboot zone that script is not executing. But it's running properly using /etc/init.d/hrms_init.sh start. I used ln -s /etc/init.d/hrms_init.sh /etc/rc3.d/S99hrms_init.sh to set it in rc3.d. Edited: added script file.

Script

#!/bin/sh

SERVER="/root/hrms/app.js"

do_stop()
{
    echo -n $"Stopping $SERVER: "
    pid=`ps -ef | grep "node $SERVER" | grep -v " grep " | awk '{print $2}'`
    kill -9 (ps -ef | grep "node $SERVER" | grep -v " grep " | awk '{print $2}') > /dev/null 2>&1
    RETVAL=$?
}

case "$1" in
    start)
            node /root/hrms/app.js
            RETVAL=$?
            ;;
    stop)
            do_stop
            ;;
    restart)
            do_stop
            do_start
            ;;
    *)
            echo "Usage: $0 {start|stop|restart}"
            RETVAL=1
esac

exit $RETVAL

Also tried by manifest link. But that manifest shows online* but not running.


Solution

  • The script is executed at boot but fails if the node command is not in the default PATH. If that is the case, you need to set the expected PATH in the startup script.

    By the way,

    echo -n $"Stopping $SERVER: "
    

    is bogus, should be:

    printf "Stopping $SERVER: "