[libvirt] [PATCH 04/16] This patch adds a -u UNITFILE qualifier to the virt-sandbox-service reload command.

Dan Walsh dwalsh at redhat.com
Tue Apr 2 22:11:20 UTC 2013


The basic idea is to allow administrators or the systemd service to reload units which are running within a container.  If you have one or more units defined
for a container, then just those units will get the reloads, as opposed to
stopping and restarting the container.

Signed-off-by: Dan Walsh <dwalsh at redhat.com>
---
 bin/virt-sandbox-service                    | 30 ++++++++++++++++++++---------
 bin/virt-sandbox-service-bash-completion.sh |  3 ++-
 bin/virt-sandbox-service-reload.pod         |  9 +++++++--
 3 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service
index 478769d..0e38577 100755
--- a/bin/virt-sandbox-service
+++ b/bin/virt-sandbox-service
@@ -164,12 +164,12 @@ After=libvirtd.service
 [Service]
 Type=simple
 ExecStart=/usr/bin/virt-sandbox-service start %(NAME)s
-ExecReload=/usr/bin/virt-sandbox-service reload %(NAME)s
+ExecReload=/usr/bin/virt-sandbox-service reload -u %(RELOAD)s %(NAME)s
 ExecStop=/usr/bin/virt-sandbox-service stop %(NAME)s
 
 [Install]
 WantedBy=%(TARGET)s
-""" % { 'NAME':name, 'FOLLOW':self.__follow_units(), 'TARGET':self.__target() }
+""" % { 'NAME':name, 'FOLLOW':self.__follow_units(), 'TARGET':self.__target(), 'RELOAD': " -u ".join(map(lambda x: x[0], self.unit_file_list)) }
         fd = open(self.unitfile, "w")
         fd.write(unit)
         fd.close()
@@ -649,11 +649,17 @@ PrivateNetwork=false
                 pass
             raise e
 
-    def reload(self):
-        # Crude way of doing this.
-        self.stop()
-        self.start()
-        # self.execute("systemctl reload %s.service" % self.get_name())
+    def reload(self, unitfiles):
+        #
+        # Reload A ServiceContainer
+        #
+        class Args:
+            command = []
+            nolabel = None
+            name = self.name
+        args = Args()
+        args.command = [ "systemctl", "reload" ] + map(lambda x: x[0], unitfiles)
+        execute(args)
 
     def __connect(self):
         if not self.conn:
@@ -800,8 +806,11 @@ def sandbox_list(args):
 
 
 def sandbox_reload(args):
-    container = Container(args.name, args.uri)
-    container.reload()
+    config = read_config(args.name)
+    if isinstance(config, gi.repository.LibvirtSandbox.ConfigInteractive):
+        raise ValueError(_("Interactive Containers do not support reload"))
+    container = ServiceContainer(uri = args.uri, config = config)
+    container.reload(args.unitfiles)
 
 def start(args):
     os.execl("/usr/libexec/virt-sandbox-service-util", "virt-sandbox-service-util","-s", args.name)
@@ -989,6 +998,9 @@ def gen_stop_args(subparser):
 def gen_reload_args(subparser):
     parser = subparser.add_parser("reload",
                                    help=_("Reload a running sandbox container"))
+    parser.add_argument("-u", "--unitfile", required=True,
+                        action=CheckUnit, dest="unitfiles",
+                        help=_("Systemd Unit file to reload within the sandbox container"))
     requires_name(parser)
     parser.set_defaults(func=sandbox_reload)
 
diff --git a/bin/virt-sandbox-service-bash-completion.sh b/bin/virt-sandbox-service-bash-completion.sh
index c855fd2..ce14a7d 100755
--- a/bin/virt-sandbox-service-bash-completion.sh
+++ b/bin/virt-sandbox-service-bash-completion.sh
@@ -57,6 +57,7 @@ _virt_sandbox_service () {
         [ALL]='-h --help'
         [CREATE]='-u --unitfile -p --path -t --type -l --level -d --dynamic -n --clone -i --image -s --size'
         [LIST]='-r --running'
+        [RELOAD]='-u --unitfile'
         [EXECUTE]='-N --noseclabel'
     )
 
@@ -88,7 +89,7 @@ _virt_sandbox_service () {
         COMPREPLY=( $(compgen -W "${OPTS[ALL]} $( __get_all_running_containers ) " -- "$cur") )
         return 0
     elif test "$verb" == "reload" ; then
-        COMPREPLY=( $(compgen -W "${OPTS[ALL]} $( __get_all_running_containers ) " -- "$cur") )
+        COMPREPLY=( $(compgen -W "${OPTS[ALL]} ${OPTS[RELOAD]} $( __get_all_running_containers ) " -- "$cur") )
         return 0
     elif test "$verb" == "connect" ; then
         COMPREPLY=( $(compgen -W "${OPTS[ALL]} $( __get_all_running_containers ) " -- "$cur") )
diff --git a/bin/virt-sandbox-service-reload.pod b/bin/virt-sandbox-service-reload.pod
index d26af82..b4919be 100644
--- a/bin/virt-sandbox-service-reload.pod
+++ b/bin/virt-sandbox-service-reload.pod
@@ -4,7 +4,7 @@ virt-sandbox-service reload - Reload a security container
 
 =head1 SYNOPSIS
 
-  virt-sandbox-service [-c URI] reload [-h] NAME
+  virt-sandbox-service [-c URI] reload [-h] -u UNIT_FILE NAME
 
 =head1 DESCRIPTION
 
@@ -26,6 +26,11 @@ Display help message
 
 =item B<-c> URI, B<--connect URI>
 
+=item B<-u UNIT_FILE>, B<--unitfile UNIT_FILE>
+
+Name of the systemd unit file to reload within the container. Can be repeated
+if multiple unit files need to be reloaded within the sandbox.
+
 The connection URI for the hypervisor (only LXC or QEMU are
 supported currently).
 
@@ -35,7 +40,7 @@ supported currently).
 
 Reload the httpd1 container
 
- # virt-sandbox-service reload httpd1
+ # virt-sandbox-service reload -u httpd.service httpd1
 
 =head1 SEE ALSO
 
-- 
1.8.2




More information about the libvir-list mailing list