This repository has been archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscourse_upgrade.sh
126 lines (96 loc) · 3.42 KB
/
discourse_upgrade.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
#!/usr/bin/env bash
###############################################################
# Discourse upgrade script for unsupported installs. #
# #
# Author: Brendan Corcoran (@bcorcoran) #
# #
# Please be aware that this, too, is unsupported. #
# This script performs the same actions as the docker upgrade #
# If interested, see: http://git.io/sScXVg #
###############################################################
# Discourse user: The user discourse runs under
DISCOURSE_USER=
# Discourse user home: The home directory of above user (the one containing .rvm)
DISCOURSE_USERHOME=
# Discourse directory: The directory that discourse install is located
DISCOURSE_DIR=
# App Server Selection
# Options:
# unicorn = Unicorn; Remember to configure discourse/config/unicorn.conf.rb and nginx upstream block!
APP_SERVER=unicorn
pre_run_test() {
# Check for required commands
local ERR=0
for REQUIRED in git grep awk bundle ruby
do
if ! command -v $REQUIRED >/dev/null 2>&1 ; then
echo "This script requires the ${REQUIRED} command."
let ERR=$ERR+1
fi
done
for REQV in DISCOURSE_USER DISCOURSE_USERHOME DISCOURSE_DIR ; do
if [ -z ${!REQV} ] ; then
echo "${REQV} variable not set!"
let ERR=$ERR+1
fi
done
if [ $ERR -gt 0 ] ; then
echo -e "\e[1;31mDiscourse upgrade script pre-test failed.\e[0m"
exit 1
else
unset ERR
echo "Discourse upgrade script pre-test passed."
fi
}
pre_run_test
upgrade_discourse() {
# Go to discourse dir
cd ${DISCOURSE_DIR}
# get pid of unicorn master
local UNICORN_PID=`ps -fu ${DISCOURSE_USER} | grep 'unicorn master' | grep -v grep | awk '{print $2}'`
# get latest code
echo -e "\e[1;33mGetting latest discourse code...\e[0m"
local CURRENT_BRANCH=`git branch | grep "*" | awk '{print $2}'`
git fetch
if [ "${CURRENT_BRANCH}" != "tests-passed" ] ; then
git checkout tests-passed
fi
git reset --hard HEAD@{upstream}
echo -e "\e[1;33mRunning discourse upgrades (bundle install, migration, asset compile)...\e[0m"
# Bundle install
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production \
bundle install --deployment --without test --without development
# Run migration
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production \
bundle exec rake multisite:migrate
# Compile assets
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production \
bundle exec rake assets:precompile
# Kill old processes
echo -e "\n\e[1;33mAttempting to kill unicorn...\e[0m\n"
for PID in ${UNICORN_PID} ; do
if [ -n "${PID}" -a "${PID}" -gt 0 ] ; then
kill $PID;
if [ $? -eq 0 ] ; then
echo "Unicorn (pid:${PID}) killed. Runit should catch up in a bit."
else
echo "Tried to kill app server pid:${PID}, but failed."
fi
else
echo "Unicorn process not found."
fi
done
echo -e "\n\e[1;32mUpgrade is complete. Reload NGINX now, if necessary, to complete upgrade.\e[0m"
}
echo -e "\e[1;33;42mDiscourse Upgrade Script\e[0m\n"
echo "The following are your configuration values: "
echo "Discourse User: ${DISCOURSE_USER}"
echo "Discourse User Home Directory: ${DISCOURSE_USERHOME}"
echo "Discourse Directory: ${DISCOURSE_DIR}"
echo "App Server: ${APP_SERVER}"
echo
read -p "Are these values correct? [Y/n]: " YN
case $YN in
[Nn] ) echo "Upgrade script aborted."; exit 0 ;;
[Yy]|* ) upgrade_discourse ;;
esac