From d9bfda2dcdfd62802346f4d1c883349b4ca6ed53 Mon Sep 17 00:00:00 2001 From: Niels Abspoel Date: Tue, 29 Jul 2014 20:34:12 +0200 Subject: [PATCH] This fixes two issues #14337 and #13788 use-forking-daemon.patch -> #14337 the other patchesr are for #13788 With thanks to Tim Serong who created the patches. --- ...allow-systemd-parameterized-services.patch | 74 +++++++++++++++++ .../allow-systemd-units-no-unit-files.patch | 79 +++++++++++++++++++ pkg/suse/pass-all-systemd-list-units.patch | 28 +++++++ pkg/suse/salt.changes | 24 ++++++ pkg/suse/salt.spec | 35 +++++--- pkg/suse/use-forking-daemon.patch | 17 ++++ 6 files changed, 244 insertions(+), 13 deletions(-) create mode 100644 pkg/suse/allow-systemd-parameterized-services.patch create mode 100644 pkg/suse/allow-systemd-units-no-unit-files.patch create mode 100644 pkg/suse/pass-all-systemd-list-units.patch create mode 100644 pkg/suse/use-forking-daemon.patch diff --git a/pkg/suse/allow-systemd-parameterized-services.patch b/pkg/suse/allow-systemd-parameterized-services.patch new file mode 100644 index 0000000000..427700b3d2 --- /dev/null +++ b/pkg/suse/allow-systemd-parameterized-services.patch @@ -0,0 +1,74 @@ +From 9617d339273ceecd3b47cbcd8c331080faac48f8 Mon Sep 17 00:00:00 2001 +From: Massimiliano Torromeo +Date: Mon, 14 Apr 2014 18:01:18 +0200 +Subject: [PATCH] Allow systemd parametrized services to be enabled by the + service state. + +This makes the systemd.get_all function return the combined output of +list-units and list-unit-files and the systemd.available function will +also check for the base unit name stripped of the user parameter +(e.g. dhcpcd@eth0 will be considered available if dhcpcd@.service exists) +--- + salt/modules/systemd.py | 18 +++++++++++++----- + 1 file changed, 13 insertions(+), 5 deletions(-) + +diff --git a/salt/modules/systemd.py b/salt/modules/systemd.py +index e2cfb1d..72079d7 100644 +--- a/salt/modules/systemd.py ++++ b/salt/modules/systemd.py +@@ -82,7 +82,7 @@ def _get_all_units(): + r')\s+loaded\s+(?P[^\s]+)') + + out = __salt__['cmd.run_stdout']( +- 'systemctl --full list-units | col -b' ++ 'systemctl --full --no-legend --no-pager list-units | col -b' + ) + + ret = {} +@@ -104,7 +104,7 @@ def _get_all_unit_files(): + r')\s+(?P.+)$') + + out = __salt__['cmd.run_stdout']( +- 'systemctl --full list-unit-files | col -b' ++ 'systemctl --full --no-legend --no-pager list-unit-files | col -b' + ) + + ret = {} +@@ -195,7 +195,7 @@ def get_all(): + + salt '*' service.get_all + ''' +- return sorted(_get_all_units().keys()) ++ return sorted(set(_get_all_units().keys() + _get_all_unit_files().keys())) + + + def available(name): +@@ -209,7 +209,15 @@ def available(name): + + salt '*' service.available sshd + ''' +- return _canonical_template_unit_name(name) in get_all() ++ name = _canonical_template_unit_name(name) ++ units = get_all() ++ if name in units: ++ return True ++ elif '@' in name: ++ templatename = name[:name.find('@') + 1] ++ return templatename in units ++ else: ++ return False + + + def missing(name): +@@ -224,7 +232,7 @@ def missing(name): + + salt '*' service.missing sshd + ''' +- return not _canonical_template_unit_name(name) in get_all() ++ return not available(name) + + + def start(name): +-- +1.9.3 + diff --git a/pkg/suse/allow-systemd-units-no-unit-files.patch b/pkg/suse/allow-systemd-units-no-unit-files.patch new file mode 100644 index 0000000000..1f9692589a --- /dev/null +++ b/pkg/suse/allow-systemd-units-no-unit-files.patch @@ -0,0 +1,79 @@ +From 90bece1faa1862465e97f7caf262c65cd84583ff Mon Sep 17 00:00:00 2001 +From: Massimiliano Torromeo +Date: Fri, 11 Apr 2014 14:43:02 +0200 +Subject: [PATCH] Allow systemd units no provided by unit files to be handled. + +This allows to query status, start, stop, restart and list units that +are not actually provided by unit files. Such units cannot be +enabled/disabled and that's why those actions still prefer the +"list-unit-files" output over "list-units". + +Units that couldn't be handled otherwise include for example mount +units and sysvinit compatibility units such as those present on +debian systems. + +The output of a "service.running ssh" state on a debian wheezy target +is: + + ID: ssh + Function: service.running + Result: False + Comment: The named service ssh is not available + Changes: + +after this patch: + + ID: ssh + Function: service.running + Result: True + Comment: The service ssh is already running + Changes: +--- + salt/modules/systemd.py | 24 +++++++++++++++++++++++- + 1 file changed, 23 insertions(+), 1 deletion(-) + +diff --git a/salt/modules/systemd.py b/salt/modules/systemd.py +index 57b55f5..e2cfb1d 100644 +--- a/salt/modules/systemd.py ++++ b/salt/modules/systemd.py +@@ -72,6 +72,28 @@ def _systemctl_cmd(action, name): + return 'systemctl {0} {1}'.format(action, _canonical_unit_name(name)) + + ++def _get_all_units(): ++ ''' ++ Get all units and their state. Units ending in .service ++ are normalized so that they can be referenced without a type suffix. ++ ''' ++ rexp = re.compile(r'(?m)^(?P.+)\.(?P' + ++ '|'.join(VALID_UNIT_TYPES) + ++ r')\s+loaded\s+(?P[^\s]+)') ++ ++ out = __salt__['cmd.run_stdout']( ++ 'systemctl --full list-units | col -b' ++ ) ++ ++ ret = {} ++ for match in rexp.finditer(out): ++ name = match.group('name') ++ if match.group('type') != 'service': ++ name += '.' + match.group('type') ++ ret[name] = match.group('active') ++ return ret ++ ++ + def _get_all_unit_files(): + ''' + Get all unit files and their state. Unit files ending in .service +@@ -173,7 +195,7 @@ def get_all(): + + salt '*' service.get_all + ''' +- return sorted(_get_all_unit_files().keys()) ++ return sorted(_get_all_units().keys()) + + + def available(name): +-- +1.9.3 + diff --git a/pkg/suse/pass-all-systemd-list-units.patch b/pkg/suse/pass-all-systemd-list-units.patch new file mode 100644 index 0000000000..8471d39156 --- /dev/null +++ b/pkg/suse/pass-all-systemd-list-units.patch @@ -0,0 +1,28 @@ +From 968b26f45351d790a9fa2afd9bbd6c5bb31f13d5 Mon Sep 17 00:00:00 2001 +From: Tim Serong +Date: Mon, 7 Jul 2014 21:14:26 +1000 +Subject: [PATCH] Pass --all when invoking `systemctl list-units` + +`systemctl list-units` without --all won't list services that aren't +actually running. See https://github.com/saltstack/salt/issues/13788 +for some further discussion. +--- + salt/modules/systemd.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/salt/modules/systemd.py b/salt/modules/systemd.py +index ca93986..036adb4 100644 +--- a/salt/modules/systemd.py ++++ b/salt/modules/systemd.py +@@ -82,7 +82,7 @@ def _get_all_units(): + r')\s+loaded\s+(?P[^\s]+)') + + out = __salt__['cmd.run_stdout']( +- 'systemctl --full --no-legend --no-pager list-units | col -b' ++ 'systemctl --all --full --no-legend --no-pager list-units | col -b' + ) + + ret = {} +-- +1.9.3 + diff --git a/pkg/suse/salt.changes b/pkg/suse/salt.changes index 9782598881..28d63875eb 100644 --- a/pkg/suse/salt.changes +++ b/pkg/suse/salt.changes @@ -1,3 +1,27 @@ +------------------------------------------------------------------- +Thu Jul 24 13:11:03 UTC 2014 - tserong@suse.com + +- Allow salt to correctly detect services provided by init scripts + + Added allow-systemd-units-no-unit-files.patch + + Added allow-systemd-parameterized-services.patch + + Added pass-all-systemd-list-units.patch +- Move systemd service file fix to patch, add PIDFile parameter (this + fix is applicable for all SUSE versions, not just 12.3) + + Added use-forking-daemon.patch + +------------------------------------------------------------------- +Wed Jul 23 06:24:00 UTC 2014 - aboe76@gmail.com + +- Improve systemd service file fix for 12.3 + Use forking instead of Simple and daemonize salt-master process + +------------------------------------------------------------------- +Sat Jul 19 07:58:18 UTC 2014 - aboe76@gmail.com + +- Fixed bug in opensuse 12.3 systemd file + systemd 198 doesn't have python-systemd binding. +- Disabled testing on SLES + ------------------------------------------------------------------- Thu Jul 10 18:25:05 UTC 2014 - aboe76@gmail.com diff --git a/pkg/suse/salt.spec b/pkg/suse/salt.spec index f56aa71c74..2c7bf46357 100644 --- a/pkg/suse/salt.spec +++ b/pkg/suse/salt.spec @@ -1,7 +1,7 @@ # # spec file for package salt # -# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -24,6 +24,14 @@ License: Apache-2.0 Group: System/Monitoring Url: http://saltstack.org/ Source0: http://pypi.python.org/packages/source/s/%{name}/%{name}-%{version}.tar.gz +# PATCH-FIX-UPSTREAM allow-systemd-units-no-unit-files.patch tserong@suse.com -- allow salt to detect init script services +Patch1: allow-systemd-units-no-unit-files.patch +# PATCH-FIX-UPSTREAM allow-systemd-units-no-unit-files.patch tserong@suse.com -- part 2 of above fix +Patch2: allow-systemd-parameterized-services.patch +# PATCH-FIX-UPSTREAM pass-all-systemd-list-units.patch tserong@suse.com -- part 3 of above fix +Patch3: pass-all-systemd-list-units.patch +# PATCH-FIX-OPENSUSE use-forking-daemon.patch tserong@suse.com -- We don't have python-systemd, so notify can't work +Patch4: use-forking-daemon.patch #for building BuildRequires: fdupes @@ -31,14 +39,14 @@ BuildRequires: logrotate BuildRequires: python-Jinja2 BuildRequires: python-M2Crypto BuildRequires: python-PyYAML -BuildRequires: python-yaml +BuildRequires: python-apache-libcloud >= 0.14.0 BuildRequires: python-devel BuildRequires: python-msgpack-python +BuildRequires: python-psutil BuildRequires: python-pycrypto BuildRequires: python-pyzmq -BuildRequires: python-psutil BuildRequires: python-requests -BuildRequires: python-apache-libcloud >= 0.14.0 +BuildRequires: python-yaml %if 0%{?sles_version} BuildRequires: python @@ -65,13 +73,13 @@ BuildRequires: python-sphinx Requires: logrotate Requires: python-Jinja2 -Requires: python-yaml Requires: python-PyYAML -Requires: python-yaml Requires: python-apache-libcloud -Requires: python-xml Requires: python-psutil Requires: python-requests +Requires: python-xml +Requires: python-yaml +Requires: python-yaml Requires(pre): %fillup_prereq %if 0%{?suse_version} < 1210 Requires(pre): %insserv_prereq @@ -87,7 +95,6 @@ Requires(pre): %insserv_prereq BuildRequires: bash-completion %endif #with_bashcomp - BuildRoot: %{_tmppath}/%{name}-%{version}-build %if 0%{?suse_version} && 0%{?suse_version} <= 1110 %{!?python_sitelib: %global python_sitelib %(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} @@ -98,7 +105,6 @@ BuildArch: noarch Recommends: python-botocore Recommends: python-netaddr - %description Salt is a distributed remote execution system used to execute commands and query data. It was developed in order to bring the best solutions found in @@ -224,6 +230,10 @@ Bash command line completion support for %{name}. %prep %setup -q +%patch1 -p1 +%patch2 -p1 +%patch3 -p1 +%patch4 -p1 %build python setup.py build @@ -253,7 +263,7 @@ mkdir -p %{buildroot}/var/log/salt mkdir -p %{buildroot}/srv/salt mkdir -p %{buildroot}/srv/pillar mkdir -p %{buildroot}%{_docdir}/salt -# + ## install init and systemd scripts %if 0%{?_unitdir:1} install -Dpm 0644 pkg/salt-master.service %{buildroot}%_unitdir/salt-master.service @@ -293,10 +303,9 @@ install -Dpm 0644 pkg/salt.bash "%{buildroot}/etc/bash_completion.d/%{name}" %endif #with_bashcomp %check -# don't test on factory because of ssl2 method deprication -#%%if 0%{?suse_version} < 1310 +%if 0%{?suse_version} < 1310 %{__python} setup.py test --runtests-opts=-u -#%%endif +%endif %preun syndic %if 0%{?_unitdir:1} diff --git a/pkg/suse/use-forking-daemon.patch b/pkg/suse/use-forking-daemon.patch new file mode 100644 index 0000000000..01ada47cbe --- /dev/null +++ b/pkg/suse/use-forking-daemon.patch @@ -0,0 +1,17 @@ +Index: salt-2014.1.7/pkg/salt-master.service +=================================================================== +--- salt-2014.1.7.orig/pkg/salt-master.service ++++ salt-2014.1.7/pkg/salt-master.service +@@ -3,8 +3,10 @@ Description=The Salt Master Server + After=syslog.target network.target + + [Service] +-Type=notify +-ExecStart=/usr/bin/salt-master ++Type=forking ++ExecStart=/usr/bin/salt-master --daemon ++# Daemon mode doesn't seem to work reliably without PIDFile ++PIDFile=/var/run/salt-master.pid + + [Install] + WantedBy=multi-user.target