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))
32 def install_and_enable_vinit(self):
33 "prepare sliver rootfs init and systemd so the vinit service kicks in"
34 # the fact that systemd attempts to run old-style services
35 # says we should do either one or the other and not both
36 # but actually if that was true we could just do it for init and be fine
37 # which is not what we've seen starting with f18
38 # so we try for a systemd system, and if it fails it means
39 # one of the dir does not exist and so we are dealing with an init-based rootfs
41 self.install_and_enable_vinit_for_systemd ()
43 self.install_and_enable_vinit_for_init ()
45 # unconditionnally install and enable the generic vinit script
46 # mimicking chkconfig for enabling the generic vinit script
47 # this is hardwired for runlevel 3
48 def install_and_enable_vinit_for_init(self):
50 suitable for init-based VMs
52 vinit_source = "/usr/share/NodeManager/sliver-initscripts/vinit"
53 vinit_script = "/vservers/%s/etc/rc.d/init.d/vinit" % self.name
54 enable_link = "/vservers/%s/etc/rc.d/rc3.d/S99vinit" % self.name
55 enable_target = "../init.d/vinit"
57 code = file(vinit_source).read()
58 if tools.replace_file_with_string(vinit_script, code, chmod=0755):
59 logger.log("Initscript: %s: installed generic vinit rc script" % self.name)
60 # create symlink for runlevel 3
61 if not os.path.islink(enable_link):
63 logger.log("Initscript: %s: creating runlevel3 symlink %s" % (self.name,enable_link))
64 os.symlink(enable_target, enable_link)
66 logger.log_exc("Initscript failed to create runlevel3 symlink %s" % enable_link, name=self.name)
68 # very similar but with systemd unit files - we target 'multi-user' in this context
69 def install_and_enable_vinit_for_systemd(self):
71 suitable for systemd-based VMs
73 # how are we wrt slice re-creation if we just kill this stuff
74 # of course no initscript will trigger at all ...
77 vinit_source = "/usr/share/NodeManager/sliver-systemd/vinit.service"
78 vinit_unit_file = "/vservers/%s/usr/lib/systemd/system/vinit.service" % self.name
79 enable_link = "/vservers/%s/etc/systemd/system/multi-user.target.wants/vinit.service" % self.name
80 enable_target = "/usr/lib/systemd/system/vinit.service"
82 code = file(vinit_source).read()
83 if tools.replace_file_with_string(vinit_unit_file, code, chmod=0755):
84 logger.log("Initscript: %s: installed vinit.service unit file" % self.name)
85 # create symlink for enabling this unit
86 if not os.path.islink(enable_link):
88 logger.log("Initscript: %s: creating enabling symlink %s" % (self.name, enable_link))
89 os.symlink(enable_target, enable_link)
91 logger.log_exc("Initscript failed to create enabling symlink %s" % enable_link,name=name)