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

**URL:** <https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384>\
**Category:** ruby-talk\
**Created:** [3 January 2016 22:18 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384 "2016-01-03T22:18:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Williams](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Samuel\_Williams](https://rubytalk.org/u/Samuel_Williams)\
**Post date:** [3 January 2016 22:18 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/1 "2016-01-03T22:18:57Z")

</div>

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.

> **[ioquatix/process-daemon](https://github.com/ioquatix/process-daemon)**
>
> process-daemon - Define a daemon using a Ruby class, provides common functionality like start, stop.

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 🙂

---

<div class="post-metadata">

**Author:** ![Eric\_Wong2](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@Eric\_Wong2](https://rubytalk.org/u/Eric_Wong2)\
**Post date:** [3 January 2016 22:46 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/2 "2016-01-03T22:46:00Z")

</div>

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](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:

---

<div class="post-metadata">

**Author:** ![Samuel\_Williams](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Samuel\_Williams](https://rubytalk.org/u/Samuel_Williams)\
**Post date:** [3 January 2016 22:47 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/3 "2016-01-03T22:47:32Z")

</div>

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](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](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Eric\_Wong2](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@Eric\_Wong2](https://rubytalk.org/u/Eric_Wong2)\
**Post date:** [3 January 2016 23:03 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/4 "2016-01-03T23:03:57Z")

</div>

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? 🙂

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?

---

<div class="post-metadata">

**Author:** ![Samuel\_Williams](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Samuel\_Williams](https://rubytalk.org/u/Samuel_Williams)\
**Post date:** [3 January 2016 23:11 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/5 "2016-01-03T23:11:40Z")

</div>

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 🙂

> **···**
>
> > 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? 🙂
> > 
> > No hope of me dealing with a centralized, Terms-of-Service-required,  
> > non-Free messaging board.

---

<div class="post-metadata">

**Author:** ![thomas\_Perkins](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@thomas\_Perkins](https://rubytalk.org/u/thomas_Perkins)\
**Post date:** [4 January 2016 02:28 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/6 "2016-01-04T02:28:23Z")

</div>

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 🙂
> > 
> > > 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? 🙂
> > > 
> > > 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](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Samuel\_Williams](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Samuel\_Williams](https://rubytalk.org/u/Samuel_Williams)\
**Post date:** [4 January 2016 04:00 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/7 "2016-01-04T04:00:58Z")

</div>

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 🙂
> > > 
> > > > 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? 🙂
> > > > 
> > > > 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](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](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![thomas\_Perkins](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@thomas\_Perkins](https://rubytalk.org/u/thomas_Perkins)\
**Post date:** [4 January 2016 16:18 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/8 "2016-01-04T16:18:10Z")

</div>

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 🙂
> > > > 
> > > > > 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? 🙂
> > > > > 
> > > > > 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](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](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](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Samuel\_Williams](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Samuel\_Williams](https://rubytalk.org/u/Samuel_Williams)\
**Post date:** [13 January 2016 21:57 UTC](https://rubytalk.org/t/ann-process-daemon-a-gem-for-managing-demonised-and-long-running-processes/73384/9 "2016-01-13T21:57:00Z")

</div>

GitHub: [GitHub - ioquatix/process-daemon: Define a daemon using a Ruby class, provides common functionality like start, stop.](https://github.com/ioquatix/process-daemon)  
and on RubyGems: [process-daemon | RubyGems.org | your community gem host](https://rubygems.org/gems/process-daemon)

🙂

> **···**
>
> On 5 January 2016 at 05:18, thomas Perkins \<thomas.perkins23@icloud.com\> wrote:
> 
> > What's the repo link?
> > 
> > Sent from my iPhone
