Nir Soffer has uploaded a new change for review.
Change subject: utils: Add systemd_run command modifier
......................................................................
utils: Add systemd_run command modifier
Using new cmdutils.systemd_run, you can modify a command so it will run
as a service, using its own cgroup. This is handy when starting a long
running command that should continue to run after the service starting
it is terminated.
The command will run as systemd service, and can be controlled using
systemctl. For more info see systemd-run(1).
Change-Id: Ic35bdae752228b6716c25f0b9975fc500897a592
Relates-To:
https://bugzilla.redhat.com/1201355
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M configure.ac
M lib/vdsm/cmdutils.py
M lib/vdsm/constants.py.in
M tests/Makefile.am
A tests/cmdutilsTests.py
M vdsm/sudoers.vdsm.in
6 files changed, 64 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/39/40239/1
diff --git a/configure.ac b/configure.ac
index 0a30c3e..4da1955 100644
--- a/configure.ac
+++ b/configure.ac
@@ -328,6 +328,7 @@
AC_PATH_PROG([SU_PATH], [su], [/bin/su])
AC_PATH_PROG([SYSCTL_PATH], [sysctl], [/sbin/sysctl])
AC_PATH_PROG([SYSTEMCTL_PATH], [systemctl], [/bin/systemctl])
+AC_PATH_PROG([SYSTEMD_RUN_PATH], [systemd-run], [/usr/bin/systemd-run])
AC_PATH_PROG([TAR_PATH], [tar], [/bin/tar])
AC_PATH_PROG([TC_PATH], [tc], [/sbin/tc])
AC_PATH_PROG([TEE_PATH], [tee], [/usr/bin/tee])
diff --git a/lib/vdsm/cmdutils.py b/lib/vdsm/cmdutils.py
index 393bd88..b03162d 100644
--- a/lib/vdsm/cmdutils.py
+++ b/lib/vdsm/cmdutils.py
@@ -51,3 +51,15 @@
command = [constants.EXT_SUDO, SUDO_NON_INTERACTIVE_FLAG]
command.extend(cmd)
return command
+
+
+def systemd_run(cmd, scope=False, unit=None, slice=None):
+ command = [constants.EXT_SYSTEMD_RUN]
+ if scope:
+ command.append('--scope')
+ if unit:
+ command.append('--unit=%s' % unit)
+ if slice:
+ command.append('--slice=%s' % slice)
+ command.extend(cmd)
+ return command
diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in
index 60c272c..007d1d4 100644
--- a/lib/vdsm/constants.py.in
+++ b/lib/vdsm/constants.py.in
@@ -165,3 +165,4 @@
EXT_CURL_IMG_WRAP = '@LIBEXECDIR@/curl-img-wrap'
EXT_FC_SCAN = '@LIBEXECDIR@/fc-scan'
+EXT_SYSTEMD_RUN = '@SYSTEMD_RUN_PATH@'
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7fa1c09..1b97e31 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,7 @@
cPopenTests.py \
capsTests.py \
clientifTests.py \
+ cmdutilsTests.py \
concurrentTests.py \
configNetworkTests.py \
cpuProfileTests.py \
diff --git a/tests/cmdutilsTests.py b/tests/cmdutilsTests.py
new file mode 100644
index 0000000..a8c928b
--- /dev/null
+++ b/tests/cmdutilsTests.py
@@ -0,0 +1,47 @@
+#
+# Copyright 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from vdsm import cmdutils
+from vdsm import constants
+
+from testlib import VdsmTestCase
+
+
+class SystemdRunTests(VdsmTestCase):
+
+ def test_defaults(self):
+ cmd = cmdutils.systemd_run(['a', 'b'])
+ res = [constants.EXT_SYSTEMD_RUN, 'a', 'b']
+ self.assertEqual(cmd, res)
+
+ def test_scope(self):
+ cmd = cmdutils.systemd_run(['a', 'b'], scope=True)
+ res = [constants.EXT_SYSTEMD_RUN, '--scope', 'a', 'b']
+ self.assertEqual(cmd, res)
+
+ def test_unit(self):
+ cmd = cmdutils.systemd_run(['a', 'b'], unit='unit')
+ res = [constants.EXT_SYSTEMD_RUN, '--unit=unit', 'a',
'b']
+ self.assertEqual(cmd, res)
+
+ def test_slice(self):
+ cmd = cmdutils.systemd_run(['a', 'b'], slice='slice')
+ res = [constants.EXT_SYSTEMD_RUN, '--slice=slice', 'a',
'b']
+ self.assertEqual(cmd, res)
diff --git a/vdsm/sudoers.vdsm.in b/vdsm/sudoers.vdsm.in
index da88ff2..dd78b24 100644
--- a/vdsm/sudoers.vdsm.in
+++ b/vdsm/sudoers.vdsm.in
@@ -27,7 +27,8 @@
@MULTIPATH_PATH@, \
@SETSID_PATH@ @IONICE_PATH@ -c ? -n ? @SU_PATH@ vdsm -s /bin/sh -c
/usr/libexec/vdsm/spmprotect.sh*, \
@SERVICE_PATH@ vdsmd *, \
- @REBOOT_PATH@ -f
+ @REBOOT_PATH@ -f, \
+ @SYSTEMD_RUN_PATH@
vdsm ALL=(ALL) NOPASSWD: VDSM_LIFECYCLE, VDSM_STORAGE
Defaults:vdsm !requiretty
--
To view, visit
https://gerrit.ovirt.org/40239
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic35bdae752228b6716c25f0b9975fc500897a592
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>