[Haskell-cafe] How to daemonize a threaded Haskell program?
dave at natulte.net
Mon Mar 7 10:01:45 CET 2011
On Mon, Mar 7, 2011 at 12:39 AM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> Sterling, Gregory, Brandon and David thanks for your suggestions.
> On 6 March 2011 05:38, David Anderson <dave at natulte.net> wrote:
> > I humbly recommend doing such daemonizations from outside your program.
> > Programs that daemonize on startup make it very difficult to monitor them
> > direct means, instead forcing you to rely on PID files and other
> > which may not always be available or fresh.
> Agreed, I already noticed that debugging is a bit harder since I have
> no stdout and stderr anymore.
> > For reference, Upstart, the new PID 1 on Ubuntu and friends, has a
> > hack built in specifically to keep track of processes that "helpfully"
> > daemonize themselves, so that it can offer additional services like
> > restarting crashed services or notifying the owner of a problem.
> > As has been pointed out elsewhere on thread, there are plenty of
> > programs that implement daemonization if you end up not using service
> > management software to do it for you.
> I plan to run the daemon on a Ubuntu server. Do you know if Upstart is
> able to daemonize a process?
It's perfectly simple. In fact, it's the default assumption of Upstart that
your program doesn't daemonize, and that Upstart should help it. You have to
specify if your program violates that assumption.
Here's a sample file. It specifies a service that; should run whenever the
main runlevels are entered (i.e. basic system init like mounting filesystems
is done, but no other guarantee); stops when the system leaves those
runlevels; runs a binary that does not fork or daemonize; respawns the
service if the process should die for any reason; can be manually stopped
and restarted by the admin if he feels like it.
$ cat /etc/init/demo.conf
description "Demo service that doesn't daemonize by itself"
start on runlevel 
stop on runlevel [!2345]
$ sudo start demo
demo start/running, process 27469
$ sudo stop demo
$ sudo status demo
Hope this helps. The upstart configuration format is a little sparsely
documented, when I wrote scripts for it, I used the existing files in
/etc/init as a rough guide.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe