]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-build.git/commitdiff
scripts: Refactor restart_libvirt_services 2529/head
authorDavid Galloway <david.galloway@ibm.com>
Wed, 14 Jan 2026 20:36:11 +0000 (15:36 -0500)
committerDavid Galloway <david.galloway@ibm.com>
Wed, 14 Jan 2026 20:37:09 +0000 (15:37 -0500)
Signed-off-by: David Galloway <david.galloway@ibm.com>
scripts/build_utils.sh

index 91bd3c9bf615e23f563a424b3cc4e7337c413a7f..eed84e97d5b05d0efaecb58881c626b8ef5fb336 100755 (executable)
@@ -1128,13 +1128,27 @@ clear_libvirt_networks() {
 }
 
 restart_libvirt_services() {
-    # restart libvirt services
-    if test -f /etc/redhat-release; then
-        sudo service libvirtd restart
+    if command -v systemctl >/dev/null 2>&1; then
+        # systemd systems
+        if systemctl list-unit-files | grep -q '^libvirt-bin\.service'; then
+            sudo systemctl restart libvirt-bin 2>/dev/null || sudo systemctl restart libvirtd
+        else
+            sudo systemctl restart libvirtd
+        fi
+
+        # Restart guests service if it exists
+        systemctl list-unit-files | grep -q '^libvirt-guests\.service' && \
+            sudo systemctl restart libvirt-guests
     else
-        sudo service libvirt-bin restart
+        # SysVinit systems
+        if sudo service libvirt-bin restart 2>/dev/null; then
+            :
+        else
+            sudo service libvirtd restart
+        fi
+
+        sudo service libvirt-guests restart 2>/dev/null || true
     fi
-    sudo service libvirt-guests restart
 }
 
 # Function to update vagrant boxes on static libvirt Jenkins builders used for ceph-ansible and ceph-docker testing