Browse code

systemd: Always create the systemd unit files

Commit 5edae54 introduced the usage of systemd in Devstack. This allowed
the transition away from 'screen'. Systemd needs "user unit files" to
describe the services. Currently, those unit files get only created when
an openstack service (n-cpu, c-sch, g-api, ...) is in the list of enabled
services (`ENABLED_SERVICES`). This means, when Devstack is fully stacked,
there is no way to start the systemd unit of an openstack service which
is *not* in that list.

This commit changes that behavior, and creates the systemd unit files
independently of the list ENABLED_SERVICES. This means, when Devstack
is fully stacked, I can start a systemd unit of an openstack service which
wasn't in the ENABLED_SERVICES list. This allows more flexible lifecycle
management of openstack services in the gate, which is useful for tests
which test components which are not in the "default configuration" (e.g.
the "nova-serialproxy" service).

The `clean.sh` script purges all traces of systemd user unit files created
by devstack.

Change-Id: I0f7e1ee8723f4de47cbc56b727182f90a2b32bfb

Markus Zoeller authored on 2017/05/31 18:21:22
Showing 2 changed files
... ...
@@ -125,6 +125,13 @@ if [[ -n "$SCREEN_LOGDIR" ]] && [[ -d "$SCREEN_LOGDIR" ]]; then
125 125
     sudo rm -rf $SCREEN_LOGDIR
126 126
 fi
127 127
 
128
+# Clean out the sytemd user unit files if systemd was used.
129
+if [[ "$USE_SYSTEMD" = "True" ]]; then
130
+    sudo find $SYSTEMD_DIR -type f -name '*devstack@*service' -delete
131
+    # Make systemd aware of the deletion.
132
+    $SYSTEMCTL daemon-reload
133
+fi
134
+
128 135
 # Clean up venvs
129 136
 DIRS_TO_CLEAN="$WHEELHOUSE ${PROJECT_VENV[@]} .config/openstack"
130 137
 rm -rf $DIRS_TO_CLEAN
... ...
@@ -1508,8 +1508,13 @@ EOF
1508 1508
 
1509 1509
 }
1510 1510
 
1511
-# Helper function to build a basic unit file and run it under systemd.
1512
-function _run_under_systemd {
1511
+# Defines a systemd service which can be enabled and started later on.
1512
+# arg1: The openstack service name ('n-cpu', 'c-sch', ...).
1513
+# arg2: The command to start (e.g. path to service binary + config files).
1514
+# arg3: The group which owns the process.
1515
+# arg4: The user which owns the process.
1516
+# Returns: The systemd service name which got defined.
1517
+function _define_systemd_service {
1513 1518
     local service=$1
1514 1519
     local command="$2"
1515 1520
     local cmd=$command
... ...
@@ -1524,9 +1529,7 @@ function _run_under_systemd {
1524 1524
     else
1525 1525
         write_user_unit_file $systemd_service "$cmd" "$group" "$user"
1526 1526
     fi
1527
-
1528
-    $SYSTEMCTL enable $systemd_service
1529
-    $SYSTEMCTL start $systemd_service
1527
+    echo $systemd_service
1530 1528
 }
1531 1529
 
1532 1530
 # Helper to remove the ``*.failure`` files under ``$SERVICE_DIR/$SCREEN_NAME``.
... ...
@@ -1567,11 +1570,19 @@ function run_process {
1567 1567
     local user=$4
1568 1568
 
1569 1569
     local name=$service
1570
+    local systemd_service
1570 1571
 
1571 1572
     time_start "run_process"
1573
+    # Note we deliberately make all service files, even if the service
1574
+    # isn't enabled, so it can be enabled by a dev manually on command
1575
+    # line.
1576
+    if [[ "$USE_SYSTEMD" = "True" ]]; then
1577
+        systemd_service=$(_define_systemd_service "$name" "$command" "$group" "$user")
1578
+    fi
1572 1579
     if is_service_enabled $service; then
1573 1580
         if [[ "$USE_SYSTEMD" = "True" ]]; then
1574
-            _run_under_systemd "$name" "$command" "$group" "$user"
1581
+            $SYSTEMCTL enable $systemd_service
1582
+            $SYSTEMCTL start $systemd_service
1575 1583
         elif [[ "$USE_SCREEN" = "True" ]]; then
1576 1584
             if [[ "$user" == "root" ]]; then
1577 1585
                 command="sudo $command"