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.
Old question is old, still: you can troubleshoot this kind of problem with a
set -x
(xtrace) at the top of your script. Also, considerset -e
, so the script errors out early.Why not just:
?
Edit:
Does dgate file has execution permission?
Try to echo the current directory (echo `pwd`) before launch dgate.
Regards, Lorenzo.
export CONQ_DIR The subshell doesn't know about the directory.
e.g.