Change in vdsm[master]: vdsmd.init: Add init adapter

zhshzhou at linux.vnet.ibm.com zhshzhou at linux.vnet.ibm.com
Tue Jun 11 19:35:32 UTC 2013


Zhou Zheng Sheng has uploaded a new change for review.

Change subject: vdsmd.init: Add init adapter
......................................................................

vdsmd.init: Add init adapter

Add vdsm/init/daemonAdapter for various init systems. daemonAdapter can
optionally start vdsm with renice, respawn, run as user option. On
powerful init systems, we call daemonAdapter with no options, on SysV
init system, we call it with respawn option.

This patch uses daemonAdapter in vdsmd.init.in and vdsmd.service.
vdsmd.service will not call the SysV init script vdsmd.init anymore,
instead, it calls daemonAdapter directly.

Change-Id: Id8e514df1ca88500f746242134ddb24c31588046
Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
---
M .gitignore
M vdsm.spec.in
M vdsm/Makefile.am
M vdsm/init/Makefile.am
A vdsm/init/daemonAdapter
M vdsm/sudoers.vdsm.in
M vdsm/vdsm
M vdsm/vdsmd.init.in
D vdsm/vdsmd.service
A vdsm/vdsmd.service.in
10 files changed, 125 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/15578/1

diff --git a/.gitignore b/.gitignore
index f2be2dc..47b474f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,6 +54,7 @@
 vdsm/vdsm.rwtab
 vdsm/vdsmd.8
 vdsm/vdsmd.init
+vdsm/vdsmd.service
 vdsm/supervdsmd.init
 vdsm/supervdsmd.service
 vdsm_api/vdsm-api.html
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 40812ee..66e17ba 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -120,6 +120,7 @@
 Requires: selinux-policy-targeted
 %else
 Requires: python
+Requires: python-argparse
 # Update the qemu-kvm requires when block_stream will be included
 Requires: qemu-kvm >= 2:0.12.1.2-2.295.el6_3.4
 Requires: qemu-img >= 2:0.12.1.2-2.295.el6_3.4
@@ -531,7 +532,6 @@
 
 %if 0%{?with_systemd}
 # Install the systemd scripts
-install -Dm 0755 vdsm/vdsmd.init %{buildroot}/lib/systemd/systemd-vdsmd
 install -Dm 0644 vdsm/vdsmd.service %{buildroot}%{_unitdir}/vdsmd.service
 install -Dm 0644 vdsm/supervdsmd.service %{buildroot}%{_unitdir}/supervdsmd.service
 
@@ -750,7 +750,6 @@
 %defattr(-, root, root, -)
 %doc COPYING README lib/vdsm/vdsm.conf.sample
 %if 0%{?with_systemd}
-/lib/systemd/systemd-vdsmd
 %{_unitdir}/vdsmd.service
 %{_unitdir}/supervdsmd.service
 %{_unitdir}/vdsm-restore-net-config.service
@@ -862,6 +861,7 @@
 %{_libexecdir}/%{vdsm_name}/spmprotect.sh
 %{_libexecdir}/%{vdsm_name}/spmstop.sh
 %dir %{_datadir}/%{vdsm_name}/init
+%{_datadir}/%{vdsm_name}/init/daemonAdapter
 %{_datadir}/%{vdsm_name}/init/libvirt_configure.sh
 %{_datadir}/%{vdsm_name}/init/run_task.sh
 %{_datadir}/%{vdsm_name}/init/final_run_final_hooks.sh
diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am
index efc7515..4cc2098 100644
--- a/vdsm/Makefile.am
+++ b/vdsm/Makefile.am
@@ -78,6 +78,7 @@
 	vdsm-restore-net-config.init \
 	vdsm.rwtab \
 	vdsmd.init \
+	vdsmd.service \
 	supervdsmd.init \
 	supervdsmd.service \
 	$(NULL)
@@ -131,7 +132,7 @@
 	vdsm.rwtab.in \
 	vdsmd.8.in \
 	vdsmd.init.in \
-	vdsmd.service \
+	vdsmd.service.in \
 	$(NULL)
 
 all-local: \
diff --git a/vdsm/init/Makefile.am b/vdsm/init/Makefile.am
index bf88cff..879f1a1 100644
--- a/vdsm/init/Makefile.am
+++ b/vdsm/init/Makefile.am
@@ -25,6 +25,7 @@
 
 vdsminitdir = $(vdsmdir)/init
 dist_vdsminit_SCRIPTS = \
+	daemonAdapter \
 	final_run_final_hooks.sh \
 	init_dummybr.sh \
 	init_gencerts.sh \
diff --git a/vdsm/init/daemonAdapter b/vdsm/init/daemonAdapter
new file mode 100755
index 0000000..7e9ccbf
--- /dev/null
+++ b/vdsm/init/daemonAdapter
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+# Copyright 2013 IBM, 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
+#
+
+import argparse
+import os
+import os.path
+import pwd
+import sys
+
+from vdsm.config import config
+from vdsm.constants import P_VDSM
+
+
+def getArgs():
+    parser = argparse.ArgumentParser(description='Start VDSM daemon with'
+                                     'various options')
+    parser.add_argument('-u', '--user', dest='user', default=None,
+                        metavar='user_name', help='Run as user_name')
+    parser.add_argument('-n', '--renice', dest='renice', default=False,
+                        action='store_true',
+                        help='Ajust nice according to configuration file')
+    parser.add_argument('-r', '--respawn-pid-file', dest='respawnPidFile',
+                        default=None, metavar='respawn_pid_file_path',
+                        help='Run with respawn watchdog protection and '
+                             'specify the respawn pid file path')
+    args = parser.parse_args(sys.argv[1:])
+    return args
+
+if __name__ == '__main__':
+
+    args = getArgs()
+    if args.renice:
+        try:
+            os.nice(config.getint('vars', 'vdsm_nice'))
+        except OSError as e:
+            sys.stderr.write("daemon adapter: failed to renice, %s" % e)
+
+    if args.user is not None:
+        userPw = pwd.getpwnam(args.user)
+        os.environ.update({
+            'LOGNAME': userPw.pw_name,
+            'USER': userPw.pw_name,
+            'LNAME': userPw.pw_name,
+            'USERNAME': userPw.pw_name})
+        os.setgid(userPw.pw_gid)
+        os.setuid(userPw.pw_uid)
+
+    cmd = []
+    if args.respawnPidFile:
+        cmd += [os.path.join(P_VDSM, 'respawn'), '--minlifetime', '10',
+                '--daemon', '--masterpid', args.respawnPidFile]
+
+    cmd.append(os.path.join(P_VDSM, 'vdsm'))
+
+    env = os.environ
+    env.update({
+        'LIBVIRT_LOG_FILTERS': config.get('vars',
+                                          'libvirt_env_variable_log_filters'),
+        'LIBVIRT_LOG_OUTPUTS': config.get('vars',
+                                          'libvirt_env_variable_log_outputs'),
+        'LC_ALL': 'C',
+    })
+
+    os.close(0)
+    os.open("/dev/null", os.O_RDONLY)
+    os.close(1)
+    os.open("/dev/null", os.O_WRONLY)
+    os.close(2)
+    os.open("/dev/null", os.O_WRONLY)
+
+    os.execve(cmd[0], cmd, env)
diff --git a/vdsm/sudoers.vdsm.in b/vdsm/sudoers.vdsm.in
index ff9e703..73c959d 100644
--- a/vdsm/sudoers.vdsm.in
+++ b/vdsm/sudoers.vdsm.in
@@ -36,4 +36,5 @@
 
 vdsm  ALL=(ALL) NOPASSWD: VDSM_LIFECYCLE, VDSM_STORAGE
 Defaults:vdsm !requiretty
+Defaults:root !requiretty
 Defaults:vdsm !syslog
diff --git a/vdsm/vdsm b/vdsm/vdsm
index fef86db..2977be3 100755
--- a/vdsm/vdsm
+++ b/vdsm/vdsm
@@ -9,6 +9,7 @@
 #
 
 import os
+import errno
 import sys
 import getopt
 import signal
@@ -145,6 +146,15 @@
 if __name__ == '__main__':
     __assertVdsmUser()
     __assertLogPermission()
-    os.setpgrp()
+    try:
+        os.setpgrp()
+    except OSError as e:
+        if e.errno == errno.EPERM:
+            # Powerful init systems such as systemd can provide us a clean
+            # daemon environment, no need to setpgrp anymore, so just ignore
+            # the exception.
+            pass
+        else:
+            raise
     parse_args()
     run()
diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in
index 2f9ea9a..15166fb 100755
--- a/vdsm/vdsmd.init.in
+++ b/vdsm/vdsmd.init.in
@@ -26,6 +26,7 @@
 VDSM_BIN=@VDSMDIR@/vdsm
 CONF_FILE=@CONFDIR@/vdsm.conf
 GETCONFITEM=@VDSMDIR@/get-conf-item
+prog=vdsm
 PIDFILE=@VDSMRUNDIR@/vdsmd.pid
 RESPAWNPIDFILE=@VDSMRUNDIR@/respawn.pid
 
@@ -68,9 +69,7 @@
     echo $"Starting up vdsm daemon: "
     local vdsm_nice=`$GETCONFITEM $CONF_FILE vars vdsm_nice -5`
 
-    LIBVIRT_LOG_FILTERS=`$GETCONFITEM $CONF_FILE vars libvirt_env_variable_log_filters ""` \
-    LIBVIRT_LOG_OUTPUTS=`$GETCONFITEM $CONF_FILE vars libvirt_env_variable_log_outputs ""` \
-    LC_ALL=C NICELEVEL=$vdsm_nice daemon --user=vdsm @VDSMDIR@/respawn --minlifetime 10 --daemon --masterpid $RESPAWNPIDFILE $VDSM_BIN
+    NICELEVEL=$vdsm_nice daemon --user=vdsm @VDSMDIR@/init/daemonAdapter -r $RESPAWNPIDFILE
     RETVAL=$?
     [ "$RETVAL" -eq 0 ] && log_success_msg $"$prog start" || log_failure_msg $"$prog start"
     [ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/vdsmd
diff --git a/vdsm/vdsmd.service b/vdsm/vdsmd.service
deleted file mode 100644
index 535548f..0000000
--- a/vdsm/vdsmd.service
+++ /dev/null
@@ -1,14 +0,0 @@
-[Unit]
-Description=Virtual Desktop Server Manager
-Requires=multipathd.service libvirtd.service time-sync.target \
-         iscsid.service supervdsmd.service
-Conflicts=libvirt-guests.service ksmtuned.service
-
-[Service]
-Type=forking
-EnvironmentFile=-/etc/sysconfig/vdsm
-ExecStart=/lib/systemd/systemd-vdsmd start
-ExecStop=/lib/systemd/systemd-vdsmd stop
-
-[Install]
-WantedBy=multi-user.target
diff --git a/vdsm/vdsmd.service.in b/vdsm/vdsmd.service.in
new file mode 100644
index 0000000..e325c3d
--- /dev/null
+++ b/vdsm/vdsmd.service.in
@@ -0,0 +1,17 @@
+[Unit]
+Description=Virtual Desktop Server Manager
+Requires=multipathd.service libvirtd.service time-sync.target \
+         iscsid.service supervdsmd.service sanlock.service
+Conflicts=libvirt-guests.service ksmtuned.service
+
+[Service]
+Type=simple
+EnvironmentFile=-/etc/sysconfig/vdsm
+ExecStartPre=@VDSMDIR@/init/run_task.sh pre-start "run_init_hooks gencerts libvirt_reconfigure syslog_available nwfilter dummybr load_needed_modules tune_system mkdirs test_space test_lo test_conflicting_conf"
+ExecStart=@PYTHON@ @VDSMDIR@/init/daemonAdapter -u vdsm -n
+ExecStopPost=@VDSMDIR@/init/run_task.sh post-stop "run_final_hooks"
+KillMode=process
+Restart=always
+
+[Install]
+WantedBy=multi-user.target


-- 
To view, visit http://gerrit.ovirt.org/15578
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id8e514df1ca88500f746242134ddb24c31588046
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>


More information about the vdsm-patches mailing list