[PUP-5604] Add journalctl command when service fails for systemd Created: 2015/12/12  Updated: 2019/03/28  Resolved: 2016/06/30

Status: Closed
Project: Puppet
Component/s: None
Affects Version/s: None
Fix Version/s: PUP 4.6.0

Type: Improvement Priority: Normal
Reporter: Peter Souter Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: puppethack, systemd
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by PUP-5686 Add the output of failed "systemctl s... Closed
Template:
Epic Link: Service Phase 1 Type/Provider Improvements
Story Points: 0
Sprint: Client 2016-06-29, Client 2016-07-13 (HA, 1.5.3)
Release Notes: New Feature
Release Notes Summary: the systemd service provider now asks journalctl why something failed and reports it back to the user for aid in debugging.

 Description   

It's not super easy to diagnose issues when services fail to start with systemd:

Error: Could not start Service[corosync]: Execution of '/usr/bin/systemctl start corosync' returned 1: Job for corosync.service failed. See 'systemctl status corosync.service' and 'journalctl -xn' for details.

Would be nice to add some logic to actually run the journalctl for the service if it fails so we can get full details of the logs.



 Comments   
Comment by Tim Meusel [ 2015/12/12 ]

+1 for this. Would be great if Puppet could run "systemctl -u $servicewebroke --full". "-n linenumberthatwelike" would also be good so we don't blow up the output.

Comment by Ranjit Viswakumar [ 2016/06/14 ]

Work around in the meantime.

service { 'foo':
 ensure => running,
 start  => '/usr/bin/systemctl start foo || (journalctl -xn; exit 1)',
}

Comment by Eric Thompson [ 2016/06/30 ]

validated against puppet agent master sha: 2e1f658732ca423ee43860cb3a7ce7b2c549938e
on rhel7
with

[root@sp87at98x02dtjk ~]# puppet apply journalctl.pp
Notice: Compiled catalog for sp87at98x02dtjk.delivery.puppetlabs.net in environment production in 0.17 seconds
Error: Execution of 'journalctl -n 50 --since '5 minutes ago' -u foo --no-pager' returned 1: -- Logs begin at Thu 2016-06-30 09:41:12 PDT, end at Thu 2016-06-30 12:13:11 PDT. --
Error: /Stage[main]/Main/Service[foo]/ensure: change from stopped to running failed: Execution of 'journalctl -n 50 --since '5 minutes ago' -u foo --no-pager' returned 1: -- Logs begin at Thu 2016-06-30 09:41:12 PDT, end at Thu 2016-06-30 12:13:11 PDT. --
Notice: Applied catalog in 0.05 seconds
[root@sp87at98x02dtjk ~]# cat journalctl.pp
service { 'foo':
 ensure => running,
 start  => '/usr/bin/systemctl start foo'
}

Generated at Mon Oct 21 09:18:50 PDT 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.