2

I'm trying to set up an init script for a process on redhat linux:

#!/bin/sh
#
# Startup script for Conquest
#
# chkconfig: 345 85 15     - start or stop process definition within the boot process
# description: Conquest DICOM Server
# processname: conquest
# pidfile: /var/run/conquest.pid

# Source function library.      This creates the operating environment for the process to be started
. /etc/rc.d/init.d/functions

CONQ_DIR=/usr/local/conquest

case "$1" in
  start)
        echo -n "Starting Conquest DICOM server: "
        cd $CONQ_DIR && daemon --user mruser ./dgate -v                 - Starts only one process of a given name.
        echo
        touch /var/lock/subsys/conquest
        ;;
  stop)
        echo -n "Shutting down Conquest DICOM server: "
        killproc conquest
        echo
        rm -f /var/lock/subsys/conquest
        rm -f /var/run/conquest.pid      - Only if process generates this file
        ;;
  status)
        status conquest
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  reload)
        echo -n "Reloading process-name: "
        killproc conquest -HUP
        echo
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit 0

However, the cd $CONQ_DIR is getting ignored, because the script errors out:

# ./conquest start
Starting Conquest DICOM server: -bash: ./dgate: No such file or directory
                                                           [FAILED]

For some reason, I have to run dgate as ./dgate. I cannot specify the full path /usr/local/conquest/dgate

The software came with an init script for a Debian system, so the script uses start-stop-daemon, with the option --chdir to where dgate is, but I haven't found a way to do this with the Redhat daemon function.

churnd
  • 3,977
  • 5
  • 33
  • 41
  • Perhaps dgate is a script, and you can fix that so it can be run from the full path? – Kyle Brandt Apr 07 '10 at 12:06
  • No, it's a binary. – churnd Apr 07 '10 at 13:33
  • Have you been able to run the process without an init script, and then in another terminal verify the process is running with ps? I don't see confirmation of it working outside of the init in this discussion. – labradort Apr 07 '10 at 17:57
  • Yes, it does work if I run it manually. `ps -aux | grep dgate` shows a ./dgate process running. – churnd Apr 07 '10 at 18:06
  • Is it possible that it's running as "conquest", not "dgate"? I ask because the stop is doing `killproc conquest`. – Bill Weiss Apr 07 '10 at 20:45

4 Answers4

2

Old question is old, still: you can troubleshoot this kind of problem with a set -x (xtrace) at the top of your script. Also, consider set -e, so the script errors out early.

Tobu
  • 4,367
  • 1
  • 23
  • 31
1

Why not just:

daemon --user mruser ${CONQ_DIR}/dgate -v

?

Edit:

cd ${CONQ_DIR} && daemon --user mruser ./dgate -v &
Bill Weiss
  • 10,782
  • 3
  • 37
  • 65
  • This doesn't work. For some reason, I have to run dgate as ./dgate. I cannot specify the full path /usr/local/conquest/dgate – churnd Apr 07 '10 at 20:18
  • Can you add a "echo $CONQ_DIR" before the "cd $CONQ_DIR && daemon --user mruser ./dgate -v" line and let me know what it says? – Bill Weiss Apr 07 '10 at 20:43
  • It says `Starting Conquest DICOM server: /usr/local/conquest`. – churnd Apr 07 '10 at 21:52
  • Ok, so it's getting the path... Is there a "conquest" running? How about any processes running as "mruser" ? – Bill Weiss Apr 07 '10 at 22:16
  • No, nothing... the script halts after echoing /usr/local/conquest and just sits there. I have to ctrl+c to kill it. – churnd Apr 07 '10 at 22:54
  • See my updated comment. Try that. – Bill Weiss Apr 07 '10 at 23:10
  • Doing that gives: Starting Conquest DICOM server: /usr/local/conquest ./dgate: No such file or directory – churnd Apr 07 '10 at 23:17
  • 1
    adding the "&" to the end of your line makes it error with "No such file or directory" ? `cd $CONQ_DIR && daemon --user mruser ./dgate -v &` ? I hope the `${}` didn't give it problems. – Bill Weiss Apr 08 '10 at 17:17
0

Does dgate file has execution permission?

Try to echo the current directory (echo `pwd`) before launch dgate.

Regards, Lorenzo.

lg.
  • 4,579
  • 3
  • 20
  • 20
  • Yes, dgate is executable. I can run it manually. `echo pwd` shows the CD command is working, but `./dgate` just doesn't work. If I add `$CONQ_DIR/dgate`, then do `/etc/init.d/conquest start`, it says it starts OK, but `ps ax` shows no dgate process running. – churnd Apr 07 '10 at 13:43
  • Try to replace: cd $CONQ_DIR && daemon --user mruser ./dgate -v with: cd $CONQ_DIR && sudo -u mruser ./dgate -v – lg. Apr 07 '10 at 15:06
  • I did this... now for some reason the script stops responding at "Starting Conquest DICOM server:". I even tried to change it back to the previous "daemon" line, but it still halts. What would make an init script halt? – churnd Apr 07 '10 at 17:58
0

export CONQ_DIR The subshell doesn't know about the directory.

e.g.

$ FOO=skhfkjsdh
$ cat foo.sh

    echo $FOO

$ sh foo.sh

$ export FOO=skhfkjsdh
$ sh foo.sh
skhfkjsdh
$
labradort
  • 1,169
  • 1
  • 8
  • 20