mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00
Modularize init script installation
Don't install various init scripts when using cloud-init
This commit is contained in:
parent
4acde32c5d
commit
668b9896c1
6 changed files with 50 additions and 37 deletions
|
@ -11,3 +11,5 @@ class BootstrapInformation(object):
|
|||
import os.path
|
||||
workspace_dirname = '{id:x}'.format(id=self.run_id)
|
||||
self.workspace = os.path.join(manifest.bootstrapper['workspace'], workspace_dirname)
|
||||
|
||||
self.initd = {'install': {}, 'disable': []}
|
||||
|
|
|
@ -1,43 +1,13 @@
|
|||
from base import Task
|
||||
from common import phases
|
||||
from common.exceptions import TaskError
|
||||
from common.tools import log_check_call
|
||||
import os.path
|
||||
|
||||
|
||||
class ResolveInitScripts(Task):
|
||||
description = 'Determining which startup scripts to install or disable'
|
||||
phase = phases.system_modification
|
||||
|
||||
def run(self, info):
|
||||
init_scripts = {}
|
||||
init_scripts['expand-root'] = 'expand-root'
|
||||
|
||||
from subprocess import CalledProcessError
|
||||
try:
|
||||
log_check_call(['/usr/sbin/chroot', info.root,
|
||||
'/usr/bin/dpkg-query', '-W', 'openssh-server'])
|
||||
init_scripts['generate-ssh-hostkeys'] = 'generate-ssh-hostkeys'
|
||||
if info.manifest.system['release'] == 'squeeze':
|
||||
init_scripts['generate-ssh-hostkeys'] = 'squeeze/generate-ssh-hostkeys'
|
||||
except CalledProcessError:
|
||||
pass
|
||||
|
||||
disable_scripts = ['hwclock.sh']
|
||||
if info.manifest.system['release'] == 'squeeze':
|
||||
disable_scripts.append('hwclockfirst.sh')
|
||||
|
||||
init_scripts_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/init.d'))
|
||||
for name, path in init_scripts.iteritems():
|
||||
init_scripts[name] = os.path.join(init_scripts_dir, path)
|
||||
|
||||
info.initd = {'install': init_scripts,
|
||||
'disable': disable_scripts}
|
||||
|
||||
|
||||
class InstallInitScripts(Task):
|
||||
description = 'Installing startup scripts'
|
||||
phase = phases.system_modification
|
||||
predecessors = [ResolveInitScripts]
|
||||
|
||||
def run(self, info):
|
||||
import stat
|
||||
|
@ -55,6 +25,47 @@ class InstallInitScripts(Task):
|
|||
log_check_call(['/usr/sbin/chroot', info.root, '/sbin/insserv', '--remove', name])
|
||||
|
||||
|
||||
class AddExpandRoot(Task):
|
||||
description = 'Adding init script to expand the root volume'
|
||||
phase = phases.system_modification
|
||||
successors = [InstallInitScripts]
|
||||
|
||||
def run(self, info):
|
||||
init_scripts_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/init.d'))
|
||||
info.initd['install']['expand-root'] = os.path.join(init_scripts_dir, 'expand-root')
|
||||
|
||||
|
||||
class AddSSHKeyGeneration(Task):
|
||||
description = 'Adding SSH private key generation init scripts'
|
||||
phase = phases.system_modification
|
||||
successors = [InstallInitScripts]
|
||||
|
||||
def run(self, info):
|
||||
init_scripts_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/init.d'))
|
||||
install = info.initd['install']
|
||||
from subprocess import CalledProcessError
|
||||
try:
|
||||
log_check_call(['/usr/sbin/chroot', info.root,
|
||||
'/usr/bin/dpkg-query', '-W', 'openssh-server'])
|
||||
if info.manifest.system['release'] == 'squeeze':
|
||||
install['generate-ssh-hostkeys'] = os.path.join(init_scripts_dir, 'squeeze/generate-ssh-hostkeys')
|
||||
else:
|
||||
install['generate-ssh-hostkeys'] = os.path.join(init_scripts_dir, 'generate-ssh-hostkeys')
|
||||
except CalledProcessError:
|
||||
pass
|
||||
|
||||
|
||||
class RemoveHWClock(Task):
|
||||
description = 'Removing hardware clock init scripts'
|
||||
phase = phases.system_modification
|
||||
successors = [InstallInitScripts]
|
||||
|
||||
def run(self, info):
|
||||
info.initd['disable'].append('hwclock.sh')
|
||||
if info.manifest.system['release'] == 'squeeze':
|
||||
info.initd['disable'].append('hwclockfirst.sh')
|
||||
|
||||
|
||||
class AdjustExpandRootScript(Task):
|
||||
description = 'Adjusting the expand-root script'
|
||||
phase = phases.system_modification
|
||||
|
|
|
@ -15,10 +15,10 @@ class AptSources(Task):
|
|||
manifest_vars = {'release': info.manifest.system['release'],
|
||||
'architecture': info.manifest.system['architecture'],
|
||||
'apt_mirror': 'http://http.debian.net/debian'}
|
||||
for name in info.manifest.plugins['packages']['sources'].iterkeys():
|
||||
for name, lines in info.manifest.plugins['packages']['sources'].iteritems():
|
||||
list_path = os.path.join(info.root, 'etc/apt/sources.list.d/', name + '.list')
|
||||
with open(list_path, 'a') as source_list:
|
||||
for line in info.manifest.plugins['packages']['sources'][name]:
|
||||
for line in lines:
|
||||
source_list.write('{line}\n'.format(line=line.format(**manifest_vars)))
|
||||
|
||||
|
||||
|
|
|
@ -57,7 +57,9 @@ def tasks(tasklist, manifest):
|
|||
common_network.RemoveDNSInfo,
|
||||
common_network.ConfigureNetworkIF,
|
||||
network.EnableDHCPCDDNS,
|
||||
common_initd.ResolveInitScripts,
|
||||
common_initd.AddExpandRoot,
|
||||
common_initd.AddSSHKeyGeneration,
|
||||
common_initd.RemoveHWClock,
|
||||
initd.AddEC2InitScripts,
|
||||
common_initd.InstallInitScripts,
|
||||
common_initd.AdjustExpandRootScript,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from base import Task
|
||||
from common import phases
|
||||
from common.exceptions import TaskError
|
||||
from common.tasks import initd
|
||||
import os.path
|
||||
|
||||
|
@ -8,7 +7,6 @@ import os.path
|
|||
class AddEC2InitScripts(Task):
|
||||
description = 'Adding EC2 startup scripts'
|
||||
phase = phases.system_modification
|
||||
predecessors = [initd.ResolveInitScripts]
|
||||
successors = [initd.InstallInitScripts]
|
||||
|
||||
def run(self, info):
|
||||
|
|
|
@ -45,7 +45,7 @@ def tasks(tasklist, manifest):
|
|||
network.RemoveDNSInfo,
|
||||
network.ConfigureNetworkIF,
|
||||
network.RemoveHostname,
|
||||
initd.ResolveInitScripts,
|
||||
initd.AddSSHKeyGeneration,
|
||||
initd.InstallInitScripts,
|
||||
cleanup.ClearMOTD,
|
||||
cleanup.CleanTMP,
|
||||
|
|
Loading…
Add table
Reference in a new issue