Search code examples
linuxdaemonprocess-management12factor

Clarification needed about the eighth factor of the Twelve-Factor App manifesto and daemonized processes


I am in reference to the Twelve-Factor app "manifesto" which can be found here: http://12factor.net

In the eighth factor, the author writes:

Twelve-factor app processes should never daemonize or write PID files. Instead, rely on the operating system’s process manager (such as Upstart, a distributed process manager on a cloud platform, or a tool like Foreman in development) to manage output streams, respond to crashed processes, and handle user-initiated restarts and shutdowns.

I am not sure what is meant here by "processes should never daemonize".

Can someone please explain what the pros and cons of daemonizing a process would be - especially in the context of a java process? Also, can't a daemonized process be managed by a process manager?


Solution

  • If a process deamonizes, it means it is effectively trying to manage its lifecycle by itself. This is good for certain applications types, but for the distributed web application, and this is the kind of app the 12-factor manifesto pertains to, it will usually mean trouble. If an app tries to manage itself, it will probably not be easily managed by external process managers or in best case it may mean that custom plugins or extensions to these managers are needed, which complicates deployment.

    An example of what you would want to do to an app and what daemonization could prevent would be automatic scaling. With tools such as Mesos, you essentially want to tell the system: “here are my 50 machines, now put my apps on these machines”. You don't wan't to manually manage what goes where but let the cluster manager handle it automatically. It might set up more or fewer instances automatically depending on conditions, e.g. how much traffic your system is receiving, and it could put several instances on a single machine. If an app tries to manage itself, it will interfere and make such external management impossible or very complex.