{"record":{"id":"bf459aceae265376","repo":"puppetlabs/puppet","slug":"systemd-stop-for-name-failed-journalctl-log-fo","errorCode":null,"errorMessage":"Systemd stop for #{name} failed!\njournalctl log for #{name}:\n#{journalctl_output}","messagePattern":"Systemd stop for #(.+?) failed!\njournalctl log for #(.+?):\n#(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/service/systemd.rb","lineNumber":222,"sourceCode":"\n  def restart\n    daemon_reload?\n    super\n  rescue Puppet::Error => e\n    raise Puppet::Error, prepare_error_message(@resource[:name], 'restart', e)\n  end\n\n  def start\n    daemon_reload?\n    super\n  rescue Puppet::Error => e\n    raise Puppet::Error, prepare_error_message(@resource[:name], 'start', e)\n  end\n\n  def stop\n    super\n  rescue Puppet::Error => e\n    raise Puppet::Error, prepare_error_message(@resource[:name], 'stop', e)\n  end\n\n  def prepare_error_message(name, action, exception)\n    error_return = \"Systemd #{action} for #{name} failed!\\n\"\n    journalctl_command = \"journalctl -n 50 --since '5 minutes ago' -u #{name} --no-pager\"\n    Puppet.debug(\"Running journalctl command to get logs for systemd #{action} failure: #{journalctl_command}\")\n    journalctl_output = execute(journalctl_command)\n    error_return << \"journalctl log for #{name}:\\n#{journalctl_output}\"\n  end\nend\n","sourceCodeStart":204,"sourceCodeEnd":233,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/service/systemd.rb#L204-L233","documentation":"Raised by Puppet's systemd service provider when stopping a service fails. The `stop` method delegates to the base provider which executes `systemctl stop <name>`; a Puppet::Error from that call is re-raised with the last 50 journalctl lines for the unit. Typically the unit fails to stop within its TimeoutStopSec, or systemd cannot cleanly kill the process group.","triggerScenarios":"`ensure => stopped` sync or explicit stop where `systemctl stop <name>` times out or errors: main process ignores SIGTERM and TimeoutStopSec expires, KillMode=none leaves children behind, the unit is in a D-state process, or systemd's DBus connection is broken.","commonSituations":"Legacy daemons that do not handle SIGTERM; containers with KillMode misconfigured; a hung process blocking shutdown; stop attempted while systemd itself is degenerate (e.g., after OOM events).","solutions":["Check the journalctl excerpt in the message and `systemctl status <name>` to see whether the process ignored the term signal or timed out.","Raise `TimeoutStopSec` in the unit file (or set a larger Puppet `timeout` on the resource) so slow shutdowns can complete.","Fix the unit's `KillMode`/`KillSignal` so systemd can actually terminate the process (default KillMode=control-group is usually correct).","Manually verify with `systemctl stop <name>` on the node; use `systemctl kill <name>` to force if the process is stuck.","Ensure the daemon's PID file / Type=forking settings match reality so systemd tracks the right main PID."],"exampleFix":"# before\nservice { 'myapp': ensure => stopped }\n# after - allow more time for graceful shutdown\nservice { 'myapp':\n  ensure  => stopped,\n  timeout => 300,\n}","handlingStrategy":"retry","validationCode":"systemctl is-active myapp  # confirm current state before ensure => stopped sync\nsc_out = Puppet::Util::Execution.execute(['systemctl', 'show', 'myapp', '-p', 'TimeoutStopUSec'], failonfail: false)","typeGuard":null,"tryCatchPattern":"attempts = 0\nbegin\n  attempts += 1\n  provider.stop\nrescue Puppet::Error => e\n  raise unless e.message.start_with?('Systemd stop for') && attempts < 3\n  Puppet.info \"stop timed out, forcing (attempt #{attempts})\"\n  Puppet::Util::Execution.execute(['systemctl', 'kill', 'myapp'])\n  retry\nend","preventionTips":["Tune TimeoutStopSec in the unit for slow-shutdown daemons.","Make daemons handle SIGTERM so systemd never has to SIGKILL.","Give the service resource an explicit `timeout` matching your stop budget."],"tags":["systemd","service-management","puppet","journalctl"],"backgroundTag":"systemd-service-stop-failure","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}