{"record":{"id":"44eb4719f528060c","repo":"puppetlabs/puppet","slug":"systemd-restart-for-name-failed-journalctl-log","errorCode":null,"errorMessage":"Systemd restart for #{name} failed!\njournalctl log for #{name}:\n#{journalctl_output}","messagePattern":"Systemd restart for #(.+?) failed!\njournalctl log for #(.+?):\n#(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/service/systemd.rb","lineNumber":209,"sourceCode":"\n  def startcmd\n    unmask\n    [command(:systemctl), \"start\", '--', @resource[:name]]\n  end\n\n  def stopcmd\n    [command(:systemctl), \"stop\", '--', @resource[:name]]\n  end\n\n  def statuscmd\n    [command(:systemctl), \"is-active\", '--', @resource[:name]]\n  end\n\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\"","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/service/systemd.rb#L191-L227","documentation":"Raised by Puppet's systemd service provider when a service restart fails. The restart method first runs daemon-reload, then delegates to the base service provider which executes `systemctl restart <name>`; any Puppet::Error from that call is re-raised with the unit's last 50 journalctl lines from the past 5 minutes appended as diagnostic context. The underlying failure is the systemctl command; the journalctl text tells you why the unit itself failed.","triggerScenarios":"A `service { 'x': ensure => running }` or explicit restart where `systemctl restart x` exits non-zero: unit file has a syntax error after edit, ExecStart binary is missing or crashes on launch, the unit hits systemd's start-rate limit (StartLimitBurst), or the start exceeds the configured timeout. The journalctl command `journalctl -n 50 --since '5 minutes ago' -u <name> --no-pager` is executed via the provider's `execute` to build the message.","commonSituations":"Deploying a new application whose ExecStart path is wrong; a unit that fails its readiness check; restarting too soon after a previous failure so StartLimitInterval trips; a broken unit symlink in /etc/systemd/system after daemon-reload; slow-starting Java services exceeding the default timeout.","solutions":["Read the journalctl excerpt embedded in the error message — it names the application-level cause (missing binary, port in use, config error).","Run `systemctl status <name>` and `journalctl -xeu <name>` on the node for full logs, and `systemd-analyze verify /path/to/unit` to catch unit-file errors.","If the start limit was hit, run `systemctl reset-failed <name>` (or raise StartLimitIntervalSec/StartLimitBurstSec in the unit) and retry.","If the service legitimately needs longer to start, set a larger `timeout` on the Puppet service resource (provider supports configurable_timeout).","Fix the unit file or application, ensure `daemon-reload` runs (the provider does it, but verify), and re-run Puppet."],"exampleFix":"# before\nservice { 'myapp': ensure => running }\n# after - give the slow-starting unit time and correct ordering\nservice { 'myapp':\n  ensure    => running,\n  timeout   => 300,\n  subscribe => File['/etc/systemd/system/myapp.service'],\n}","handlingStrategy":"try-catch","validationCode":"# on the node, before the Puppet run\nsystemctl cat myapp.service >/dev/null 2>&1 || echo 'unit missing'\nsystemd-analyze verify /etc/systemd/system/myapp.service","typeGuard":null,"tryCatchPattern":"begin\n  # invoke provider restart (custom function / face / spec)\n  provider.restart\nrescue Puppet::Error => e\n  if e.message.start_with?('Systemd restart for')\n    logs = e.message[/journalctl log for .*:\\n(.*)\\z/m, 1].to_s\n    # surface unit-level cause instead of the generic failure\n    raise Puppet::Error, \"restart failed, unit logs: #{logs.lines.first(3).join}\"\n  end\n  raise\nend","preventionTips":["Always subscribe the service resource to the unit file (and package) so daemon-reload plus restart happen in the same run.","Set an explicit `timeout` on units that start slowly.","Validate edited unit files with `systemd-analyze verify` in CI before shipping them."],"tags":["systemd","service-management","puppet","journalctl"],"backgroundTag":"systemd-service-restart-failure","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}