-
Notifications
You must be signed in to change notification settings - Fork 35
/
INSTALL
executable file
·189 lines (159 loc) · 4.84 KB
/
INSTALL
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
set -e; sudo -v || exit
check_install () {
for prog in $@
do
if ! hash $prog 2>/dev/null; then
echo "Please install $prog."
exit 1
fi
done
}
add_service () {
# adds an init script service to chkconfig or update-rc.d
if [ -f /etc/debian_version ]; then
sudo update-rc.d $1 defaults
elif [ -f /etc/redhat-release ]; then
sudo chkconfig --add $1
sudo chkconfig --level 2345 $1 on
else
echo "Error! Couldn't determine Linux distribution!"
echo "no /etc/debian_version or /etc/redhat-release file"
exit 1
fi
}
check_install git virtualenv gcc nginx ntpd
if [ -f /etc/debian_version ]; then
supervisord_init=supervisord_debian
nginx_init=nginx_debian
# ntpd should already be running
elif [ -f /etc/redhat-release ]; then
supervisord_init=supervisord_redhat
nginx_init=nginx_redhat
sudo chkconfig ntpd on
else
echo "Error! Couldn't determine Linux distribution!"
echo "no /etc/debian_version or /etc/redhat-release file"
exit 1
fi
redis_conf=redis.conf;
supervisord_conf=supervisord.conf;
nginx_conf=nginx.conf;
# create conf file for minard
temp=$(mktemp)
echo "SUPERVISOR = True" > $temp
sudo install -m 644 $temp /etc/minard.conf
if [ ! -f /usr/local/bin/redis-server ]; then
# install redis to /usr/local
printf "Installing redis..."
cd /usr/local
sudo curl -O -s http://download.redis.io/redis-stable.tar.gz
sudo tar -xzf redis-stable.tar.gz
cd redis-stable
sudo make &>/tmp/redis.log
sudo make install &>/tmp/redis.log
printf "Done\n"
fi
# make directories for redis
# see "Installing Redis more properly" at http://redis.io/topics/quickstart
sudo mkdir -p /etc/redis /var/redis /opt/redis
if [ ! -d /opt/minard ]; then
sudo mkdir /opt/minard
sudo chown $USER /opt/minard
fi
if [ ! -f /opt/minard/bin/activate ]; then
# create virtual environment
virtualenv --no-site-packages /opt/minard
fi
cd /opt/minard
source bin/activate
pip install -qq supervisor
if [ ! -d /opt/minard/src ]; then
mkdir src
fi
if [ ! -d /opt/minard/src/minard ]; then
printf "Installing minard..."
cd $VIRTUAL_ENV/src
git clone -q git@github.com:snoplus/minard.git
pip install -qq ./minard
cd minard/doc
make html
cp -r _build/html /opt/minard/www/static/doc
printf "Done\n"
else
printf "Updating minard..."
cd $VIRTUAL_ENV/src/minard
git pull git@github.com:snoplus/minard.git master
cd doc
make html &>/dev/null
rm -rf /opt/minard/www/static/doc
cp -r _build/html /opt/minard/www/static/doc
cd $VIRTUAL_ENV/src
yes | pip -qq uninstall minard
pip -qq install ./minard
printf "Done\n"
fi
if [ ! -d /opt/minard/src/disp ]; then
printf "Installing disp..."
cd $VIRTUAL_ENV/src
git clone -q git@github.com:snoplus/disp.git
cd disp
make &>/tmp/disp.log
echo 'export PYTHONPATH=$VIRTUAL_ENV/src/disp/python:$PYTHONPATH' >> $VIRTUAL_ENV/bin/activate
echo 'export LD_LIBRARY_PATH=$VIRTUAL_ENV/src/disp/lib:$LD_LIBRARY_PATH' >> $VIRTUAL_ENV/bin/activate
ln -s $VIRTUAL_ENV/src/disp/bin/dispatch $VIRTUAL_ENV/bin/dispatch
printf "Done\n"
else
printf "Updating disp..."
cd $VIRTUAL_ENV/src/disp
git pull
make clean &>/dev/null
make &>/tmp/disp_install.log
printf "Done\n"
fi
# make sure gunicorn user exists
if ! id -u gunicorn >/dev/null; then
echo "Adding gunicorn user..."
sudo useradd -r gunicorn
fi
# make sure spmon user exists
if ! id -u spmon >/dev/null; then
echo "Adding spmon user..."
sudo useradd -d /home/spmon spmon
fi
# make sure nginx user exists
if ! id -u nginx >/dev/null; then
echo "Adding nginx user..."
sudo useradd -r nginx
fi
# create /var/log/snoplus
sudo mkdir -p /var/log/snoplus /var/log/snoplus_log /var/log/minard
sudo chown spmon:spmon /var/log/snoplus /var/log/snoplus_log /var/log/minard
cd $VIRTUAL_ENV/src/minard
# install gunicorn init script
sudo cp init/gunicorn /etc/init.d/gunicorn
# add gunicorn service
add_service gunicorn
sudo cp init/$supervisord_init /etc/init.d/supervisord
add_service supervisord
sudo cp etc/$supervisord_conf /etc/supervisord.conf
sudo cp init/$nginx_init /etc/init.d/nginx
add_service nginx
sudo mkdir -p /etc/nginx
sudo cp etc/$nginx_conf /etc/nginx/nginx.conf
sudo mkdir -p /var/log/nginx
sudo chown -R nginx:nginx /var/log/nginx
# install redis init script
sudo cp init/redis_6379 /etc/init.d/redis_6379
# redis configuration file
# this is where, for example, the location of the backup image is configured
sudo cp etc/$redis_conf /etc/redis/6379.conf
# add redis service
add_service redis_6379
# echo commands from here
set -x
sudo /etc/init.d/redis_6379 stop
sudo /etc/init.d/redis_6379 start
sudo /etc/init.d/nginx restart
sudo /etc/init.d/gunicorn restart
sudo /etc/init.d/supervisord restart