Success with start-stop-daemon and mono-service2?

前端 未结 4 1016
情深已故
情深已故 2020-12-28 10:49

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

4条回答
  •  长发绾君心
    2020-12-28 11:28

    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
        }
    }
    

提交回复
热议问题