88# Authors: Kyle Fazzari <kyrofa@ubuntu.com>
99# Daniel Swarbrick <dswarbrick@debian.org>
1010
11+ import argparse
1112import apt
1213import collections
1314import contextlib
@@ -74,14 +75,19 @@ def _write_autoremove_pending(registry, cache):
7475 g .set (len (autoremovable_packages ))
7576
7677
77- def _write_reboot_required (registry ):
78+ def _write_reboot_required (registry , root_dir ):
7879 g = Gauge ('node_reboot_required' , "Node reboot is required for software updates." ,
7980 registry = registry )
80- g .set (int (os .path .isfile ('/ run/reboot-required' )))
81+ g .set (int (os .path .isfile (os . path . join ( root_dir , ' run/reboot-required') )))
8182
8283
8384def _main ():
84- cache = apt .cache .Cache ()
85+ parser = argparse .ArgumentParser ()
86+ parser .add_argument ('-r' , '--root-dir' , dest = 'root_dir' , type = str , default = '/' ,
87+ help = "Set root directory to a different path than /" )
88+ args = parser .parse_args ()
89+
90+ cache = apt .cache .Cache (rootdir = args .root_dir )
8591
8692 # First of all, attempt to update the index. If we don't have permission
8793 # to do so (or it fails for some reason), it's not the end of the world,
@@ -96,7 +102,7 @@ def _main():
96102 _write_pending_upgrades (registry , cache )
97103 _write_held_upgrades (registry , cache )
98104 _write_autoremove_pending (registry , cache )
99- _write_reboot_required (registry )
105+ _write_reboot_required (registry , args . root_dir )
100106 print (generate_latest (registry ).decode (), end = '' )
101107
102108
0 commit comments