Marcos Oliveira
Marcos Oliveira

Reputation: 1697

How to capture `systemctl status` and `journalctl -xe` from a kitchen run inside a Jenkins job

I have a Jenkins job running kitchen converge that is giving the following error:

---- Begin output of /bin/systemctl restart docker ----
STDOUT: 
STDERR: Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
---- End output of /bin/systemctl restart docker ----

I'm looking for a way to capture the output of both commands above so I can diagnose what's wrong with the cookbook in that environment.

Running kitchen converge locally gives no error and I don't have access to the Jenkins node where this job is running.

I could get output adding the following code:

require 'mixlib/shellout'


Chef.event_handler do
  on :run_failed do                              
    systemctl = Mixlib::ShellOut.new("/bin/systemctl status docker.service")
    systemctl.run_command                                                            
    Chef::Log.info "Recipe failed miserably"
    Chef::Log.info systemctl.stdout
    Chef::Log.info systemctl.stderr
    journalctl = Mixlib::ShellOut.new("/bin/journalctl -xe")                           
    journalctl.run_command
    Chef::Log.info journalctl.stdout                      
    Chef::Log.info journalctl.stderr                                                   
  end                                            
end           

Which doesn't seem to be optimal.

Upvotes: 0

Views: 917

Answers (1)

Mr.
Mr.

Reputation: 10102

you didn't specify which chef resource executes the commands above, but generally speaking - execute chef-client with debug log level:

$ chef-client --log_level debug

you can achieve it by setting the log level in kitchen provisioner

---
provisioner:
  name: chef_zero
  log_level: :debug

Upvotes: 1

Related Questions