forked from blackberry/saturnring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaturnring_postbootup_as_vagrant_user.sh
executable file
·156 lines (125 loc) · 4.9 KB
/
saturnring_postbootup_as_vagrant_user.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
#!/bin/bash
#Copyright 2014 Blackberry Limited
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
source ./envvars.sh
cd $INSTALLLOCATION
#Get latest saturnringsoftware from master branch
#git clone https://github.com/sachinkagarwal/saturnring/
cd $INSTALLLOCATION
if [ $INSTALLLOCATION != $CODEROOT ]; then
cp -R $CODEROOT .
fi
if [ ! -d "$INSTALLLOCATION/saturnenv" ]; then
virtualenv saturnenv
fi
cd $INSTALLLOCATION/ssddj
source $INSTALLLOCATION/saturnenv/bin/activate
pip install -r $INSTALLLOCATION/python-virtualenv-requirements.txt --allow-external django-admin-changelist-stats --allow-unverified django-admin-changelist-stats
cat <<EOF > $INSTALLLOCATION/ssddj/saturn.ini
[saturnring]
#Cluster name: This is used as the stats Excel XLS filename
clustername=$CLUSTERNAME
#This is where the Saturnring picks up scripts to install on the saturnnode for things like creating/deleting iSCSI targets
bashscripts=globalstatemanager/bashscripts/
#The user needs to copy the corresponding public key to the saturn node's user (specified in the [saturnnode] section using e.g. ssh-copy-id
privatekeyfile=$SATURNWKDIR/saturnringconfig/saturnkey
#This is where saturnring keeps the latest iscsi config file
iscsiconfigdir=$SATURNWKDIR/saturnringconfig/
#Django secret key (CHANGE in production)
django_secret_key=$DJANGOSECRETKEY
#Logging path
logpath=$SATURNWKDIR/saturnringlog
#Number of queues
#If you change this number then please adjust the /etc/supervisor/conf.d/saturnring.conf by adding or deleting queue entries out there
numqueues=$NUMWORKERS
#Proxyfolder
#This is the proxy subfolder if the application is being run behind a proxy
proxyfolder=$PROXYFOLDER
[database]
dbtype=$DATABASE_TYPE
dbname=$DATABASE_NAME
dbhost=$DATABASE_HOST
dbport=$DATABASE_PORT
dbuser=$DATABASE_USER
dbpassword=$DATABASE_PASSWORD
dbdir=$DATABASE_DIR
[saturnnode]
user=$INSTALLUSER
#Location on the saturnnode where the scripts are installed.
install_location=$INSTALLLOCATION/saturn/
bashpath=/bin/bash
pythonpath=/usr/bin/python
[activedirectory]
enabled=$LDAP_ENABLED
ldap_uri=$LDAP_LDAP_URI
user_dn=$LDAP_USER_DN
staff_group=$LDAP_STAFF_GROUP
bind_user_dn=$LDAP_BIND_USER_DN
bind_user_pw=$LDAP_BIND_USER_PW
[tests]
saturnringip=$HOSTNAME
saturnringport=80
#saturniscsiserver=172.19.157.201
EOF
python manage.py syncdb --noinput
python manage.py convert_to_south ssdfrontend
python manage.py schemamigration ssdfrontend --auto
python manage.py migrate
cd $INSTALLLOCATION/ssddj
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', '$ADMINEMAIL', '$SATURNRINGPASSWORD')" | python manage.py shell
cat <<EOF > /var/www/saturnring/index.wsgi
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('$INSTALLLOCATION/saturnenv/$INSTALLUSER/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('$INSTALLLOCATION/ssddj')
sys.path.append('$INSTALLLOCATION/ssddj/ssddj')
os.environ['DJANGO_SETTINGS_MODULE'] = 'ssddj.settings'
# Activate your virtual env
activate_env=os.path.expanduser("$INSTALLLOCATION/saturnenv/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
EOF
python manage.py collectstatic --noinput
#This little bit uses cron to keep updating stats within the application
if [ ! -f mycron ];then
crontab -l > mycron
#echo new cron into cron file
echo "12 22 * * * cd $INSTALLLOCATION/ssddj/; source ../saturnenv/bin/activate; python manage.py cleanup && echo 'vacuum (analyze, verbose);' | python manage.py dbshell" >> mycron
echo "* * * * * curl -X GET http://$SATURNRINGHOST:$SATURNRINGAPACHEPORT/api/stateupdate/" >> mycron
#install new cron file
crontab mycron
fi
git config --global user.email "[email protected]"
git config --global user.name "$INSTALLUSER"
# Create new keys
CONFIGDIR=$SATURNWKDIR/saturnringconfig
sudo mkdir -p $CONFIGDIR
sudo chown $INSTALLUSER:$INSTALLUSER $CONFIGDIR
cd $CONFIGDIR
git init
ssh-keygen -q -f saturnkey -N ''
ssh-keygen -f saturnkey.pub -e -m pem > saturnkey.pem
git add *
git commit -a -m "Created Saturn keys"
mkdir -p $INSTALLLOCATION/redisqconf
cat <<EOF > $INSTALLLOCATION/redisqconf/rqworker.sh
#!/bin/bash
source $INSTALLLOCATION/saturnenv/bin/activate
python $INSTALLLOCATION/ssddj/manage.py rqworker \$1
EOF
chmod +x $INSTALLLOCATION/redisqconf/rqworker.sh