8 def __init__(self, name):
12 def configure(self, rec):
13 # install or remove the slice inistscript, as instructed by the initscript tag
14 new_initscript = rec['initscript']
15 if new_initscript == self.initscript:
17 logger.log("initscript.configure {}".format(self.name))
18 self.initscript = new_initscript
19 code = self.initscript
20 sliver_initscript = "/vservers/%s/etc/rc.d/init.d/vinit.slice" % self.name
21 if tools.replace_file_with_string(sliver_initscript, code, remove_if_empty=True, chmod=0755):
23 logger.log("Initscript: %s: Installed new initscript in %s" % (self.name, sliver_initscript))
25 # Only need to rerun the initscript if the vserver is
26 # already running. If the vserver isn't running, then the
27 # initscript will automatically be started by
28 # /etc/rc.d/vinit when the vserver is started.
29 self.rerun_slice_vinit()
31 logger.log("Initscript: %s: Removed obsolete initscript %s" % (self.name, sliver_initscript))
33 def install_and_enable_vinit(self):
34 "prepare sliver rootfs init and systemd so the vinit service kicks in"
35 # the fact that systemd attempts to run old-style services
36 # says we should do either one or the other and not both
37 # but actually if that was true we could just do it for init and be fine
38 # which is not what we've seen starting with f18
39 # so we try for a systemd system, and if it fails it means
40 # one of the dir does not exist and so we are dealing with an init-based rootfs
42 self.install_and_enable_vinit_for_systemd ()
44 self.install_and_enable_vinit_for_init ()
46 # unconditionnally install and enable the generic vinit script
47 # mimicking chkconfig for enabling the generic vinit script
48 # this is hardwired for runlevel 3
49 def install_and_enable_vinit_for_init(self):
51 suitable for init-based VMs
53 vinit_source = "/usr/share/NodeManager/sliver-initscripts/vinit"
54 vinit_script = "/vservers/%s/etc/rc.d/init.d/vinit" % self.name
55 enable_link = "/vservers/%s/etc/rc.d/rc3.d/S99vinit" % self.name
56 enable_target = "../init.d/vinit"
58 with open(vinit_source) as f:
60 if tools.replace_file_with_string(vinit_script, code, chmod=0755):
61 logger.log("Initscript: %s: installed generic vinit rc script" % self.name)
62 # create symlink for runlevel 3
63 if not os.path.islink(enable_link):
65 logger.log("Initscript: %s: creating runlevel3 symlink %s" % (self.name, enable_link))
66 os.symlink(enable_target, enable_link)
68 logger.log_exc("Initscript failed to create runlevel3 symlink %s" % enable_link, name=self.name)
70 # very similar but with systemd unit files - we target 'multi-user' in this context
71 def install_and_enable_vinit_for_systemd(self):
73 suitable for systemd-based VMs
77 ########## initscripts : current status - march 2015
80 # the initscripts business worked smoothly up to f18 inclusive
81 # with f20 and the apparition of machinectl, things started to
84 # so starting with f20, after having tried pretty hard to get this right,
85 # but to no success obviously, and in order to stay on the safe side
86 # of the force, I am turning off the initscript machinery completely
87 # that is to say: the vinit.service does not get installed at all
89 if os.path.isfile('/usr/bin/machinectl'):
90 logger.log("WARNING: initscripts are not supported anymore in nodes that have machinectl")
93 vinit_source = "/usr/share/NodeManager/sliver-systemd/vinit.service"
94 vinit_unit_file = "/vservers/%s/usr/lib/systemd/system/vinit.service" % self.name
95 enable_link = "/vservers/%s/etc/systemd/system/multi-user.target.wants/vinit.service" % self.name
96 enable_target = "/usr/lib/systemd/system/vinit.service"
98 with open(vinit_source) as f:
100 if tools.replace_file_with_string(vinit_unit_file, code, chmod=0755):
101 logger.log("Initscript: %s: installed vinit.service unit file" % self.name)
102 # create symlink for enabling this unit
103 if not os.path.islink(enable_link):
105 logger.log("Initscript: %s: creating enabling symlink %s" % (self.name, enable_link))
106 os.symlink(enable_target, enable_link)
108 logger.log_exc("Initscript failed to create enabling symlink %s" % enable_link, name=name)