How to encode Mono Daemon

I am trying to write a Mono C # daemon for Linux.

I would like to start and stop it when I finished processing, and not just kill the process.

Does anyone have any examples of this?

Edit: I figured out how to use start-stop-daemon - background in debian, so I think I'm just using it now.

Edit: I implement this in java too, and they have this nice addShutdownHook that catches application termination. I need to spend a little more time sorting dependencies for monoservice or find a way to catch the end of the application.

There is a SessionEnd event, but this is available only for services, not console applications.

Answer: using monoservice to port a Windows service to Linux

+52
c # linux mono daemon mono-service
Oct 09 '08 at 9:12
source share
7 answers

You must implement the service and use the mono service. Google and you will find some examples.

+20
Oct 11 '08 at 11:18
source share

To receive Unix notifications using signals, you want to use Mono.Unix.UnixSignal for each signal you plan to receive, and then call UnixSignal.WaitAny () in the signal array.




Usually you do this in a separate thread.

+25
Oct 19 '08 at 16:30
source share

A simple method would be to listen on the (local, high) port and receive commands from a management client, such as bind.

A more unix-ish path will be to register the signal handler using UnixSignal and exit correctly when a specific signal is received. See the Mono FAQ, β€œCan I use signal handlers with Mono?” for reservations and example.

lupus found mono-service , which is hosting using ServiceProcess interfaces. Unfortunately, this requires setting MONO_DISABLE_SHM , which disables some functions in Mono, in particular, IPC cross-process systems.

+16
Oct 09 '08 at 14:28
source share

A Linux daemon usually listens for signals, such as a kill signal, but there are others that allow it to do things like soft restart (read in configuration), etc.

This is usually followed by a script in the /etc/init.d directory, which controls the start and stop of such daemons. Usually a pid file is created in / var / run, which saves the process ID for the script to quickly identify the process.

Even when coding for Mono, you have a good understanding of the environment for which you are coding, since there is no difference between a Mono process or its own process (e.g., created in C) or a script.

Dave

+4
09 Oct '08 at 14:41
source share

Miguel de Icaza recently wrote about the new Mono C # interactive shell , which you should be able to demonize quite easily. Miguel has a follow-up article with some source code that shows how you can incorporate an interactive shell into other C # applications. This can be a good starting point for your demon.

Please note that the interactive shell requires Mono version 2.2, which has not yet been released. However, the code is available in the Mono svn repository .

0
Oct 10 '08 at 2:59
source share

David is right, termination is done through a UNIX signal, and you must use a signal handler to catch it.

0
Oct 10 '08 at 3:27
source share

As an alternative, I use a shell script. It launches my mono application, and then, when my application closes (intentionally or unintentionally), it looks at any return signals that my application has installed. This can be used to tell the script to copy in an update, reboot, or shutdown. If my application crashes, the signal will not be returned, so the script will restart my application and send me an email with the last lines of the console output.

See Windows, how is LINUX developing services using MONO?

0
Jun 20 '10 at 12:24
source share



All Articles