EvanKrall / puppet-initscript

Defined type for creating init scripts for a command
Apache License 2.0
6 stars 5 forks source link

Handle both daemonizing and foreground programs #8

Open EvanKrall opened 8 years ago

EvanKrall commented 8 years ago

Some programs can daemonize themselves, some can't. This often makes a difference in how your init script should look. For example:

One thought is to provide a flag daemonizing or forking or something, indicating whether / how many times the daemon forks; then the init script templates could write out appropriate configs.

Another thought is to provide two command arguments: foreground_command and daemon_command. Since many programs are capable of daemonizing themselves or remaining in the foreground with a command line flag, it may be better to let the templates for each init style pick the command that is most appropriate. (i.e. foreground_command for upstart or systemd, daemon_command for sysv_*. I think this would require very similar complexity to the previous option (it'd probably be one if/else either way) but would let us create more idiomatic init scripts.

hashbrowncipher commented 8 years ago

I vote we do "One thought..."

I think also that this module is the right place to provide the requisite "special attention" for SysV init styles that need forking.

EvanKrall commented 8 years ago

I think both options will be pretty similar:

<% if @forking %>
<%= @command.shelljoin %>
<% else %>
<%= @command.shelljoin %> &
<% endif %>

Versus

<% if @background_command %>
<%= @background_command.shelljoin %>
<% else %>
<%= @foreground_command.shelljoin %> &
<% endif %>
solarkennedy commented 8 years ago

I vote that this thing only support foreground commands and when the module knows it needs to fork (for sysvinit), it forks.

Supporting daemon or forking in sysv is going to make it very dificult to track pids outside of our control, which is going to make status not work.

At the very least, YAGNI until there is actually a program that you find that needs this module and has no way to run in the foreground? (haproxy?)

EvanKrall commented 8 years ago

Most things know how to run in the foreground, I agree, but some don't know how to background.

For the programs that do know how to daemonize, we'll be able to produce more idiomatic init scripts. (If the program knows how to daemonize, why would you tell it to run in the foreground and then background it from the script?)