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 for now let's try to do it for both systems unconditionnally
29 # this being said all the paths do not necessarily exist on all flavours of rootfs
30 try: self.install_and_enable_vinit_for_init ()
32 try: self.install_and_enable_vinit_for_systemd ()
35 # unconditionnally install and enable the generic vinit script
36 # mimicking chkconfig for enabling the generic vinit script
37 # this is hardwired for runlevel 3
38 def install_and_enable_vinit_for_init (self):
39 "suitable for init-based VMs"
40 vinit_source="/usr/share/NodeManager/sliver-initscripts/vinit"
41 vinit_script="/vservers/%s/etc/rc.d/init.d/vinit"%self.name
42 enable_link="/vservers/%s/etc/rc.d/rc3.d/S99vinit"%self.name
43 enable_target="../init.d/vinit"
45 code=file(vinit_source).read()
46 if tools.replace_file_with_string(vinit_script,code,chmod=0755):
47 logger.log("Initscript: %s: installed generic vinit rc script"%self.name)
48 # create symlink for runlevel 3
49 if not os.path.islink(enable_link):
51 logger.log("Initscript: %s: creating runlevel3 symlink %s"%(self.name,enable_link))
52 os.symlink(enable_target,enable_link)
54 logger.log_exc("Initscript: %s: failed to create runlevel3 symlink %s"%enable_link)
56 # very similar but with systemd unit files - we target 'multi-user' in this context
57 def install_and_enable_vinit_for_systemd(self):
58 "suitable for systemd-based VMs"
59 vinit_source="/usr/share/NodeManager/sliver-systemd/vinit.service"
60 vinit_unit_file="/vservers/%s/usr/lib/systemd/system/vinit.service"%self.name
61 enable_link="/vservers/%s/etc/systemd/system/multi-user.target.wants/vinit.service"%self.name
62 enable_target="/usr/lib/systemd/system/vinit.service"
64 code=file(vinit_source).read()
65 if tools.replace_file_with_string(vinit_unit_file,code,chmod=0755):
66 logger.log("Initscript: %s: installed vinit.service unit file"%self.name)
67 # create symlink for enabling this unit
68 if not os.path.islink(enable_link):
70 logger.log("Initscript: %s: creating enabling symlink %s"%(self.name,enable_link))
71 os.symlink(enable_target,enable_link)
73 logger.log_exc("Initscript: %s: failed to create enabling symlink %s"%enable_link)
76 #ln -s '/usr/lib/systemd/system/vinit.service' '/etc/systemd/system/multi-user.target.wants/vinit.service'
79 # install or remove the slice inistscript, as instructed by the initscript tag
80 def refresh_slice_vinit(self):
82 sliver_initscript="/vservers/%s/etc/rc.d/init.d/vinit.slice"%self.name
83 if tools.replace_file_with_string(sliver_initscript,code,remove_if_empty=True,chmod=0755):
85 logger.log("Initscript: %s: Installed new initscript in %s"%(self.name,sliver_initscript))
87 # Only need to rerun the initscript if the vserver is
88 # already running. If the vserver isn't running, then the
89 # initscript will automatically be started by
90 # /etc/rc.d/vinit when the vserver is started.
91 self.rerun_slice_vinit()
93 logger.log("Initscript: %s: Removed obsolete initscript %s"%(self.name,sliver_initscript))