rackerlabs / kthresher

Tool to remove unused kernels in Debian/Ubuntu
Apache License 2.0
17 stars 12 forks source link

Add systemd timer support #57

Closed komish closed 6 years ago

komish commented 6 years ago

Provides Systemd Timer and associated service file for optional use.

Fixes #48

Considerations

komish commented 6 years ago

@tonyskapunk

The issue is that the default config does not specify an action to take from what I see, so the service reports as failed because the command with no arguments/config returns a non-zero exit code

# systemctl status kthresher.service
● kthresher.service - Purge unused kernels
   Loaded: loaded (/etc/systemd/system/kthresher.service; static; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2018-10-07 23:58:01 UTC; 25s ago
     Docs: man:kthresher(8)
  Process: 4759 ExecStart=/usr/local/bin/kthresher (code=exited, status=1/FAILURE)
 Main PID: 4759 (code=exited, status=1/FAILURE)

Oct 07 23:58:01 ubuntu systemd[1]: kthresher.service: Main process exited, code=exited, status=1/FAILURE
Oct 07 23:58:01 ubuntu systemd[1]: kthresher.service: Failed with result 'exit-code'.
Oct 07 23:58:01 ubuntu systemd[1]: Failed to start Purge unused kernels.
# kthresher &>/dev/null; echo $?
1

If that's fine, I'll remove the --dry-run. Alternatives might include leaving --dry-run, or specifying the ExecStart line have a - before the executable here. This causes systemd to ignore the non-zero and report success (or in this case, inactivity). I'm not sure that's a better path - when we get non-zero, I would imagine we want this to report failure.

ExecStart=-/usr/local/bin/kthresher
# systemctl status kthresher.service
● kthresher.service - Purge unused kernels
   Loaded: loaded (/etc/systemd/system/kthresher.service; static; vendor preset: enabled)
   Active: inactive (dead) since Mon 2018-10-08 00:00:00 UTC; 8s ago
     Docs: man:kthresher(8)
  Process: 4874 ExecStart=/usr/local/bin/kthresher (code=exited, status=1/FAILURE)
 Main PID: 4874 (code=exited, status=1/FAILURE)

Let me know which you would prefer.

komish commented 6 years ago

The config I'm seeing as "default" for reference


[main]
include = /etc/kthresher.d/*.conf

# Is recommended to put the configuration in the included directory instead
# of making changes in here.
#
# The options are:
#   headers - [ yes | on | true | no | off | false ] Include or not the headers.
#   include - [ /path/to/file ] Suports globbing, e.g. /path/to/dir/*.conf
#   keep - Number of kernel images to keep (0-9), default is 1 if none defined
#   purge - [ yes | on | true | no | off | false ] Commit changes
#   verbose - [ yes | on | true | no | off | false ] Be verbose
#
# NOTES:
# 1) The --dry-run option is only allowed through CLI, if purge is defined
#    in the config file and --dru-run is used, the latter has precedence.
# 2) IF defined, only the non-boolean options can be overriden from CLI.```

There is nothing in the related `kthresher.d` out of the box.
tonyskapunk commented 6 years ago

For now let's remove the --dry-run I'll make the changes to avoid a failure. Thanks @Komish

komish commented 6 years ago

@tonyskapunk Done - I've removed the comment and the --dry-run flag. Should be set to go. Let me know if there is anything further!

tonyskapunk commented 6 years ago

Thaaaanks!, there will be stickers! :+1: