[ANN] Process-Daemon, a gem for managing demonised and long running processes

Process::Daemon is a useful class to manage simple command line daemons
supporting the usual start, stop, restart, status commands and has a couple
of innovative features. It has been around for a long time (originally
called RExec) and even works correctly on RBX now.

This gem also provides cross-thread/cross-process notifications which are
useful for signalling various state changes and interrupts. For example,
there are many operations which don't work well in a trap context, so you
can use the notification system to pass notifications into the daemon code
without invoking functions directly from the trap context. This is very
common for a daemon code, e.g. Logger generally doesn't work in a trap
context, neither does Celluloid, etc. By default, the daemon controller
uses this to gracefully handle SIGINT, as long as your daemon code runs
asynchronously.

In addition, it includes very practical logging. If the daemon crashes,
when you go to restart it, it would print out the last exception backtrace
from the log file. This is useful to understand why the daemon crashed.

As process graphs like systemd take over, the usefulness of process-daemon
is probably being reduced, but it is still a very practical tool for
cross-platform daemon code, just a few lines of code gets you a working
background daemon/process with pretty decent semantics.

There is already a ton of documentation but some of it is a bit out of
date, so if anyone finds this tool useful, improved documentation would be
helpful :slight_smile:

You can probably steal the bit for inheriting sockets systemd-style

http://mid.gmane.org/20151030-inherit-fds-w-o-sd_listen_fds-in-pure@ruby

···

Samuel Williams <space.ship.traveller@gmail.com> wrote:

As process graphs like systemd take over, the usefulness of process-daemon
is probably being reduced,

from my post to ruby-talk a few months back:

That’s pretty awesome. Care to provide a PR?

···

On 4/01/2016, at 11:46 AM, Eric Wong <normalperson@yhbt.net> wrote:

Samuel Williams <space.ship.traveller@gmail.com> wrote:

As process graphs like systemd take over, the usefulness of process-daemon
is probably being reduced,

You can probably steal the bit for inheriting sockets systemd-style
from my post to ruby-talk a few months back:

http://mid.gmane.org/20151030-inherit-fds-w-o-sd_listen_fds-in-pure@ruby

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Sorry, I'm unlikely to actually use process-daemon myself and
don't have time to look at your codebase. It's only 3 lines
you need put somewhere.

...And by "PR", I assume you mean an emailed pull-request formatted
using the "git request-pull" command pointing to any
publically-accessible server on the Internet, right? :slight_smile:

No hope of me dealing with a centralized, Terms-of-Service-required,
non-Free messaging board.

···

Samuel Williams <space.ship.traveller@gmail.com> wrote:

That’s pretty awesome. Care to provide a PR?

It’s not just the few lines of code but the context in which it fits into Process::Daemon - I guess this would be part of a daemon #startup. This is the first time I’ve seen this style of daemon in the code (although I did know about it generally). I’ll have to read the man page and look at some existing daemons to see how it fits in and makes sense in Ruby.

Thanks :slight_smile:

···

On 4/01/2016, at 12:03 PM, Eric Wong <normalperson@yhbt.net> wrote:

Samuel Williams <space.ship.traveller@gmail.com> wrote:

That’s pretty awesome. Care to provide a PR?

Sorry, I'm unlikely to actually use process-daemon myself and
don't have time to look at your codebase. It's only 3 lines
you need put somewhere.

...And by "PR", I assume you mean an emailed pull-request formatted
using the "git request-pull" command pointing to any
publically-accessible server on the Internet, right? :slight_smile:

No hope of me dealing with a centralized, Terms-of-Service-required,
non-Free messaging board.

So what's the significance of this? Why should I use it?

···

Sent from my iPhone

On Jan 3, 2016, at 5:11 PM, Samuel Williams <space.ship.traveller@gmail.com> wrote:

It’s not just the few lines of code but the context in which it fits into Process::Daemon - I guess this would be part of a daemon #startup. This is the first time I’ve seen this style of daemon in the code (although I did know about it generally). I’ll have to read the man page and look at some existing daemons to see how it fits in and makes sense in Ruby.

Thanks :slight_smile:

On 4/01/2016, at 12:03 PM, Eric Wong <normalperson@yhbt.net> wrote:

Samuel Williams <space.ship.traveller@gmail.com> wrote:

That’s pretty awesome. Care to provide a PR?

Sorry, I'm unlikely to actually use process-daemon myself and
don't have time to look at your codebase. It's only 3 lines
you need put somewhere.

...And by "PR", I assume you mean an emailed pull-request formatted
using the "git request-pull" command pointing to any
publically-accessible server on the Internet, right? :slight_smile:

No hope of me dealing with a centralized, Terms-of-Service-required,
non-Free messaging board.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

It’s a simple modern library for making a program into a daemon on UNIX. It’s designed to be basically fool-proof.

It’s useful if you want to run something as a background or long running process, e.g. a backup script, a RubyDNS server, etc.

Kind regards,
Samuel

···

On 4/01/2016, at 3:28 PM, thomas Perkins <thomas.perkins23@icloud.com> wrote:

So what's the significance of this? Why should I use it?

Sent from my iPhone

On Jan 3, 2016, at 5:11 PM, Samuel Williams <space.ship.traveller@gmail.com> wrote:

It’s not just the few lines of code but the context in which it fits into Process::Daemon - I guess this would be part of a daemon #startup. This is the first time I’ve seen this style of daemon in the code (although I did know about it generally). I’ll have to read the man page and look at some existing daemons to see how it fits in and makes sense in Ruby.

Thanks :slight_smile:

On 4/01/2016, at 12:03 PM, Eric Wong <normalperson@yhbt.net> wrote:

Samuel Williams <space.ship.traveller@gmail.com> wrote:

That’s pretty awesome. Care to provide a PR?

Sorry, I'm unlikely to actually use process-daemon myself and
don't have time to look at your codebase. It's only 3 lines
you need put somewhere.

...And by "PR", I assume you mean an emailed pull-request formatted
using the "git request-pull" command pointing to any
publically-accessible server on the Internet, right? :slight_smile:

No hope of me dealing with a centralized, Terms-of-Service-required,
non-Free messaging board.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

What's the repo link?

···

Sent from my iPhone

On Jan 3, 2016, at 10:00 PM, Samuel Williams <space.ship.traveller@gmail.com> wrote:

It’s a simple modern library for making a program into a daemon on UNIX. It’s designed to be basically fool-proof.

It’s useful if you want to run something as a background or long running process, e.g. a backup script, a RubyDNS server, etc.

Kind regards,
Samuel

On 4/01/2016, at 3:28 PM, thomas Perkins <thomas.perkins23@icloud.com> wrote:

So what's the significance of this? Why should I use it?

Sent from my iPhone

On Jan 3, 2016, at 5:11 PM, Samuel Williams <space.ship.traveller@gmail.com> wrote:

It’s not just the few lines of code but the context in which it fits into Process::Daemon - I guess this would be part of a daemon #startup. This is the first time I’ve seen this style of daemon in the code (although I did know about it generally). I’ll have to read the man page and look at some existing daemons to see how it fits in and makes sense in Ruby.

Thanks :slight_smile:

On 4/01/2016, at 12:03 PM, Eric Wong <normalperson@yhbt.net> wrote:

Samuel Williams <space.ship.traveller@gmail.com> wrote:

That’s pretty awesome. Care to provide a PR?

Sorry, I'm unlikely to actually use process-daemon myself and
don't have time to look at your codebase. It's only 3 lines
you need put somewhere.

...And by "PR", I assume you mean an emailed pull-request formatted
using the "git request-pull" command pointing to any
publically-accessible server on the Internet, right? :slight_smile:

No hope of me dealing with a centralized, Terms-of-Service-required,
non-Free messaging board.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

GitHub: GitHub - ioquatix/process-daemon: Define a daemon using a Ruby class, provides common functionality like start, stop.
and on RubyGems: process-daemon | RubyGems.org | your community gem host

:slight_smile:

···

On 5 January 2016 at 05:18, thomas Perkins <thomas.perkins23@icloud.com> wrote:

What's the repo link?

Sent from my iPhone