Daemonize v0.1 - simple way to create cross-platform daemons

Philippe Sigaud via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sun Aug 31 12:45:23 PDT 2014


>> Does the user sees/uses this name in any way afterwards? Because I
>> think you could also produce a unique string at compile-time (by using
>> __FILE__ and __LINE__, unless someone has a better idea), if the user
>> does not provide one. Maybe he just wants an anonymous daemon, or
>> doesn't care, whatever.
>
> Yes, the name is used in windows service manager (you can start/stop the
> daemon by control panel) and for default locations of .pid and .lock files.

OK.

> Auto generated name will prevent sending signals and could be ugly displayed
> in service manager. The feature is useful for simple daemons, I will play
> around with that idea to find out if it worth.

Great.


> I will add the approach in next release (it requires some more additional
> templates to wrap all the mess) thanks to arguments "grammar" has no
> ambiguities.

Yes, the grammar is simple, use it to simplify the life of your users.

>> Is the idea that, if the delegate has two arguments, then the second
>> is the signal that will be passed to it, and if it has only one
>> argument, only the logger will be passed?
>
> Yes

OK.
IIRC, I read in your code that composed signals means the next
delegate must have the (logger, signal) {...} form.
Why?


>> What if the user does not want a logger? Is a daemon always associated
>> to a log file in OSes?
>
> It is a general rule as the stderr and stdout files are closed. At next
> version I want to use duck typing for logger (or sink approach same as
> toString uses) and add a feature to reopen stderr/stdout to another file.

OK.


>> Concerning the DaemonClient template, could you not ask for Daemon to
>> generate it on demand? Or is DaemonClient always used in another
>> module?
>
> DaemonClient is designed to be used in another module, you can send signals
> with full Daemon template.

OK. I'd have thought that just having the name of the daemon would be
enough to send it signals.

>> What happens when an unhandled signal is passed to a daemon?
>
> The event is logged down and ignored.

Is that the standard behavior for daemons in OSes?
You could have the daemon stopped, after logging the unhandled signal.
Or you could also block compilation if a daemon does not handle all signals...
Or have a 'catch-all' delegate, as std.concurrency.receive, which uses
a (Variant v) {...} delegate at the end.
See:
http://dlang.org/library/std/concurrency/receive.html

(btw, signals could also be types and you could have a handling syntax
similar to receive).


More information about the Digitalmars-d-announce mailing list