1

I write a script to start/stop/restart a custom server application.

When starting the daemon server it should make the following:

#!/bin/sh -e
### BEGIN INIT INFO
...
...
### END INIT INFO

# Start service
pga_server_start()
{
        /opt/pga/server/server -d
}


# Stop  service
pga_server_stop()
{
        PID=`cat /var/lock/pga_server.lock`
        /bin/kill --signal SIGTERM $PID
}

pga_load_excalibur()
{
        is_loaded=`lsmod | grep excalbr`
        echo "Done"


        if [ -z "$is_loaded" ]; then
                /usr/local/bin/excload
                echo "Driver excalibur loaded."
        else
                echo "Driver excalibur already loaded."
        fi
}

case "$1" in
        start)
        pga_load_excalibur
        pga_server_start
        ;;
...
...

Initialy it worked fine. Then I've added the pga_load_excalibur function. Afterward, it does not work anymore. It never returns from the function pga_load_excalibur. It seems that the call to is_loaded=lsmod | grep excalbrnever returns as the subsequentecho` is never printed.

However, if I copy/paste this function in a separate shell script...it works.

But if I launch the starter script manually this way:

/etc/init.d/server start or service server start

it does not work. I'm using a Debian Wheezy 7.9 x64.

Although I'm not a schell script, it looks correct. I don't understand why it does not work when it's embedded into this service starter script.

Please note that I've also tried to replace the grep line with:

is_loaded=$(lsmod | grep excalbr)

But it does not work either. I'm running out of ideas :(

Z.

1 Answer 1

1

What do you get if you run the script in debug mode? try to run it with:

#!/bin/sh -xv

That may give some idea of why it's failing, post the output if you can't figure it out

Sign up to request clarification or add additional context in comments.

3 Comments

Good idea ! I didn't think about that. I'll try it tomorrow morning and let you know.
Well...I changed my code header with yours: #!/bin/sh -xv Everything works fine. So it seems that using #!bin/sh -e is not the good solution. -e means that the script immediately exits if a command failed. I still don't understand what's wrong with the command: is_loaded=lsmod | grep excalbr Finally, I removed the -xv and simply let #!/bin/sh in the header. I'm not 100% sastisfied but at least the script works.
Send the debug info from the -xv and I'll try to help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.