Browse code

Make devstack fail early for common systemd pitfalls

There are a couple of issues that have ended up being hit by devstack
plugin authors which we can detect and error in a much nicer way
instead of them having a cryptic systemd failure.

Change-Id: I45e4ac363aeefb4503015f9e1b57c58f79b58f40

Sean Dague authored on 2017/05/05 02:08:25
Showing 1 changed files
... ...
@@ -1480,10 +1480,41 @@ function write_uwsgi_user_unit_file {
1480 1480
     $SYSTEMCTL daemon-reload
1481 1481
 }
1482 1482
 
1483
+function _common_systemd_pitfalls {
1484
+    local cmd=$1
1485
+    # do some sanity checks on $cmd to see things we don't expect to work
1486
+
1487
+    if [[ "$cmd" =~ "sudo" ]]; then
1488
+        local msg=<<EOF
1489
+You are trying to use run_process with sudo, this is not going to work under systemd.
1490
+
1491
+If you need to run a service as a user other than $STACK_USER call it with:
1492
+
1493
+   run_process \$name \$cmd \$group \$user
1494
+EOF
1495
+        die $LINENO $msg
1496
+    fi
1497
+
1498
+    if [[ ! "$cmd" =~ ^/ ]]; then
1499
+        local msg=<<EOF
1500
+The cmd="$cmd" does not start with an absolute path. It will fail to
1501
+start under systemd.
1502
+
1503
+Please update your run_process stanza to have an absolute path.
1504
+EOF
1505
+        die $LINENO $msg
1506
+    fi
1507
+
1508
+}
1509
+
1510
+# Helper function to build a basic unit file and run it under systemd.
1483 1511
 function _run_under_systemd {
1484 1512
     local service=$1
1485 1513
     local command="$2"
1486 1514
     local cmd=$command
1515
+    # sanity check the command
1516
+    _common_systemd_pitfalls "$cmd"
1517
+
1487 1518
     local systemd_service="devstack@$service.service"
1488 1519
     local group=$3
1489 1520
     local user=${4:-$STACK_USER}
... ...
@@ -1527,7 +1558,7 @@ function is_running {
1527 1527
 # If an optional group is provided sg will be used to run the
1528 1528
 # command as that group.
1529 1529
 # Uses globals ``USE_SCREEN``
1530
-# run_process service "command-line" [group]
1530
+# run_process service "command-line" [group] [user]
1531 1531
 function run_process {
1532 1532
     local service=$1
1533 1533
     local command="$2"