Has anyone had any success using start-stop-daemon and mono-service2 together? I\'ve been fighting this for a few days now and have gotten various bits to work, but have ha
We had a lot of issues with mono-service and ended up implementing our own "service" code in our app. Nothing hard, just grabbing some signals:
UnixSignal intr = new UnixSignal (Signum.SIGINT);
UnixSignal term = new UnixSignal (Signum.SIGTERM);
UnixSignal hup = new UnixSignal (Signum.SIGHUP);
UnixSignal usr2 = new UnixSignal (Signum.SIGUSR2);
UnixSignal[] signals = new UnixSignal[] { intr, term, hup, usr2 };
for (bool running = true; running; )
{
int idx = UnixSignal.WaitAny(signals);
if (idx < 0 || idx >= signals.Length) continue;
log.Debug("daemon: received signal " + signals[idx].Signum.ToString());
if ((intr.IsSet || term.IsSet))
{
intr.Reset ();
term.Reset ();
log.Debug("daemon: stopping...");
running = false;
}
else if (hup.IsSet)
{
// Ignore. Could be used to reload configuration.
hup.Reset();
}
else if (usr2.IsSet)
{
usr2.Reset();
// do something
}
}
I got this script working with a couple of minor changes:
A pidfile in /var/run only works if you run as root - if you try to run the script without sudo, mono-service will fail silently.
Use --pidfile instead of --name to find the service to stop.
do_stop()
{
test -f $PIDFILE && kill `cat $PIDFILE` && return 2
start-stop-daemon --stop --quiet --verbose --oknodo --retry=0/30/KILL/5\
--exec mono-service2
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
So it works, I think it just because you can't stop a process by the command "start-stop-daemon" i'm learning to use mono now,your invitation help me very much.thank you. my english is poor,forgive my half-baked english.
I know this question is old but there are no accepted answers. I tinkered around with this for awhile too and came up with a daemon script which worked like a charm for me. I blogged about it here: http://www.geekytidbits.com/start-stop-daemon-with-mono-service2/