Hello,
I have created an init script for an application:
Code:
#!/bin/sh
#
# CServer.exe
#
# chkconfig: 345 85 15
# description:
### BEGIN INIT INFO
# Provides: elcorrectord
# Required-Start: $local_fs $network
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description:
# Description:
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
exec="/usr/share/ElCorrector/Cotig/CServer.exe"
path="/usr/share/ElCorrector/Cotig"
prog="elcorrectord"
# config="<path to major config file>"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/$prog
start() {
# [ -x $exec ] || exit 5
# [ -f $config ] || exit 6
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
cd $path
/usr/bin/mono $exec -def -cfg -sil &
retval=$?
[ $retval -eq 0 ] && echo_success || echo_failure
echo $! > /var/run/$prog.pid
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
kill -9 `cat /var/run/$prog.pid`
retval=$?
[ $retval -eq 0 ] && echo_success || echo_failure
rm -f /var/run/$prog.pid
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
I have also added this line to /etc/sudoers:
Code:
ALL ALL = NOPASSWD: /sbin/service elcorrectord *
Now, if I from the terminal type "sudo /sbin/service elcorrectord start" or "sudo /sbin/service elcorrectord stop", everthing works fine.
However, if instead install a desktop file in the menu:
Code:
[Desktop Entry]
Encoding=UTF-8
Name=Start server
Exec=/usr/bin/sudo /sbin/service elcorrectord start
Icon=ElCorrector
Terminal=true
Type=Application
Categories=Qt;
... and also for stopping the server, then I start getting problems. I can then stop the server, but when ever I try to start the server and then execute "sudo /sbin/service elcorrectord status", I get the message:
elcorrectord dead but pid file exists
Has anyone run across this type of problem before? What to me appears so strange is that it works fine from the terminal, but when I execute the commands from the menu, stopping the server works, but starting it doesn't...