This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Restart cygrunsrv service on failure


Glen Burson wrote:
[snip]
> I'm having real trouble getting my service to restart on failure, using the
> Windows service "Recovery" options. I have set: -
> 
> First Failure "Restart the Service"
[snip]
> Windows logs in the Event Viewer that the service terminated (gracefully,
> error code 0) but doesn't restart it.
> 
> I have tried exiting from the script using a non-zero code (I've tried lots
> of different ones) but although the non-zero exit code is logged in the
> Event Viewer, it still doesn't restart it.
> 
> I've also tried the install option "-n" which tells Windows that the service
> should never terminate but, although I now get an error in the Event Viewer,
> it still doesn't restart it!
> 
> The ONLY way I've managed to get Windows to restart the service is to kill
> the cygrunsrv process before the child script terminates. Killing the child
> script does not work either.
> 
> It seems to be related to how the process terminates but I seem to crack it!
> 
> Thanks in advance for any suggestions. I've seen some postings that imply
> that people have this working but no examples.

I never tried exactly what you want, it looks like Windows doesn't cooperate so
its good to know not to waste time trying that.

One way I have a server set up is by installing a script (that watches the real
server) as the service, the interesing part of the script is this:

# Keep checking that it is working every TIME secs
trap '$DAEMON stop; exit' SIGTERM SIGQUIT SIGKILL
while true; do
  sleep $TIME
  $CLAMDWATCH -q -s $SOCKET &&
  ( $DAEMON stop
    sleep 1
    rm -f $SOCKET
    $DAEMON start
  )
done

I know this is not what you asked, here I have a program that tests to see if
the daemon is not responding and the script restarts the daemon in that case.

Back to your test, I think you are using the wrong exit codes.  Windows does not
use the Unix like codes 0, 1, etc.   I don't remember Windows codes but they
where something like (exit_code << 8 | windows_flags) that means 256 instead of 1.

HTH
-- 
René Berber


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]