-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.sh
172 lines (147 loc) · 4.33 KB
/
functions.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
docker_services="etcd docker"
kubernetes_services="kube-proxy kubelet kube-scheduler kube-controller-manager kube-apiserver $docker_services"
providers="docker"
tests="hello_apache.sh"
function parse_opts {
local OPTIND opt p
while getopts "p:t:" opt; do
case $opt in
p)
providers=`echo $OPTARG | tr ',' ' '`
;;
t)
tests=`echo $OPTARG | tr ',' ' '`
;;
esac
done
shift $((OPTIND - 1))
}
function configure() {
local prov=$1
if [ "$prov" = "docker" ]; then
:
elif [ "$prov" = "kubernetes" ]; then
key_dir="/etc/pki/kube-apiserver"
key_file="$key_dir/serviceaccount.key"
mkdir -p $key_dir
/bin/openssl genrsa -out $key_file 2048
sed -i -e "s%KUBE_API_ARGS=\".*\"%KUBE_API_ARGS=\"--service_account_key_file=$key_file\"%" /etc/kubernetes/apiserver
sed -i -e "s%KUBE_CONTROLLER_MANAGER_ARGS=\".*\"%KUBE_CONTROLLER_MANAGER_ARGS=\"--service_account_private_key_file=$key_file\"%" /etc/kubernetes/controller-manager
fix_kubernetes_issue_29
else
echo "Unknown provider '$prov'"
exit 1
fi
}
function get_services() {
local prov=$1
if [ "$prov" = "docker" ]; then
echo "$docker_services"
elif [ "$prov" = "kubernetes" ]; then
echo "$kubernetes_services"
else
echo "Unknown provider '$prov'"
exit 1
fi
}
function startup() {
local prov=$1
shutdown $prov
start_services $(get_services $prov)
}
function cleanup() {
local prov=$1
if [ "$prov" = "docker" ]; then
if [ `docker ps -aq | wc -l` -gt 0 ]; then
docker rm $(docker ps -aq)
fi
if [ `docker images -aq | wc -l` -gt 0 ]; then
docker rmi $(docker images -aq)
fi
elif [ "$prov" = "kubernetes" ]; then
kubectl delete rc --all
fi
rm -rf .workdir Dockerfile Nulecule answers.conf artifacts
}
function shutdown() {
local prov=$1
cleanup $prov
stop_services $(get_services $prov)
}
function start_services() {
local services=$*
rtn_code=0
for s in $services; do
service $s start
if [ $? -gt $rtn_code ]; then
rtn_code=$?
fi
done
sleep 5
return $rtn_code
}
function stop_services() {
local services=$*
for s in `echo $services | awk '{ for (i=NF; i>0; --i) printf("%s%s", $i, (i>1?OFS:ORS))}'`; do
service $s stop
done
return 0
}
function fix_kubernetes_issue_29 {
# Fixing issue #29
cat << EOF > /etc/systemd/system/kube-apiserver.service
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
[Service]
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/apiserver
User=kube
ExecStart=/usr/bin/kube-apiserver \\
\$KUBE_LOGTOSTDERR \\
\$KUBE_LOG_LEVEL \\
\$KUBE_ETCD_SERVERS \\
\$KUBE_API_ADDRESS \\
\$KUBE_API_PORT \\
\$KUBELET_PORT \\
\$KUBE_ALLOW_PRIV \\
\$KUBE_SERVICE_ADDRESSES \\
\$KUBE_ADMISSION_CONTROL \\
\$KUBE_API_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
}
parse_opts $*
function install_packages() {
echo 'Yum updating the host'
yum -y -d0 upgrade
echo 'Installing atomic'
yum -y -d 1 install atomic kubernetes etcd flannel mariadb redis
rpm -qa | egrep -q '^redis'
if [ $? -ne 0 ]; then
back=`pwd`
echo 'Installing redis'
mkdir /tmp/redis.$$
cd /tmp/redis.$$
yum -y -d 1 install wget
wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/e/
rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-*.rpm
yum -y -d 1 install redis
cd $back
fi
echo 'writing out atomicapp executable'
cat <<'EOF' > /usr/local/bin/atomicapp
#!/bin/bash
docker run -it --rm --privileged -v $(pwd):/atomicapp -v /run:/run -v /:/host --net=host --name atomicapp projectatomic/atomicapp:dev $@
EOF
chmod 755 /usr/local/bin/atomicapp
echo 'Patching atomic stop.'
yum -y -d 1 install patch
patch -N -p 0 -u /usr/lib/python2.7/site-packages/Atomic/atomic.py < 2748df6.patch
}