Daemons and output in ruby

Backgrounding a process in ruby is easy, just add

Process.daemon

This works great but by doing so you will actually lose any output since daemon
will redirect stdout and stderr to /dev/null by default. Depending on how you
handle logging this might actually not be a great idea, I personally prefer
redirecting the output of a daemon process myself so I can add logging easily.

This is easily solve so by passing both parameters for daemon, first to either
do or don’t change the working dir to / and the second to not redirect stdout
and stderr.

Process.daemon true, true

Just a nice thing which is quickly overlooked.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.