-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfunctions.sh
More file actions
executable file
·153 lines (118 loc) · 4.74 KB
/
functions.sh
File metadata and controls
executable file
·153 lines (118 loc) · 4.74 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
#!/bin/bash
create_stack_user(){
#add stack user and make him be sudoer
# 9 code = user already exist
adduser stack -d $1 || [ $? -eq 9 ]
if ! grep -q "stack ALL=(ALL) NOPASSWD: ALL" "/etc/sudoers"; then
echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "Defaults:stack !requiretty" >> /etc/sudoers
else
usermod -m -d $1 stack || echo "call \" rm -rf $1\""
fi
}
onboot_preparations () {
# Enable connection tracking for CT0
# There was first beta where we had two files controlling this
# vz.conf and parallels.conf. Let's modify both
MODEPROBE_VZ="options nf_conntrack ip_conntrack_disable_ve0"
NEED_REBOOT=false
if ! grep -q "$MODEPROBE_VZ=0" /etc/modprobe.d/parallels.conf ||
! grep -q "$MODEPROBE_VZ=0" /etc/modprobe.d/vz.conf; then
NEED_REBOOT=true
fi
if grep -q "$MODEPROBE_VZ" /etc/modprobe.d/parallels.conf; then
sed -i s/"$MODEPROBE_VZ=.*"/"$MODEPROBE_VZ=0"/ /etc/modprobe.d/parallels.conf
else
echo -ne "$MODEPROBE_VZ=0" >> /etc/modprobe.d/parallels.conf
fi
if grep -q "$MODEPROBE_VZ" /etc/modprobe.d/vz.conf; then
sed -i s/"$MODEPROBE_VZ=.*"/"$MODEPROBE_VZ=0"/ /etc/modprobe.d/vz.conf
else
echo -ne "$MODEPROBE_VZ=0" >> /etc/modprobe.d/vz.conf
fi
# devstack requires set hostname
[ -n "$(hostname -f)" ] || hostname localhost
#sometimes this file prevents from starting mysql
service mysqld stop || true
[[ ! -f /var/lib/mysql/mysql.sock ]] || rm -f /var/lib/mysql/mysql.sock
# we kill prl_naptd because it conflicts with used by devstack dnsmasq
# we kill httpd because in some circumstances it does't restart well
# all other are openstack services that shouldn't be running at the moment we start stack.sh
for proc in prl_naptd httpd qpid rabbit mysqld horizon keystone cinder glance nova ceilometer neutron swift trove heat;
do
kill_proc $proc;
done;
if [[ -n "$1" ]]; then
eval $1=$NEED_REBOOT
fi
}
function apply_cherry_pick {
local git_remote=$1
local dest_dir=$2
local cherry_pick_refs=$3
pushd .
cd $dest_dir
# modify current source
for ref in ${cherry_pick_refs//,/ }; do
echo "Applying $ref from $git_remote ..."
set -e
git fetch $git_remote $ref
git cherry-pick FETCH_HEAD
set +e
echo "Applying $ref from $git_remote ... done"
done
popd
}
function clone_and_fix_openstack_project {
local project=$1
local changes=$2
if [[ ! -d ~stack/$project ]]; then
clone_openstack_project $project
fix_openstack_project $project $changes
fi
}
function clone_openstack_project {
local project=$1
local repo=https://review.openstack.org/openstack/$project
if [[ ! -d ~stack/$project ]]; then
su stack -c "source ~stack/devstack/functions && \
git_clone $repo ~stack/$project master"
fi
}
function fix_openstack_project {
local project=$1
local changes=$2
local repo=${3:-https://review.openstack.org/openstack/$project}
su stack -c "source functions.sh && \
apply_cherry_pick $repo ~stack/$project $changes"
}
function kill_proc() {
local name=$1
id_list=`ps -ef | grep $name | grep -v grep | awk '{print $2}'`
for proc_id in $id_list
do
proc_info=`sudo ps -ef | grep ${proc_id}`
if [[ -n $proc_info ]]; then
kill $proc_id 2 > /dev/null
else
break 2
fi
done
}
fixup_configs_for_libvirt(){
# fix libvirtd.conf
sed -i s/"#log_level = 3"/"log_level = 2"/ /etc/libvirt/libvirtd.conf
sed -i s/"#unix_sock_group = \"libvirt\""/"unix_sock_group = \"stack\""/ /etc/libvirt/libvirtd.conf
sed -i s/"#unix_sock_ro_perms = \"0777\""/"unix_sock_ro_perms = \"0777\""/ /etc/libvirt/libvirtd.conf
sed -i s/"#unix_sock_rw_perms = \"0770\""/"unix_sock_rw_perms = \"0770\""/ /etc/libvirt/libvirtd.conf
sed -i s/"#unix_sock_dir = \"\/var\/run\/libvirt\""/"unix_sock_dir = \"\/var\/run\/libvirt\""/ /etc/libvirt/libvirtd.conf
sed -i s/"#auth_unix_ro = \"none\""/"auth_unix_ro = \"none\""/ /etc/libvirt/libvirtd.conf
sed -i s/"#auth_unix_rw = \"none\""/"auth_unix_rw = \"none\""/ /etc/libvirt/libvirtd.conf
}
function cleanup_compute(){
# cleanup existing OpenStack instances
# stop running
prlctl list | grep instance- | awk '{ system("prlctl stop " $1 " --kill")} '
# destroy destroy them
prlctl list -a | grep instance- | awk '{ system("prlctl destroy " $1)} '
}