8 def __init__(self, name):
12 def configure(self, rec):
13 # logger.log("Initscript.configure")
14 new_initscript = rec['initscript']
15 if new_initscript != self.initscript:
16 self.initscript = new_initscript
17 # not used anymore, we always check against the installed script
18 #self.initscriptchanged = True
19 self.refresh_slice_vinit()
21 def install_and_enable_vinit(self):
22 "prepare sliver rootfs init and systemd so the vinit service kicks in"
23 # the fact that systemd attempts to run old-style services
24 # says we should do either one or the other and not both
25 # but actually if that was true we could just do it for init and be fine
26 # which is not what we've seen starting with f18
27 # so we try for a systemd system, and if it fails it means
28 # one of the dir does not exist and so we are dealing with an init-based rootfs
30 self.install_and_enable_vinit_for_systemd ()
32 self.install_and_enable_vinit_for_init ()
34 # unconditionnally install and enable the generic vinit script
35 # mimicking chkconfig for enabling the generic vinit script
36 # this is hardwired for runlevel 3
37 def install_and_enable_vinit_for_init(self):
39 suitable for init-based VMs
41 vinit_source = "/usr/share/NodeManager/sliver-initscripts/vinit"
42 vinit_script = "/vservers/%s/etc/rc.d/init.d/vinit" % self.name
43 enable_link = "/vservers/%s/etc/rc.d/rc3.d/S99vinit" % self.name
44 enable_target = "../init.d/vinit"
46 code = file(vinit_source).read()
47 if tools.replace_file_with_string(vinit_script, code, chmod=0755):
48 logger.log("Initscript: %s: installed generic vinit rc script" % self.name)
49 # create symlink for runlevel 3
50 if not os.path.islink(enable_link):
52 logger.log("Initscript: %s: creating runlevel3 symlink %s" % (self.name,enable_link))
53 os.symlink(enable_target, enable_link)
55 logger.log_exc("Initscript failed to create runlevel3 symlink %s" % enable_link, name=self.name)
57 # very similar but with systemd unit files - we target 'multi-user' in this context
58 def install_and_enable_vinit_for_systemd(self):
60 suitable for systemd-based VMs
62 vinit_source = "/usr/share/NodeManager/sliver-systemd/vinit.service"
63 vinit_unit_file = "/vservers/%s/usr/lib/systemd/system/vinit.service" % self.name
64 enable_link = "/vservers/%s/etc/systemd/system/multi-user.target.wants/vinit.service" % self.name
65 enable_target = "/usr/lib/systemd/system/vinit.service"
67 code = file(vinit_source).read()
68 if tools.replace_file_with_string(vinit_unit_file, code, chmod=0755):
69 logger.log("Initscript: %s: installed vinit.service unit file" % self.name)
70 # create symlink for enabling this unit
71 if not os.path.islink(enable_link):
73 logger.log("Initscript: %s: creating enabling symlink %s" % (self.name, enable_link))
74 os.symlink(enable_target, enable_link)
76 logger.log_exc("Initscript failed to create enabling symlink %s" % enable_link,name=name)
79 # install or remove the slice inistscript, as instructed by the initscript tag
80 def refresh_slice_vinit(self):
81 logger.log("initscript.refresh_slice_vinit {}".format(self.name))
82 code = self.initscript
83 sliver_initscript="/vservers/%s/etc/rc.d/init.d/vinit.slice" % self.name
84 if tools.replace_file_with_string(sliver_initscript, code, remove_if_empty=True, chmod=0755):
86 logger.log("Initscript: %s: Installed new initscript in %s" % (self.name, sliver_initscript))
88 # Only need to rerun the initscript if the vserver is
89 # already running. If the vserver isn't running, then the
90 # initscript will automatically be started by
91 # /etc/rc.d/vinit when the vserver is started.
92 self.rerun_slice_vinit()
94 logger.log("Initscript: %s: Removed obsolete initscript %s" % (self.name, sliver_initscript))
96 logger.log("initscript.refresh_slice_vinit {} - void".format(self.name))