github.com/containers/podman/v5@v5.1.0-rc1/test/system/helpers.systemd.bash (about) 1 # -*- bash -*- 2 # 3 # BATS helpers for systemd-related functionality 4 # 5 6 # podman initializes this if unset, but systemctl doesn't 7 if [ -z "$XDG_RUNTIME_DIR" ]; then 8 if is_rootless; then 9 export XDG_RUNTIME_DIR=/run/user/$(id -u) 10 fi 11 fi 12 13 # For tests which write systemd unit files 14 UNIT_DIR="/run/systemd/system" 15 _DASHUSER= 16 if is_rootless; then 17 UNIT_DIR="${XDG_RUNTIME_DIR}/systemd/user" 18 # Why isn't systemd smart enough to figure this out on its own? 19 _DASHUSER="--user" 20 fi 21 22 mkdir -p $UNIT_DIR 23 24 systemctl() { 25 timeout --foreground -v --kill=10 $PODMAN_TIMEOUT systemctl $_DASHUSER "$@" 26 } 27 28 journalctl() { 29 timeout --foreground -v --kill=10 $PODMAN_TIMEOUT journalctl $_DASHUSER "$@" 30 } 31 32 systemd-run() { 33 timeout --foreground -v --kill=10 $PODMAN_TIMEOUT systemd-run $_DASHUSER "$@"; 34 } 35 36 # "systemctl start" is special: when it fails, it doesn't give any useful info. 37 # This helper fixes that. 38 systemctl_start() { 39 # Arg processing. First arg might be "--wait"... 40 local wait= 41 if [[ "$1" = "--wait" ]]; then 42 wait="$1" 43 shift 44 fi 45 # ...but beyond that, only one arg is allowed 46 local unit="$1" 47 shift 48 assert "$*" = "" "systemctl_start invoked with spurious args" 49 50 echo "$_LOG_PROMPT systemctl $wait start $unit" 51 run systemctl $wait start "$unit" 52 echo "$output" 53 if [[ $status -eq 0 ]]; then 54 return 55 fi 56 57 # Failed. This is our value added. 58 echo 59 echo "***** systemctl start $unit -- FAILED!" 60 echo 61 echo "$_LOG_PROMPT systemctl status $unit" 62 run systemctl status "$unit" 63 echo "$output" 64 echo 65 echo "$_LOG_PROMPT journalctl -xeu $unit" 66 run journalctl -xeu "$unit" 67 echo "$output" 68 false 69 } 70 71 install_kube_template() { 72 # If running from a podman source directory, build and use the source 73 # version of the play-kube-@ unit file 74 unit_name="podman-kube@.service" 75 unit_file="contrib/systemd/system/${unit_name}" 76 if [[ -e ${unit_file}.in ]]; then 77 echo "# [Building & using $unit_name from source]" >&3 78 # Force regenerating unit file (existing one may have /usr/bin path) 79 rm -f $unit_file 80 BINDIR=$(dirname $PODMAN) make $unit_file 81 cp $unit_file $UNIT_DIR/$unit_name 82 fi 83 } 84 85 quadlet_to_service_name() { 86 local filename=$(basename -- "$1") 87 local extension="${filename##*.}" 88 local filename="${filename%.*}" 89 local suffix="" 90 91 if [ "$extension" == "volume" ]; then 92 suffix="-volume" 93 elif [ "$extension" == "network" ]; then 94 suffix="-network" 95 elif [ "$extension" == "image" ]; then 96 suffix="-image" 97 elif [ "$extension" == "pod" ]; then 98 suffix="-pod" 99 fi 100 101 echo "$filename$suffix.service" 102 }