forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunit
More file actions
executable file
·156 lines (136 loc) · 3.52 KB
/
runit
File metadata and controls
executable file
·156 lines (136 loc) · 3.52 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
set -e
nodeprefix="m"
script_args=()
while [[ $1 = -* ]]; do
if [[ "$1" = "-s" ]] || [[ "$1" = "--source" ]]; then
shift
src=$1
elif [[ "$1" = "-p" ]] || [[ "$1" = "--nodeprefix" ]]; then
shift
nodeprefix=$1
elif [[ "$1" = "-n" ]] || [[ "$1" = "--numnodes" ]]; then
shift
numnodes=$1
elif [[ "$1" = "-c" ]] || [[ "$1" = "--commands" ]]; then
shift
commands=$1
elif [[ "$1" = "-f" ]] || [[ "$1" = "--file" ]]; then
shift
script=$1
elif [[ "$1" = "-a" ]] || [[ "$1" = "--file-arg" ]]; then
shift
script_args+=("$1")
fi
shift
done
if [[ "$src" = "" ]] || [[ "$numnodes" = "" ]]; then
echo "Usage: $0 -s source_directory -p nodeprefix -n numnodes [-c commands] [-f file]" >&2
exit 1
fi
prefix="$(git --git-dir "$src/.git" rev-parse --short HEAD)"
if [[ "$prefix" = "" ]]; then
echo 'Could not get the revision.' >&2
exit 1
fi
export COMPOSE_PROJECT_NAME=$prefix
rm -fr common
mkdir common
for node in $(seq 1 $numnodes); do
cluster="$cluster ${nodeprefix}${node}"
containers="$containers ${nodeprefix}$node"
done
if [[ -f /proc/sys/kernel/core_pattern ]]; then
# If core pattern is an absolute path, prepare to mount
abspath=$(grep '^/' /proc/sys/kernel/core_pattern) || true
if [[ "$abspath" != "" ]]; then
coredir=$(dirname $abspath)
mkdir -p common/c1/cores
for node in $(seq 1 $numnodes); do
mkdir -p common/${nodeprefix}${node}/cores
done
fi
fi
if [[ "$script" != "" ]]; then
cp $script common/user_script
chmod +x common/user_script
fi
if ((${#script_args[@]} > 0)); then
printf '%s ' "${script_args[@]}" > common/user_script_args
fi
docker build -t comdb2test:$prefix -f $src/tests/docker/Dockerfile.install $src
echo $cluster >common/cluster
ssh-keygen -N "" -f common/id_rsa
compose=docker-compose.yml
cat > $compose <<EOF
version: '2'
networks:
primary:
n3:
n4:
services:
client:
container_name: c1
hostname: c1
labels:
what: "testclient"
networks:
- primary
build:
context: $src
dockerfile: tests/docker/Dockerfile.db
args:
- REVISION=$prefix
volumes:
- ./common:/common
- ./common/c1:/dedicated
EOF
[[ "$coredir" != "" ]] && { cat >> $compose <<EOF
- ./common/c1/cores:$coredir
EOF
}
cat >> $compose <<EOF
command: /client $commands
cap_add:
- SYS_PTRACE
EOF
for node in $containers; do
cat >> $compose <<EOF
$node:
container_name: $node
hostname: $node
labels:
what: "testserver"
networks:
primary:
n3:
aliases:
- $node-n3
n4:
aliases:
- $node-n4
build:
context: $src
dockerfile: tests/docker/Dockerfile.db
args:
- REVISION=$prefix
volumes:
- ./common:/common
- ./common/$node:/dedicated
EOF
[[ "$coredir" != "" ]] && { cat >> $compose <<EOF
- ./common/$node/cores:$coredir
EOF
}
cat >> $compose <<EOF
command: /server
cap_add:
- SYS_PTRACE
EOF
done
# Make sure that root can access common/ under SELinux
chmod 777 -R common
docker-compose build
docker-compose up --abort-on-container-exit
docker-compose down --rmi all --volumes
docker-compose rm -f