Add the ability to have setup.py have a CLI option that specifies the daemon type
which then later affects the installation of certain config files, which then can be extracted during package creation as needed.
This commit is contained in:
parent
b40dfc6e9e
commit
d043d304f4
@ -150,6 +150,7 @@ def generate_spec_contents(args, tmpl_fn):
|
||||
else:
|
||||
subs['systemd'] = False
|
||||
|
||||
subs['daemon_type'] = args.boot
|
||||
return templater.render_from_file(tmpl_fn, params=subs)
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
|
||||
|
||||
# See: See: http://www.zarb.org/~jasonc/macros.php
|
||||
# See: http://www.zarb.org/~jasonc/macros.php
|
||||
# Or: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets
|
||||
# Or: http://www.rpm.org/max-rpm/ch-rpm-inside.html
|
||||
|
||||
@ -61,7 +61,9 @@ ssh keys and to let the user run various scripts.
|
||||
|
||||
%install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT
|
||||
%{__python} setup.py install -O1 \
|
||||
--skip-build --root $RPM_BUILD_ROOT \
|
||||
--daemon-type={{daemon_type}}
|
||||
|
||||
# Note that /etc/rsyslog.d didn't exist by default until F15.
|
||||
# el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420
|
||||
@ -69,24 +71,6 @@ mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d
|
||||
cp -p tools/21-cloudinit.conf \
|
||||
$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
|
||||
|
||||
{{if init_d}}
|
||||
mkdir -p $RPM_BUILD_ROOT/%{_initddir}/
|
||||
{{endif}}
|
||||
{{if init_d_local}}
|
||||
cp -p initd/cloud-init-local $RPM_BUILD_ROOT/%{_initddir}/
|
||||
cp -p initd/cloud-config $RPM_BUILD_ROOT/%{_initddir}/
|
||||
cp -p initd/cloud-final $RPM_BUILD_ROOT/%{_initddir}/
|
||||
{{elif init_d}}
|
||||
cp -p initd/cloud-init $RPM_BUILD_ROOT/%{_initddir}/
|
||||
cp -p initd/cloud-config $RPM_BUILD_ROOT/%{_initddir}/
|
||||
cp -p initd/cloud-final $RPM_BUILD_ROOT/%{_initddir}/
|
||||
{{endif}}
|
||||
|
||||
{{if systemd}}
|
||||
mkdir -p $RPM_BUILD_ROOT/%{_unitdir}
|
||||
cp -p systemd/* $RPM_BUILD_ROOT/%{_unitdir}
|
||||
{{endif}}
|
||||
|
||||
%clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
@ -103,13 +87,13 @@ fi
|
||||
{{endif}}
|
||||
|
||||
{{if init_d_local}}
|
||||
/sbin/chkconfig --add /etc/rc.d/init.d/cloud-init-local
|
||||
/sbin/chkconfig --add %{_initrddir}/cloud-init-local
|
||||
{{elif init_d}}
|
||||
/sbin/chkconfig --add /etc/rc.d/init.d/cloud-init
|
||||
/sbin/chkconfig --add %{_initrddir}/cloud-init
|
||||
{{endif}}
|
||||
{{if init_d}}
|
||||
/sbin/chkconfig --add /etc/rc.d/init.d/cloud-config
|
||||
/sbin/chkconfig --add /etc/rc.d/init.d/cloud-final
|
||||
/sbin/chkconfig --add %{_initrddir}/cloud-config
|
||||
/sbin/chkconfig --add %{_initrddir}/cloud-final
|
||||
{{endif}}
|
||||
|
||||
%preun
|
||||
@ -166,11 +150,7 @@ fi
|
||||
{{endif}}
|
||||
|
||||
{{if systemd}}
|
||||
%{_unitdir}/cloud-config.service
|
||||
%{_unitdir}/cloud-config.target
|
||||
%{_unitdir}/cloud-init.service
|
||||
%{_unitdir}/cloud-init-local.service
|
||||
%{_unitdir}/cloud-final.service
|
||||
%{_unitdir}/cloud-*
|
||||
{{endif}}
|
||||
|
||||
# Program binaries
|
||||
|
72
setup.py
72
setup.py
@ -26,10 +26,45 @@ import os
|
||||
import re
|
||||
|
||||
import setuptools
|
||||
from setuptools.command.install import install
|
||||
|
||||
from distutils.command.install_data import install_data
|
||||
from distutils.errors import DistutilsArgError
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
def is_f(p):
|
||||
return os.path.isfile(p)
|
||||
|
||||
|
||||
DAEMON_FILES = {
|
||||
'initd': filter((lambda x: is_f(x)
|
||||
and x.find('local') == -1), glob('initd/*')),
|
||||
'initd-local': filter((lambda x: is_f(x)
|
||||
and not x.endswith('cloud-init')), glob('initd/*')),
|
||||
'systemd': filter((lambda x: is_f(x)), glob('systemd/*')),
|
||||
'upstart': filter((lambda x: is_f(x)
|
||||
and x.find('local') == -1
|
||||
and x.find('nonet') == -1), glob('upstart/*')),
|
||||
'upstart-nonet': filter((lambda x: is_f(x)
|
||||
and x.find('local') == -1
|
||||
and not x.endswith('cloud-init.conf')), glob('upstart/*')),
|
||||
'upstart-local': filter((lambda x: is_f(x)
|
||||
and x.find('nonet') == -1
|
||||
and not x.endswith('cloud-init.conf')), glob('upstart/*')),
|
||||
}
|
||||
DAEMON_ROOTS = {
|
||||
'initd': '/etc/rc.d/init.d',
|
||||
'initd-local': '/etc/rc.d/init.d',
|
||||
'systemd': '/etc/systemd/system/',
|
||||
'upstart': '/etc/init/',
|
||||
'upstart-nonet': '/etc/init/',
|
||||
'upstart-local': '/etc/init/',
|
||||
}
|
||||
DAEMON_TYPES = sorted(list(DAEMON_ROOTS.keys()))
|
||||
|
||||
|
||||
def tiny_p(cmd, capture=True):
|
||||
# Darn python 2.6 doesn't have check_output (argggg)
|
||||
stdout = subprocess.PIPE
|
||||
@ -46,10 +81,6 @@ def tiny_p(cmd, capture=True):
|
||||
return (out, err)
|
||||
|
||||
|
||||
def is_f(p):
|
||||
return os.path.isfile(p)
|
||||
|
||||
|
||||
def get_version():
|
||||
cmd = ['tools/read-version']
|
||||
(ver, _e) = tiny_p(cmd)
|
||||
@ -62,6 +93,34 @@ def read_requires():
|
||||
return deps.splitlines()
|
||||
|
||||
|
||||
# TODO: Is there a better way to do this??
|
||||
class DaemonInstallData(install):
|
||||
user_options = install.user_options + [
|
||||
# This will magically show up in member variable 'daemon_type'
|
||||
('daemon-type=', None,
|
||||
('daemon type to configure (%s) [default: None]') %
|
||||
(", ".join(DAEMON_TYPES))
|
||||
),
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
install.initialize_options(self)
|
||||
self.daemon_type = None
|
||||
|
||||
def finalize_options(self):
|
||||
install.finalize_options(self)
|
||||
if self.daemon_type and self.daemon_type not in DAEMON_TYPES:
|
||||
raise DistutilsArgError(
|
||||
("You must specify one of (%s) when"
|
||||
" specifying a daemon type!") % (", ".join(DAEMON_TYPES))
|
||||
)
|
||||
elif self.daemon_type:
|
||||
self.distribution.data_files.append((DAEMON_ROOTS[self.daemon_type],
|
||||
DAEMON_FILES[self.daemon_type]))
|
||||
# Force that command to reinitalize (with new file list)
|
||||
self.distribution.reinitialize_command('install_data', True)
|
||||
|
||||
|
||||
setuptools.setup(name='cloud-init',
|
||||
version=get_version(),
|
||||
description='EC2 initialisation magic',
|
||||
@ -84,4 +143,9 @@ setuptools.setup(name='cloud-init',
|
||||
('/usr/share/doc/cloud-init/examples/seed', filter(is_f, glob('doc/examples/seed/*'))),
|
||||
],
|
||||
install_requires=read_requires(),
|
||||
cmdclass = {
|
||||
# Use a subclass for install that handles
|
||||
# adding on the right daemon configuration files
|
||||
'install': DaemonInstallData,
|
||||
},
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user