github.com/rootless-containers/rootlesskit/v2@v2.3.4/hack/integration-systemd-socket.sh (about) 1 #!/bin/bash 2 3 srcdir=$(realpath $(dirname $0)) 4 source "${srcdir}/common.inc.sh" 5 6 test_with_uuidd_daemon() { 7 uuidd_tmpdir=$(mktemp -d) 8 uuidd_sock="${uuidd_tmpdir}/uuidd.sock" 9 systemd-socket-activate -l "${uuidd_sock}" "$ROOTLESSKIT" uuidd --no-pid --no-fork --socket-activation & 10 pid=$! 11 sleep 2 12 uuidd -d -r -n 1 -s "${uuidd_sock}" || return 1 13 uuidd -d -t -n 1 -s "${uuidd_sock}" || return 1 14 uuidd -d -k -s "${uuidd_sock}" || return 1 15 rm -r "${uuidd_tmpdir}" || return 1 16 wait $pid || return 1 17 } 18 19 test_env_variables() { 20 tmpdir=$(mktemp -d) 21 sock1="${tmpdir}/sock1.sock" 22 sock2="${tmpdir}/sock2.sock" 23 sock3="${tmpdir}/sock3.sock" 24 ## Test 1 socket 25 timeout 30 systemd-socket-activate -l "${sock1}" "$ROOTLESSKIT" "${srcdir}/integration-systemd-socket-check-env.sh" "${tmpdir}/ok1" "${tmpdir}/fail1" 1 & 26 pid=$! 27 sleep 2 28 curl --unix-socket "${sock1}" "http//example.com" >/dev/null 2>&1 || true # just trigger 29 wait $pid 30 if [[ ! -e "${tmpdir}/ok1" ]]; then return 1; fi 31 ## Test 2 sockets 32 timeout 30 systemd-socket-activate -l "${sock1}" -l "${sock2}" "$ROOTLESSKIT" "${srcdir}/integration-systemd-socket-check-env.sh" "${tmpdir}/ok2" "${tmpdir}/fail2" 2 & 33 pid=$! 34 sleep 2 35 curl --unix-socket "${sock1}" "http//example.com" >/dev/null 2>&1 || true 36 wait $pid 37 if [[ ! -e "${tmpdir}/ok2" ]]; then return 1; fi 38 ## Test 3 sockets 39 timeout 30 systemd-socket-activate -l "${sock1}" -l "${sock2}" -l "${sock3}" "$ROOTLESSKIT" "${srcdir}/integration-systemd-socket-check-env.sh" "${tmpdir}/ok3" "${tmpdir}/fail3" 3 & 40 pid=$! 41 sleep 2 42 curl --unix-socket "${sock1}" "http//example.com" >/dev/null 2>&1 || true 43 wait $pid 44 if [[ ! -e "${tmpdir}/ok3" ]]; then return 1; fi 45 46 rm -r "${tmpdir}" 47 } 48 49 INFO "===== Systemd socket activation: uuidd daemon =====" 50 test_with_uuidd_daemon 51 52 INFO "===== Systemd socket activation: LISTEN_* variables check =====" 53 test_env_variables 54 55 INFO "===== PASSING ====="