-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprepare_fresh_ubuntu_for_deploy.sh
executable file
·234 lines (180 loc) · 9.57 KB
/
prepare_fresh_ubuntu_for_deploy.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/sh
# As of 2008-09-17 this script gets called by install.sh placed in the same dir
# the command= trick gets screwed up with quotes so be careful
# TODO setup LibertyNet/connectivity
#echo "Becoming root user"
#command="sudo su"
#echo "Running: $command"
#read -p "Press any key to begin" -r A
#$command
echo "Make it so that the OS doesn't record the read time of every file (an optimization and SSD saver)"
read -p "Press any key to begin" -r A
cat /etc/fstab | sed -e 's/relatime,errors=remount-ro/relatime,noatime,errors=remount-ro/' > /tmp/fstab
mv /tmp/fstab /etc/fstab
echo "Reduce swappiness factor so that the swap file is only needed in extreme situations"
read -p "Press any key to begin" -r A
echo "# Set swappiness to zero to save SSD and maximize use of memory
vm.swappiness=0" >> /etc/sysctl.conf
echo "
## Install
## See also (http://codeplot.com/documents/3186/edit)
#I Installed Ubuntu 8.04 Server
#US Keyboard Layout
#Zimbabwe region
#If this machine was using an SSD drive configure the paritions so that it has no swap
#I did a single partition marked as bootable and setup for the root on EXT3+Journaling
#I marked the OpenSSH server as an additional option
#I did not set it as a DNS server or Mail Server
## Naming
# For baobab we name our computers after trees so I called this one Sapele
# I added the default user as baobab
## Reboot and login
## Get the stuff you will need (you may want to combine these steps so you can leave the download running)
"
command="apt-get update"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
command="apt-get install mysql-server nginx build-essential sudo git-core libopenssl-ruby lynx openssh-client vim irb ruby1.8-dev ruby1.8 libmysql-ruby rdoc1.8 ri1.8"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
ln -s /usr/bin/ruby1.8 /usr/bin/ruby
if [ ! -f /usr/bin/gem1.8 ]; then
echo "Downloading and installing rubygems"
read -p "Press any key to continue" -r A
wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
tar xvzf rubygems-1.2.0.tgz
cd rubygems-1.2.0
ruby setup.rb
cd ..
fi
ln -s /usr/bin/gem1.8 /usr/bin/gem
read -p "Press any key to continue" -r A
command="sudo gem install mongrel --no-rdoc --no-ri --verbose"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
command="sudo gem install mongrel_cluster --no-rdoc --no-ri --verbose"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
command="sudo gem install rake --verbose"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
command="sudo gem install json --verbose"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
echo "
## At the end you will need to input the mysql root password
# In general we create paswords with a hash of the machine name, a common nonce value and some special characters
"
## Ubuntu 8.0.4.1 and beyond don't need to worry about this
## Update the ssh for Debian security vulnerability
## If you are running Ubuntu/Debian locally, you should do this on your machine *before*
## You ssh into the server!
## Check for vulnerable keys
# If you are using 8.04 like me (I think that Intrepid will include this fix by default)
# Then you will get a message saying that it is correcting the blacklisted keys
# When completed, you should run ssh-vulnkey to make sure your root user is
# Not blacklisted. You should see two keys listed and both should start with
# Not blacklisted:
# read -p "Press any key to continue" -r A
# ssh-vulnkey
echo "## Creating deploy and www users on server"
command="adduser --disabled-password deploy"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
command="adduser --system --no-create-home --group --disabled-password www"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
visudo_commands="deploy ALL=(ALL) NOPASSWD:ALL
Defaults env_reset, insults"
echo "Adding:
-----
$visudo_commands
-----
to /etc/sudoers"
read -p "Press any key to continue" -r A
echo "$visudo_commands" >> /etc/sudoers
echo "
Enter file in which to save the key (/home/YOURLOCALUSER/.ssh/id_rsa): <Enter>
Enter passphrase (empty for no passphrase): <Enter>
Enter same passphrase again: <Enter>
## On your local scp your public key up (note that I use the baobab user I created when installing Ubuntu on the server)
## Make sure you copy the id_rsa.pub and not the id_rsa, the id_rsa file is your private key and you want to keep it safe!
## If you don't know your server's ip address, type ifconfig on the server
scp ~/.ssh/id_rsa.pub baobab@YOURSERVERIP:/tmp
password: <Enter your server's baobab user password>
Generating keys for the deploy user now...
Press enter twice when asked for a passphrase (we want an empty passphrase)
"
read -p "Press any key to continue" -r A
echo "Running: su deploy -c \"ssh-keygen -t rsa\""
read -p "Press any key to continue" -r A
su deploy -c "ssh-keygen -t rsa"
echo "## Adding public keys for all Baobab programmers
This should be safe to do - public keys are only have of the authentication puzzle -
hence private and public keys.
"
read -p "Press any key to continue" -r A
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyUvMIvhJUYs7nIaiLBnUcs03XuOeHiw1JGh1M/ovbKc9YO4SJsl9CYxpyDeh9jSyvdNhNdeUSg7PBSSyAYpVXeK6WXN9LnqKOWRu8n5rXGNSycM2tenaADiS/xtMkHmIFYOE/QFQF+Amg5lKR1DjsfZXzscdtYsmAT09j6GFYfgY/KIP/gxSsEDzOGSIxYqJwpCzV+/nwub72ElzVcW9EJu2HpSD8jhKF6XrZ3VExsCk9v86qrTGWeVOyFubRb7+V6Db4xc+x2HirdyMW7hZceDfTpB0xX1GXd4PYZ023gfvNkGbIj/aOSDeJtDIJyQhzCbIXY+CiL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BW5U1Vgn8ce/WDYr6A2/stqDvMwCAlZFqpBZExjWcFDC30aNX7bjdESwJ+BJTSZ6P7pCe4N+uia8nFLvxfUCMSXTvQ+cmOKnpmRbMDvctAafuk5fSLuPS9bReY/sh76ax135jrQejbGW4q+pLpUV3D0Ff9vgo905OCVjpCx+QrYMr4bqQ38h/a/GvdLx8Ow6c7fHJPDzJx+lxXQ6YUhm1AIzJFAgtVg1JXs0tkC4/9TxreRUnHyIWH7h4c+lzdPoJT8a2QV4IkHf3xMhki/mCYRFx7GBk3N8pnTO9b2PWlTN6dZtDYixrnVpkGxp4zKAmAa3i6G3IQ9QBkQ== bond@nkungudza
" >> /home/deploy/.ssh/authorized_keys
chmod 600 /home/deploy/.ssh/authorized_keys
chown deploy /home/deploy/.ssh/authorized_keys
echo "## On the server, create the root project folder (our project is called 'bart')"
command="mkdir /var/www/bart"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
command="chown deploy:deploy /var/www/bart"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
command="mkdir /etc/mongrel_cluster"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
echo "Creating mongrel user"
command="sudo adduser --system --no-create-home --group --disabled-password mongrel"
echo "Running: $command"
read -p "Press any key to continue" -r A
$command
echo "
## On the server, setup the database
## We should be calling the database openmrs, with the user openmrs
## The password should be common probably
Enter the password you want to use for the openmrs database"
read -r PASSWORD
echo "Creating the openmrs database and the openmrs user. Enter root db password when prompted"
read -p "Press any key to continue" -r A
echo "CREATE DATABASE openmrs; GRANT ALL on openmrs.* to 'openmrs'@'localhost' IDENTIFIED BY '$PASSWORD';" | mysql -u root -p
echo "
## On your LOCAL MACHINE (NOT THE SERVER), cross your fingers and deploy (cap -T if you want to see all tasks)
## I have noticed that the deploy and deploy:setup tasks rely on each other
## So you have to run cap deploy first and let it fail...
## then run setup, then run deploy again
cap deploy
cap deploy:setup
cap deploy
cap nginx:setup
cap nginx:start
* On the SERVER, run these db/migrate and bootstrap scripts while in /var/www/bart/current
echo 'DELETE FROM schema_migrations; DROP TABLE sessions; DROP TABLE weight_for_heights;' | mysql -u {dbusername} -p {database}
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake openmrs:bootstrap:load:defaults
RAILS_ENV=production script/runner 'PatientAdherenceDate.reset;PatientPrescriptionTotal.reset;PatientWholeTabletsRemainingAndBrought.reset;PatientHistoricalOutcome.reset'
* On your LOCAL MACHINE
cap deploy:restart
# ------------- Firefox
# READ the firefox README
# If you don't have the firefox daemon it is here http://github.com/baobab/firefox-daemon
"