forked from brock-granular/setup-graphite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubuntu.bash
executable file
·215 lines (173 loc) · 5.77 KB
/
ubuntu.bash
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
function installDependencies()
{
printHeader 'INSTALLING DEPENDENCIES'
apt-get update
apt-get upgrade -y
apt-get install -y apache2
apt-get install -y erlang-os-mon
apt-get install -y erlang-snmp
apt-get install -y expect
apt-get install -y libapache2-mod-python
apt-get install -y libapache2-mod-wsgi
apt-get install -y memcached
apt-get install -y python-cairo-dev
apt-get install -y python-dev
apt-get install -y python-ldap
apt-get install -y python-memcache
apt-get install -y python-pip
apt-get install -y python-pysqlite2
apt-get install -y sqlite3
}
function installGraphite()
{
printHeader 'INSTALLING GRAPHITE'
pip install carbon
pip install graphite-web
pip install whisper
pip install Twisted==11.1.0
pip install django==1.5
pip install django-tagging
}
function configApache()
{
printHeader 'CONFIGURING APACHE'
local oldWSGISocketPrefix="$(escapeSearchPattern 'WSGISocketPrefix run/wsgi')"
local newWSGISocketPrefix="$(escapeSearchPattern 'WSGISocketPrefix /var/run/apache2/wsgi')"
if [[ -f '/etc/apache2/sites-available/000-default.conf' ]]
then
local defaultConfigFileName='000-default.conf'
$(safeCopyFile "${appPath}/conf/apache2/apache2.conf" '/etc/apache2/apache2.conf')
else
local defaultConfigFileName='default'
fi
sed "s@${oldWSGISocketPrefix}@${newWSGISocketPrefix}@g" \
'/opt/graphite/examples/example-graphite-vhost.conf' \
> "/opt/graphite/examples/${defaultConfigFileName}"
$(safeMoveFile "/opt/graphite/examples/${defaultConfigFileName}" "/etc/apache2/sites-available/${defaultConfigFileName}")
}
function configGraphite()
{
local login="${1}"
local password="${2}"
local email="${3}"
printHeader 'CONFIGURING GRAPHITE'
$(safeMoveFile '/opt/graphite/conf/carbon.conf.example' '/opt/graphite/conf/carbon.conf')
$(safeMoveFile '/opt/graphite/conf/storage-schemas.conf.example' '/opt/graphite/conf/storage-schemas.conf')
$(safeMoveFile '/opt/graphite/conf/graphite.wsgi.example' '/opt/graphite/conf/graphite.wsgi')
$(safeMoveFile '/opt/graphite/webapp/graphite/local_settings.py.example' '/opt/graphite/webapp/graphite/local_settings.py')
cd '/opt/graphite/webapp/graphite'
python manage.py syncdb --noinput
python manage.py createsuperuser --username="${login}" --email="${email}" --noinput
expect << DONE
spawn python manage.py changepassword "${login}"
expect "Password: "
send -- "${password}\r"
expect "Password (again): "
send -- "${password}\r"
expect eof
DONE
chown -R 'www-data:www-data' '/opt/graphite/storage'
}
function configUpstart()
{
$(safeCopyFile "${appPath}/conf/upstart/carbon-cache.conf" '/etc/init')
}
function restartServers()
{
printHeader 'RESTARTING SERVERS'
"${appPath}/bin/restart"
}
function displayUsage()
{
local scriptName="$(basename ${0})"
echo -e "\033[1;33m"
echo "SYNOPSIS :"
echo " ${scriptName} --help --login <LOGIN> --password <PASSWORD> --email <EMAIL>"
echo -e "\033[1;35m"
echo "DESCRIPTION :"
echo " --help Help page"
echo " --login Graphite Browser admin-user's login (require)"
echo " --password Graphite Browser admin-user's password (require)"
echo " --email Graphite Browser admin-user's email (require)"
echo -e "\033[1;36m"
echo "EXAMPLES :"
echo " ./${scriptName} --help"
echo " ./${scriptName} --login 'root' --password 'root' --email '[email protected]'"
echo -e "\033[1;32m"
echo "USEFUL COMMANDS :"
echo " To stop/start/restart apache2 : service apache2 <stop|start|restart>"
echo " To stop/start/restart memcached : service memcached <stop|start|restart>"
echo " To stop/start/restart carbon-cache : <stop|start|restart> carbon-cache"
echo " To stop/start/restart all services : ${appPath}/bin/<stop|start|restart>"
echo -e "\033[0m"
exit ${1}
}
function runInstallation()
{
local login="${1}"
local password="${2}"
local email="${3}"
checkRequireRootUser
installDependencies
installGraphite
configApache
configGraphite "${login}" "${password}" "${email}"
configUpstart
restartServers
}
function main()
{
appPath="$(cd "$(dirname "${0}")" && pwd)"
source "${appPath}/lib/util.bash" || exit 1
local optCount=${#}
while [[ ${#} -gt 0 ]]
do
case "${1}" in
--help)
displayUsage 0
;;
--login)
shift
if [[ ${#} -gt 0 ]]
then
local login="$(trimString "${1}")"
fi
;;
--password)
shift
if [[ ${#} -gt 0 ]]
then
local password="$(trimString "${1}")"
fi
;;
--email)
shift
if [[ ${#} -gt 0 ]]
then
local email="$(trimString "${1}")"
fi
;;
*)
shift
;;
esac
done
if [[ "$(isEmptyString ${login})" = 'true' || "$(isEmptyString ${password})" = 'true' ||
"$(isEmptyString ${email})" = 'true' ]]
then
if [[ ${optCount} -gt 0 ]]
then
error '\nERROR: login, password, or email parameter not found!'
displayUsage 1
fi
displayUsage 0
fi
if [[ "$(isValidEmail ${email})" = 'false' ]]
then
error '\nERROR: invalid email!\n'
exit 1
fi
runInstallation "${login}" "${password}" "${email}"
}
main "${@}"