Auto restart script does not work

I have a service that are not 100% stable and stops from time to time.
So I have a script that do restart the service if it does not run.

This script works win on Ubuntu 9.04 but will not start the service in Ubuntu 10.10

If I run the part that do starts the service from CLI, it starts normal.
Any idea of what is wrong?

This runs fine manually

/var/bin/Server.x86 &

Script

#!/bin/sh
date=`date`
echo "-------------------------------------------------"  >> /var/bin/checksvc.log   
echo "Restarting Server : $date" >> /var/bin/checksvc.log
echo "-------------------------------------------------"  >> /var/bin/checksvc.log

while [ 1 ] 
do
pidof Server.x86 >/dev/null
if [ $? -eq 0 ] ; then
echo ""
else
date=`date` 
echo "Restarting CCcam : $date" >> /var/bin/checksvc.log
/var/bin/Server.x86 &
  if [ $? -eq 0 ] ; then
    echo "ok!"
      else
        echo "hm, didn't work. Try doing it manually"
          fi 
          fi
          sleep 30
          done

What shell you are using for command line execution? probably its different from "/bin/sh".
and you are not getting the proper environment to run the command successfully.

try replacing this line :

/var/bin/Server.x86 &

with :

/var/bin/Server.x86  >> /var/bin/checksvc.log 2>&1 &

So that you can get some error msg (if any) in the log file.

also, check your working shell with echo $0 on the command line and run the script in that shell.

1 Like

Thanks, you are my man
echo $0 did show bash, sames as ps listed
Changing script to #!/bin/bash did solve my problem