8
8
# Authors: Kyle Fazzari <[email protected] >
9
9
# Daniel Swarbrick <[email protected] >
10
10
11
+ import argparse
11
12
import apt
12
13
import collections
13
14
import contextlib
@@ -74,14 +75,19 @@ def _write_autoremove_pending(registry, cache):
74
75
g .set (len (autoremovable_packages ))
75
76
76
77
77
- def _write_reboot_required (registry ):
78
+ def _write_reboot_required (registry , root_dir ):
78
79
g = Gauge ('node_reboot_required' , "Node reboot is required for software updates." ,
79
80
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') )))
81
82
82
83
83
84
def _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 )
85
91
86
92
# First of all, attempt to update the index. If we don't have permission
87
93
# to do so (or it fails for some reason), it's not the end of the world,
@@ -96,7 +102,7 @@ def _main():
96
102
_write_pending_upgrades (registry , cache )
97
103
_write_held_upgrades (registry , cache )
98
104
_write_autoremove_pending (registry , cache )
99
- _write_reboot_required (registry )
105
+ _write_reboot_required (registry , args . root_dir )
100
106
print (generate_latest (registry ).decode (), end = '' )
101
107
102
108
0 commit comments