Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a Ruby program a daemon?

Tags:

ruby

daemon

I want to write a Ruby program that will always be running in the background (a daemon) on my Mac.

Can someone point me in the right direction on how this would be done?

like image 580
ab217 Avatar asked Sep 10 '10 21:09

ab217


People also ask

What is daemon in rails?

Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server) to be run as a daemon and to be controlled by simple start/stop/restart commands. You can also call blocks as daemons and control them from the parent or just daemonize the current process.

What is a daemon in linux?

A daemon is a long-running background process that answers requests for services. The term originated with Unix, but most operating systems use daemons in some form or another. In Unix, the names of daemons conventionally end in "d". Some examples include inetd , httpd , nfsd , sshd , named , and lpd .

How is daemon process created?

In a Unix environment, the parent process of a daemon is often, but not always, the init process. A daemon is usually created either by a process forking a child process and then immediately exiting, thus causing init to adopt the child process, or by the init process directly launching the daemon.


1 Answers

Ruby 1.9.x has now the following:

Process.daemon 

Put it in your code and that's it.

Taken from "Daemon Processes in Ruby."

like image 122
Hertzel Guinness Avatar answered Sep 29 '22 18:09

Hertzel Guinness