You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.2 KiB
Bash
66 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
# Static contract checks for the Go Agent and PHP panel service units.
|
|
# This test never invokes systemctl, starts a service, contacts a host, or
|
|
# changes network state. Run it from the repository checkout:
|
|
# bash deploy/test_go_agent_units.sh
|
|
set -eu
|
|
|
|
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
DEPLOY=$ROOT/deploy
|
|
|
|
fail() {
|
|
echo "go-agent unit contract: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
has() {
|
|
grep -Fq -- "$2" "$1" || fail "$1 is missing: $2"
|
|
}
|
|
|
|
not_has() {
|
|
if grep -Fq -- "$2" "$1"; then
|
|
fail "$1 must not contain: $2"
|
|
fi
|
|
}
|
|
|
|
agent_unit=$DEPLOY/virt-cloud-agent.service
|
|
agent_example=$DEPLOY/virt-cloud-agent.service.example
|
|
[ -f "$agent_unit" ] || fail "missing canonical Agent unit"
|
|
[ -f "$agent_example" ] || fail "missing Agent unit template"
|
|
|
|
for unit in "$agent_unit" "$agent_example"; do
|
|
has "$unit" 'Type=exec'
|
|
has "$unit" 'EnvironmentFile=-/etc/virt-cloud-agent/agent.env'
|
|
has "$unit" 'ExecStart=/usr/local/bin/virt-cloud-agent'
|
|
has "$unit" 'UMask=0077'
|
|
has "$unit" 'ProtectSystem=strict'
|
|
has "$unit" 'ReadWritePaths=/var/lib/virt-cloud-agent'
|
|
not_has "$unit" 'ExecStart=/usr/bin/python'
|
|
not_has "$unit" 'ExecStart=python'
|
|
not_has "$unit" 'ExecStart=/usr/bin/ssh'
|
|
done
|
|
|
|
# PHP workers are panel-side and may serve many remote Agents. They must not
|
|
# be ordered after or require either the retired Python Engine or a local Agent.
|
|
for unit in \
|
|
"$DEPLOY/virt-cloud-worker.service" \
|
|
"$DEPLOY/virt-cloud-lifecycle.service" \
|
|
"$DEPLOY/virt-cloud-policy-worker@.service"; do
|
|
has "$unit" 'After=network-online.target'
|
|
not_has "$unit" 'virt-cloud-engine.service'
|
|
not_has "$unit" 'virt-cloud-agent.service'
|
|
not_has "$unit" 'ExecStart=/usr/bin/python'
|
|
done
|
|
|
|
# Verify syntax when systemd tooling is installed, but keep this contract
|
|
# usable on macOS/development machines where systemd is not present.
|
|
if command -v systemd-analyze >/dev/null 2>&1; then
|
|
systemd-analyze verify \
|
|
"$agent_unit" \
|
|
"$DEPLOY/virt-cloud-worker.service" \
|
|
"$DEPLOY/virt-cloud-lifecycle.service" \
|
|
"$DEPLOY/virt-cloud-policy-worker@.service"
|
|
fi
|
|
|
|
echo 'go-agent unit contract: ok'
|