-
Notifications
You must be signed in to change notification settings - Fork 9
/
atlassian_create_test_server
executable file
·220 lines (193 loc) · 8.36 KB
/
atlassian_create_test_server
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
#!/bin/bash
# This script automates the procedure for creating a Test server for Confluence or JIRA
# Common directories between Confluence or JIRA
HOME_DIR="/var/atlassian/application-data"
INSTALL_DIR="/usr/local/atlassian"
APP="null"
DB_HOST="null"
CFGXML_FILE="null"
SQLDUMP_FILE="null"
INSTALLDIR_TAR="null"
HOMEDIR_TAR="null"
# Must be root to run this script
if [ "`/usr/bin/id -urn`" != "root" ] ; then
echo -e "\nYou must be root to execute this script \n"
exit 1
fi
USAGE() {
echo -e "\nUsage: `basename $0` [ -c | -j ] -d [DATABASE-HOSTNAME] -x [PATH-TO-CFGXML-FILE] -s [PATH-TO-SQLDUMP-FILE] -i [PATH-TO-INSTALLDIR-TAR] -h [PATH-TO-HOMEDIR-TAR]"
echo -e "-c --> Create a Confluence test server"
echo -e "-j --> Create a JIRA test server"
echo -e "-d DATABASE-HOSTNAME --> Hostname of MySQL Database server"
echo -e "-x PATH-TO-CFGXML-FILE --> Location of xml file with connection information to the Confluence/JIRA Test database"
echo -e "-s PATH-TO-SQLDUMP-FILE --> Location of the Production SQL DUMP file"
echo -e "-i PATH-TO-INSTALLDIR-TAR --> Location of the Production Installation directory archive"
echo -e "-h PATH-TO-HOMEDIR-TAR --> Location of the Production Home directory archive \n"
}
while getopts ":cjd:x:s:i:h:" OPT ; do
case $OPT in
c)
APP="confluence"
APP_LINK="jira"
CFG_DIR="$INSTALL_DIR/confluence/conf"
ENV_FILE="$INSTALL_DIR/confluence/bin/user.sh"
DBXML_FILE="$HOME_DIR/confluence/confluence.cfg.xml"
SRVXML_FILE="$CFG_DIR/server.xml"
PORT=8090
BASE_URL="docs"
;;
j)
APP="jira"
APP_LINK="docs"
CFG_DIR="$INSTALL_DIR/jira/conf"
ENV_FILE="$INSTALL_DIR/jira/bin/user.sh"
DBXML_FILE="$HOME_DIR/jira/dbconfig.xml"
SRVXML_FILE="$CFG_DIR/server.xml"
PORT=8080
BASE_URL="jira"
;;
d)
DB_HOST="$OPTARG"
;;
x)
CFGXML_FILE="$OPTARG"
;;
s)
SQLDUMP_FILE="$OPTARG"
;;
i)
INSTALLDIR_TAR="$OPTARG"
;;
h)
HOMEDIR_TAR="$OPTARG"
;;
\?)
echo -e "\nInvalid option: -$OPTARG" >&2
USAGE
exit 1
;;
:)
echo -e "\nOption -$OPTARG requires an argument" >&2
USAGE
exit 1
;;
esac
done
for VAR in $APP $DB_HOST $CFGXML_FILE $SQLDUMP_FILE $INSTALLDIR_TAR $HOMEDIR_TAR ; do
if [ "$VAR" = "null" ] ; then
USAGE
exit 1
fi
done
# Perform checks to determine if this script can run on this server
# -------------------------------------------------------------------
# Determine if this script can be run on this system
if [ -s $ENV_FILE ] ; then
# By sourcing $ENV_FILE we import the dedicated $APP user account - should be confluence or jira
. $ENV_FILE
# Dedicated $APP user account stored in $CONF_USER or $JIRA_USER
if [ -n "$CONF_USER" ] ; then
DED_USER=$CONF_USER
elif [ -n "$JIRA_USER" ] ; then
DED_USER=$JIRA_USER
else
echo -e "\nA dedicated $APP user account was not found on this system"
echo -e "This indicates $APP exists on this system but is not installed properly\n"
exit 1
fi
# $APP must not be running
if [ "`netstat -nlt | grep $PORT`" != "" ] ; then
echo -e "\n$APP is running"
echo -e "Stop $APP first before running this script \n"
exit 1
fi
else
echo -e "\n$APP does not appear to be installed on this system \n"
echo -e "Ensure a base install of $APP is available before running this script \n"
exit 1
fi
# Verify the file paths given exist and each file contains data
for FILE in $CFGXML_FILE $SQLDUMP_FILE $INSTALLDIR_TAR $HOMEDIR_TAR ; do
if [ ! -s $FILE ] ; then
echo -e "\nCould not find file $FILE or $FILE is empty\n"
exit 1
fi
done
# -------------------------------------------------------------------
# Checks Complete
# Begin the creation of the Test $APP Server
# -------------------------------------------------------------------
# In the SQL Dump file, the base URL is still set to the Production $APP URL
# Change this to be the TEST $APP URL
echo -e "\nSetting the base URL to ${BASE_URL}-test.libary.ucla.edu"
sed -i "s/${BASE_URL}.library.ucla.edu/${BASE_URL}-test.library.ucla.edu/g" $SQLDUMP_FILE
# Need to change the base URL for any External Gadget Links and the Applicaiton Links
# These will still be pointing to Production $APP and need change to TEST $APP_LINK
# This also points Service Desk to the correct Confluence KB URL if $APP = jira
echo -e "\nSetting the Application Link base URL to ${APP_LINK}-test.libary.ucla.edu"
sed -i "s/${APP_LINK}.library.ucla.edu/${APP_LINK}-test.library.ucla.edu/g" $SQLDUMP_FILE
# If necessary remove the existing $APP installation and home directories
# This ensures a clean environment for the extraction of the tar files
[ -d $INSTALL_DIR/$APP ] && rm -rf $INSTALL_DIR/$APP
[ -d $HOME_DIR/$APP ] && rm -rf $HOME_DIR/$APP
# Untar the archive files of the Install and Home directories
echo -e "\nUnpacking the $APP Installation directory \n"
tar xzf $INSTALLDIR_TAR -C $INSTALL_DIR
echo -e "Unpacking the $APP Home directory \n"
tar xzf $HOMEDIR_TAR -C $HOME_DIR
# The server.xml file still contains the proxyName of the Production $APP URL
# Change this to be the Test $APP URL
echo -e "\nSetting the proxyName to ${BASE_URL}-test.library.ucla.edu \n"
sed -i "s/${BASE_URL}.library.ucla.edu/${BASE_URL}-test.library.ucla.edu/g" $SRVXML_FILE
# Restore the back-up file containing the Test database connection information
echo -e "\nInserting the Test database connection information \n"
rm -f $DBXML_FILE
cp -p $CFGXML_FILE $DBXML_FILE
chown ${DED_USER}:${DED_USER} $DBXML_FILE
chmod 644 $DBXML_FILE
# Determine the database name and user account from $APP's $DBXML_FILE
if [ "$APP" = "confluence" ] ; then
DBUSER=`grep username $DBXML_FILE | grep -o "conf[a-zA-Z]*[0-9]*"`
DBNAME=`grep url $DBXML_FILE | grep -o "conf[a-zA-Z]*[0-9]*"`
elif [ "$APP" = "jira" ] ; then
DBUSER=`grep username $DBXML_FILE | grep -o "jira[a-zA-Z]*[0-9]*"`
DBNAME=`grep url $DBXML_FILE | grep -o "jira[a-zA-Z]*[0-9]*"`
else
echo -e "\nCould not determine database name and/or user account information \n"
exit 1
fi
# Before restoring the database, we will drop all existing tables to ensure a clean start
echo -e "\nDropping all tables from $DBNAME - if this is correct press Enter - otherwise CTRL-C"
read
/usr/local/bin/atlassian/atlassian_drop_db_tables $DBNAME
# Restore the MySQL dump file to the $APP Test database
echo -e "\nRestoring $SQLDUMP_FILE to the $DBNAME database"
echo -e "This can be a lengthy process - please be patient \n"
mysql -h $DB_HOST -u $DBUSER $DBNAME < $SQLDUMP_FILE
if [ $? -ne 0 ] ; then
echo -e "\nThere was a problem restoring the SQL dump file to the $DBNAME database. \n"
exit 1
fi
if [ "$APP" = "confluence" ] ; then
echo -e "\nThe $APP Test server is now ready."
echo -e "Start the $APP process and access the URL http://${BASE_URL}-test.library.ucla.edu in your browser \n"
echo -e "Some things you will need to do manually in the $APP GUI: \n"
echo -e "1. Change the Outgoing Mail Server to a fake name so $APP does not attempt to send out notificaitons \n"
echo -e "2. Install the developer $APP license - you'll need to obtain this from the atlassian account website \n"
elif [ "$APP" = "jira" ] ; then
echo -e "\nThe $APP Test server is now ready."
echo -e "Disable Mail so $APP does not attempt to send out notificaitons - do this in the setenv.sh file \n"
echo -e "Start the $APP process and access the URL http://${BASE_URL}-test.library.ucla.edu in your browsers \n"
echo -e "Some things you will need to do manually in the $APP GUI: \n"
echo -e "1. Install the JIRA Core developer license - you'll need to obtain this from the my.atlassian.com portal \n"
echo -e "2. Install the JIRA Service Desk developer license - you'll need to obtain this from the my.atlassian.com portal \n"
echo -e "3. Change the Incoming Mail server settings to use the lib_atlassiantest mailbox \n"
echo -e "4. Change the Outgoing Mail server settings to use localhost \n"
echo -e "5. Disable Service Desk notifications \n"
echo -e "6. Disable email requests for all Service Desk portals \n"
echo -e "7. Stop $APP and re-enable mail in the setenv.sh file \n"
else
echo -e "\nThe $APP Test server is now ready."
fi
echo -e "\nThe archive files you specified on the cmd line are still on this server taking up space"
echo -e "If you no longer need them you should delete them \n"