Hey,
I'm struggling with this init script I've created.
The process runs fine, but I'm unable to get the PIDFILE to create, and I can't kill the process because of this.
Other than the issues with the PID/PIDFILE, the script works fine.
I even tried a
pid=`ps -A |grep java |cut -d" " -f1`
echo ${pid} > ${pidfile}
which works in bash, just not within the script
Code:
#!/bin/bash
#
# stock-management
#
# chkconfig: 2345 80 30
# description: stock-management
### BEGIN INIT INFO
# Provides: stock-management
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop stock-management
### END INIT INFO
# Author: Dave
# Source function library
. /etc/rc.d/init.d/functions
voyager_dir=${VOYAGER_DIR-/opt/voyager}
appname=${APPNAME-stock-management}
pidfile=${PIDFILE-/var/run/${appname}.pid}
lockfile=${LOCKFILE-/var/lock/subsys/${appname}}
RETVAL=0
start() {
echo -n $"Starting stock-management: "
daemon --user="voyager" --pidfile="${pidfile}" "${voyager_dir}/${appname}/bin/${appname} -Dconfig.file=${voyager_dir}/${appname}.conf > ${voyager_dir}/${appname}/${appname}-`date +%Y%m%d%H%M`.log "
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping stock-management: "
kill $(cat ${pidfile})
REVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL
Any help?
Thanks!