-
Notifications
You must be signed in to change notification settings - Fork 1
/
other_servers_update_data.sh
148 lines (125 loc) · 4.59 KB
/
other_servers_update_data.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
#!/bin/bash
########################
#
## Servers that do NOT need updating:
# -Gateway HTTPD proxy
# -PC Beacon - hosts Care4Rare exomes, no way to change them?
# -PC Preprod - Old data doesn't matter?
# -PC Dev - Old data doesn't matter
# -PC Playground - Old data doesn't matter
#
########################
########################
#
## Servers that DO need updating:
# - PhenoTips Database: PT Farm, PC Prod2
# - ElasticCompute: Stats
# - Jenkins: CI
# - Nexus: Nexus
#
########################
########################
## Dump PhenoTips Database
#
# Apply to Servers:
# PT Farm
# PC Prod2
#
########################
# Detect where the PhenoTips instance is
if [[ -f /var/lib/tomcat6/webapps/ROOT/WEB-INF/xwiki.properties ]]
then
HIBERNATE_CONFIG="/var/lib/tomcat6/webapps/ROOT/WEB-INF/hibernate.cfg.xml"
elif [[ -f /var/lib/tomcat6/webapps/phenotips/WEB-INF/xwiki.properties ]]
then
HIBERNATE_CONFIG="/var/lib/tomcat6/webapps/phenotips/WEB-INF/hibernate.cfg.xml"
elif [[ -f /var/lib/phenotips/webapp/WEB-INF/xwiki.properties ]]
then
HIBERNATE_CONFIG="/var/lib/phenotips/webapp/WEB-INF/hibernate.cfg.xml"
fi
# Extract the mysql host, DB name, username and password
MHOST=`cat $HIBERNATE_CONFIG | grep 'jdbc:mysql://' | sed -r -e 's/.*\/\/([^\/]+)\/.*/\1/'`
MDB=`cat $HIBERNATE_CONFIG | grep 'jdbc:mysql://' | sed -r -e 's/.*\/\/[^\/]+\/([^?<]+).*/\1/'`
MUSER=`cat $HIBERNATE_CONFIG | grep 'jdbc:mysql://' -A 5 | grep 'connection.username' | sed -r -e 's/.*>([^<]+)<.*/\1/'`
MPASS=`cat $HIBERNATE_CONFIG | grep 'jdbc:mysql://' -A 5 | grep 'connection.password' | sed -r -e 's/.*>([^<]+)<.*/\1/'`
# Compute the backup filename and make sure its parent directory exists
BACKUPDIR=/var/lib/phenotips/backups/mysql
DBFILE=data.sql
# Dump the database
mysqldump --events --single-transaction $MDB -u $MUSER -h $MHOST -p $MPASS > $DBFILE
########################
## Load PhetoTips Database
########################
mysql -u $MUSER -h $MHOST -p $MPASS < $DBFILE
########################
## Upgrade Phenotips Version (Only if out of date)
########################
# Option 1) Install PhenoTips From APT
curl https://phenotips.org/download/PhenoTips/Download/PhenoTips.repo > PhenoTips.repo
sudo chown root:root PhenoTips.repo
sudo mv PhenoTips.repo /etc/yum.repos.d/
sudo yum install -y phenotips
# Option 2) Install PhenoTips From WGET
systemctl stop tomcat || service tomcat stop
mkdir -p /var/lib/phenotips/next
cd /var/lib/phenotips/next
wget https://nexus.phenotips.org/nexus/content/repositories/releases/org/phenotips/phenotips-standalone/1.2.5/phenotips-standalone-1.2.5.zip
unzip phenotips-*.zip && rm phenotips-*.zip
cd phenotips-*
rm -rf ../../solr/ && cp -r data/solr ../../
mkdir /var/lib/phenotips/backup
mv /var/lib/tomcat*/webapps/phenotips /var/lib/phenotips/backup
mv /var/lib/tomcat*/webapps/ROOT /var/lib/phenotips/backup # ? needed
mv webapps/phenotips /var/lib/tomcat*/webapps
rm -rf /var/lib/phenotips/next
chown -R tomcat:tomcat /var/lib/phenotips || chown -R tomcat:tomcat /var/lib/phenotips
# Merge any custom changes done in the following configuration files from the old instance into the new one:
diff xwiki.cfg /var/lib/phenotips/webapp/WEB-INF/xwiki.cfg
diff xwiki.properties /var/lib/phenotips/webapp/WEB-INF/xwiki.properties
diff hibernate.cfg.xml /var/lib/phenotips/webapp/WEB-INF/hibernate.cfg.xml
# Start new version of Phenotips
systemctl start tomcat || service tomcat start
########################
## Elastic Compute
#
# Apply to Server: Stats
#
########################
# Initialize Snapshot Respository
curl -sX PUT http://$ES_HOST:$ES_PORT/_snapshot/$REPOSITORY_NAME -w "\n" -d @- << EOF
{
"type": "fs",
"settings": {
"location": "/root/elastic_backup"
}
}
EOF
# Perform a snapshat
curl -sX PUT -w "\n" http://$ES_HOST:$ES_PORT/_snapshot/$REPOSITORY_NAME/$SNAPNAME?wait_for_completion=true
# Restore from an existing snapshot:
curl -sX POST -w "\n" http://$ES_HOST:$ES_PORT/_snapshot/$REPOSITORY_NAME/$SNAPNAME/_restore
/var/lib
########################
## Nexus
#
# Apply to Server: Nexus
#
########################
cat <<EOF >> /etc/ssh/ssh_config
Host *.local
ProxyCommand ssh -i ~/.ssh/id_rsa.dan -q root@frontend1.ccm.sickkids.ca nc %h 22
EOF
rsync -v -e "ssh -i /root/.ssh/id_rsa.dan" nexus.local:/home/nexus /home/nexus
########################
## Jenkins
## https://wiki.jenkins.io/display/JENKINS/Administering+Jenkins
#
# Apply to Server: CI
#
########################
cat <<EOF >> /etc/ssh/ssh_config
Host *.local
ProxyCommand ssh -i ~/.ssh/id_rsa.dan -q root@frontend1.ccm.sickkids.ca nc %h 22
EOF
rsync -v -e "ssh -i /root/.ssh/id_rsa.dan" ci.local:/var/lib/jenkins /var/lib/jenkins
```