Skip to content

Commit

Permalink
Manage error when running needrestart.
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMou committed Oct 18, 2024
1 parent ea4ea9b commit 62b5d2e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions needrestart_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,17 @@ def write_sessions(registry, needrestart_data):
def main():
registry = CollectorRegistry()

needrestart_output = subprocess.run(
["needrestart", "-b"], capture_output=True, text=True
).stdout
needrestart_data = NeedRestartData(needrestart_output)
try:
needrestart_output = subprocess.run(
["needrestart", "-b"], capture_output=True, text=True, check=True
).stdout
needrestart_data = NeedRestartData(needrestart_output)
except subprocess.CalledProcessError as e:
print(f"Error executing needrestart:\n{e}")
sys.exit(1)
except Exception as e:
print(f"An unexpected error occurred:\n{e}")
sys.exit(1)

write_timestamp(registry, needrestart_data)
write_kernel(registry, needrestart_data)
Expand Down

0 comments on commit 62b5d2e

Please sign in to comment.