-
Notifications
You must be signed in to change notification settings - Fork 1
/
runc_sd_notify.sh
executable file
·70 lines (60 loc) · 2.08 KB
/
runc_sd_notify.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# This script will test whether sd_notify (systemd notify) is
# working successfully with runc containers.
# Requires: docker daemon (running), docker client, systemctl.
# Script must be run as a root user.
# Author: Shishir Mahajan <shishir dot mahajan at redhat dot com>
main(){
if [[ "$(id -u)" -ne "0" ]]; then
echo "runc_sd_notify requires root access. Please try again."
exit 0
fi
init=$(ps -q 1 -o comm=)
if [ "$init" != "systemd" ];then
echo "Systemd init system is required to run runc_sd_notify. Skipping test."
exit 0
fi
if ! systemctl is-active docker >/dev/null; then
echo "Docker daemon is not running. Skipping test."
exit 0
fi
trap cleanup EXIT
setup
# Let's not build the image `fed_runc` everytime we run this tool. Why??
# (1) docker build process is time consuming. disk is cheap.
# (2) `dnf install` fails sporadically due to fedora repo/mirror not available sometimes.
# If the mirror is not available it blows up the entire test.
# Error message: Failed to synchronize cache for repo 'fedora'.
# Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1257034
imageName=$(docker images --format "{{.Repository}}"|grep fed_runc)
if [ "$imageName" != "fed_runc" ];then
echo "Building docker image fed_runc"
docker build -t fed_runc .|| exit 1
else
echo "docker image fed_runc already exists, skipping docker build"
fi
set -e
docker create --name fed_runc_container fed_runc echo
docker export fed_runc_container|tar -C /tmp/fed-runc/rootfs -xf -
systemctl daemon-reload
systemctl start runc-notify
echo "runc_sd_notify completed successfully"
}
cleanup(){
systemctl stop runc-notify
rm -rf /tmp/fed-runc
rm /etc/systemd/system/runc-notify.service 2>/dev/null
systemctl daemon-reload
rm /run/mycontainerid 2>/dev/null
docker rm fed_runc_container
}
setup(){
if [ -f /etc/systemd/system/runc-notify.service ];then
echo "/etc/systemd/system/runc-notify.service already exists. Skipping test."
exit 0
fi
install -m 644 systemd/runc-notify.service /etc/systemd/system
mkdir -p /tmp/fed-runc/rootfs
cp config.json /tmp/fed-runc
}
main "$@"