Exec type and backgrounded processes

566 views
Skip to first unread message

Thomas Müller

unread,
May 22, 2018, 2:38:08 AM5/22/18
to Puppet Users
Hi

If I define:

exec { '/bin/sleep 300 &':
  timeout => 10,
}

and run it with puppet apply: it happily starts the sleep, backgrounds it and finishes - leaving the sleep in the background alive.

Is this behaviour as expected? I personally expected that puppet would ensure all started processes are killed if once the exec resource finishes.

- Thomas

David Schmitt

unread,
May 22, 2018, 4:56:51 AM5/22/18
to puppet...@googlegroups.com
That is not surprising to me. To provide maximal flexibility, puppet does not do any management or cleanup of processes started. As an exercise, try to define a parameter to exec that specifies how puppet should cleanup processes after exec: as soon as the exec returns? when the agent run ends? everything in the control group, or just non-detached processes?

Better to use a proper/any process manager (systemd, init, runit, upstart) that was purpose built to solve those problems.

Cheers, David

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/61aff915-21a1-4945-b346-dbfbcb699391%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

jcbollinger

unread,
May 22, 2018, 10:37:37 AM5/22/18
to Puppet Users


On Tuesday, May 22, 2018 at 1:38:08 AM UTC-5, Thomas Müller wrote:
Hi

If I define:

exec { '/bin/sleep 300 &':
  timeout => 10,
}

and run it with puppet apply: it happily starts the sleep, backgrounds it and finishes - leaving the sleep in the background alive.

Is this behaviour as expected?


It's what I would have expected, at any rate.

 
I personally expected that puppet would ensure all started processes are killed if once the exec resource finishes.


I'm not sure why someone would expect that.  The documentation of the Exec resource type does not describe any such behavior, and it seems pretty arbitrary considering how generic Exec resources are.  Why shouldn't one be able to use an Exec to launch a background process?  Why should Puppet forcibly prevent such a background process from outliving the application of the Exec that starts it, or even the whole catalog run?  What if that was the whole point of the Exec in the first place?

Perhaps it's a matter of interpretation.  If the command of an Exec expresses starting a process in the background, then its job is successfully completed when the background job is started.  If you want an Exec to run a command to completion, then have it run that command in the foreground (the usual case).  Through no coincidence at all, this mirrors the behavior of background jobs launched by a non-interactive shell.


John

Thomas Müller

unread,
May 23, 2018, 2:24:14 AM5/23/18
to Puppet Users


Am Dienstag, 22. Mai 2018 16:37:37 UTC+2 schrieb jcbollinger:


On Tuesday, May 22, 2018 at 1:38:08 AM UTC-5, Thomas Müller wrote:
Hi

If I define:

exec { '/bin/sleep 300 &':
  timeout => 10,
}

and run it with puppet apply: it happily starts the sleep, backgrounds it and finishes - leaving the sleep in the background alive.

Is this behaviour as expected?


It's what I would have expected, at any rate.

 
I personally expected that puppet would ensure all started processes are killed if once the exec resource finishes.


I'm not sure why someone would expect that. 

the puppet-agent service runs for longer time in the background. Processes could leak unintended .  It's not only about procesces backgrounded by the Exec directly but also about subprocesses started by the exec command. Like:

exec { '/bin/bash -c "sleep 300 &"': timeout => 10, }


if this is the expected behaviour then all is fine. I just was suprised one can start "daemon" processes with puppet exec.

I was already thinking about using systemd oneshot+time units to run puppet instead of the service because of the SELinux fcontext issue with the service . Another plus would be that systemd could ensure leftover processes started in the background will be treated.



- Thomas

warron.french

unread,
May 23, 2018, 8:54:47 AM5/23/18
to puppet...@googlegroups.com
Use an attribute of the Exec resource, such as onlyif to restrict it's execution if that's what you are trying to do.

\\Warron French from mobile

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

Thomas Müller

unread,
May 23, 2018, 9:25:30 AM5/23/18
to Puppet Users


Am Mittwoch, 23. Mai 2018 14:54:47 UTC+2 schrieb Warron French:
Use an attribute of the Exec resource, such as onlyif to restrict it's execution if that's what you are trying to do.

I'm not trying to use backgrounded processes with puppet at all. I'll actually think that starting processes in the background with puppet exec an anti-pattern. If something should be run in the background, then it's a thing for Systemd or whatever your init system uses.

- Thomas
Reply all
Reply to author
Forward
0 new messages