Skip to content

Commit fc1da70

Browse files
committed
Upgrade docs from 1.1 to 1.2.
1 parent d321b18 commit fc1da70

File tree

3 files changed

+243
-0
lines changed

3 files changed

+243
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE RepoInfo ADD COLUMN status INTEGER DEFAULT 0;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE `base_filecomment` ADD `detail` LONGTEXT DEFAULT NULL;
2+
ALTER TABLE `base_filecomment` ADD `resolved` TINYINT(1) NOT NULL DEFAULT 0;
3+
ALTER TABLE `base_filecomment` ADD INDEX `resolved` (`resolved`);
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#!/bin/bash
2+
3+
SCRIPT=$(readlink -f "$0") # haiwen/seafile-server-1.3.0/upgrade/upgrade_xx_xx.sh
4+
UPGRADE_DIR=$(dirname "$SCRIPT") # haiwen/seafile-server-1.3.0/upgrade/
5+
INSTALLPATH=$(dirname "$UPGRADE_DIR") # haiwen/seafile-server-1.3.0/
6+
TOPDIR=$(dirname "${INSTALLPATH}") # haiwen/
7+
default_ccnet_conf_dir=${TOPDIR}/ccnet
8+
default_conf_dir=${TOPDIR}/conf
9+
default_pids_dir=${TOPDIR}/pids
10+
default_logs_dir=${TOPDIR}/logs
11+
seafile_server_symlink=${TOPDIR}/seafile-server-latest
12+
seahub_data_dir=${TOPDIR}/seahub-data
13+
seahub_settings_py=${TOPDIR}/seahub_settings.py
14+
15+
manage_py=${INSTALLPATH}/seahub/manage.py
16+
17+
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
18+
export SEAFILE_CENTRAL_CONF_DIR=${default_conf_dir}
19+
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.6/site-packages:${INSTALLPATH}/seafile/lib64/python2.6/site-packages:${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH
20+
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seafile/lib64/python2.7/site-packages:$PYTHONPATH
21+
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
22+
23+
prev_version=1.1
24+
current_version=1.2
25+
26+
echo
27+
echo "-------------------------------------------------------------"
28+
echo "This script would upgrade your seafile server from ${prev_version} to ${current_version}"
29+
echo "Press [ENTER] to contiune"
30+
echo "-------------------------------------------------------------"
31+
echo
32+
read dummy
33+
34+
function check_python_executable() {
35+
if [[ "$PYTHON" != "" && -x $PYTHON ]]; then
36+
return 0
37+
fi
38+
39+
if which python2.7 2>/dev/null 1>&2; then
40+
PYTHON=python2.7
41+
elif which python27 2>/dev/null 1>&2; then
42+
PYTHON=python27
43+
else
44+
echo
45+
echo "Can't find a python executable of version 2.7 or above in PATH"
46+
echo "Install python 2.7+ before continue."
47+
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
48+
echo
49+
exit 1
50+
fi
51+
}
52+
53+
function read_seafile_data_dir () {
54+
seafile_ini=${default_ccnet_conf_dir}/seafile.ini
55+
if [[ ! -f ${seafile_ini} ]]; then
56+
echo "${seafile_ini} not found. Now quit"
57+
exit 1
58+
fi
59+
seafile_data_dir=$(cat "${seafile_ini}")
60+
if [[ ! -d ${seafile_data_dir} ]]; then
61+
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
62+
echo "Please check it first, or create this directory yourself."
63+
echo ""
64+
exit 1;
65+
fi
66+
67+
export SEAFILE_CONF_DIR=$seafile_data_dir
68+
}
69+
70+
function ensure_server_not_running() {
71+
# test whether seafile server has been stopped.
72+
if pgrep seaf-server 2>/dev/null 1>&2 ; then
73+
echo
74+
echo "seafile server is still running !"
75+
echo "stop it using scripts before upgrade."
76+
echo
77+
exit 1
78+
elif pgrep -f "${manage_py} run_gunicorn" 2>/dev/null 1>&2 \
79+
|| pgrep -f "seahub.wsgi:application" 2>/dev/null 1>&2; then
80+
echo
81+
echo "seahub server is still running !"
82+
echo "stop it before upgrade."
83+
echo
84+
exit 1
85+
elif pgrep -f "${manage_py} runfcgi" 2>/dev/null 1>&2 ; then
86+
echo
87+
echo "seahub server is still running !"
88+
echo "stop it before upgrade."
89+
echo
90+
exit 1
91+
fi
92+
}
93+
94+
function migrate_avatars() {
95+
echo
96+
echo "migrating avatars ..."
97+
echo
98+
media_dir=${INSTALLPATH}/seahub/media
99+
orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
100+
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
101+
102+
# move "media/avatars" directory outside
103+
if [[ ! -d ${dest_avatar_dir} ]]; then
104+
mkdir -p "${TOPDIR}/seahub-data"
105+
mv "${orig_avatar_dir}" "${dest_avatar_dir}" 2>/dev/null 1>&2
106+
ln -s ../../../seahub-data/avatars "${media_dir}"
107+
108+
elif [[ ! -L ${orig_avatar_dir} ]]; then
109+
mv "${orig_avatar_dir}"/* "${dest_avatar_dir}" 2>/dev/null 1>&2
110+
rm -rf "${orig_avatar_dir}"
111+
ln -s ../../../seahub-data/avatars "${media_dir}"
112+
fi
113+
echo "Done"
114+
}
115+
116+
function update_database() {
117+
echo
118+
echo "Updating seafile/seahub database ..."
119+
echo
120+
121+
db_update_helper=${UPGRADE_DIR}/db_update_helper.py
122+
if ! $PYTHON "${db_update_helper}" 1.2.0; then
123+
echo
124+
echo "Failed to upgrade your database"
125+
echo
126+
exit 1
127+
fi
128+
echo "Done"
129+
}
130+
131+
function upgrade_seafile_server_latest_symlink() {
132+
# update the symlink seafile-server to the new server version
133+
if [[ -L "${seafile_server_symlink}" || ! -e "${seafile_server_symlink}" ]]; then
134+
echo
135+
printf "updating \033[33m${seafile_server_symlink}\033[m symbolic link to \033[33m${INSTALLPATH}\033[m ...\n\n"
136+
echo
137+
if ! rm -f "${seafile_server_symlink}"; then
138+
echo "Failed to remove ${seafile_server_symlink}"
139+
echo
140+
exit 1;
141+
fi
142+
143+
if ! ln -s "$(basename ${INSTALLPATH})" "${seafile_server_symlink}"; then
144+
echo "Failed to update ${seafile_server_symlink} symbolic link."
145+
echo
146+
exit 1;
147+
fi
148+
fi
149+
}
150+
151+
function make_media_custom_symlink() {
152+
media_symlink=${INSTALLPATH}/seahub/media/custom
153+
if [[ -L "${media_symlink}" ]]; then
154+
return
155+
156+
elif [[ ! -e "${media_symlink}" ]]; then
157+
ln -s ../../../seahub-data/custom "${media_symlink}"
158+
return
159+
160+
161+
elif [[ -d "${media_symlink}" ]]; then
162+
cp -rf "${media_symlink}" "${seahub_data_dir}/"
163+
rm -rf "${media_symlink}"
164+
ln -s ../../../seahub-data/custom "${media_symlink}"
165+
fi
166+
167+
}
168+
169+
function move_old_customdir_outside() {
170+
# find the path of the latest seafile server folder
171+
if [[ -L ${seafile_server_symlink} ]]; then
172+
latest_server=$(readlink -f "${seafile_server_symlink}")
173+
else
174+
return
175+
fi
176+
177+
old_customdir=${latest_server}/seahub/media/custom
178+
179+
# old customdir is already a symlink, do nothing
180+
if [[ -L "${old_customdir}" ]]; then
181+
return
182+
fi
183+
184+
# old customdir does not exist, do nothing
185+
if [[ ! -e "${old_customdir}" ]]; then
186+
return
187+
fi
188+
189+
# media/custom exist and is not a symlink
190+
cp -rf "${old_customdir}" "${seahub_data_dir}/"
191+
}
192+
193+
function add_gunicorn_conf() {
194+
gunicorn_conf=${default_conf_dir}/gunicorn.conf
195+
if ! $(cat > ${gunicorn_conf} <<EOF
196+
import os
197+
198+
daemon = True
199+
workers = 5
200+
201+
# default localhost:8000
202+
bind = "127.0.0.1:8000"
203+
204+
# Pid
205+
pids_dir = '$default_pids_dir'
206+
pidfile = os.path.join(pids_dir, 'seahub.pid')
207+
208+
# for file upload, we need a longer timeout value (default is only 30s, too short)
209+
timeout = 1200
210+
211+
limit_request_line = 8190
212+
EOF
213+
); then
214+
echo "failed to generate gunicorn.conf";
215+
fi
216+
}
217+
218+
#################
219+
# The main execution flow of the script
220+
################
221+
222+
check_python_executable;
223+
read_seafile_data_dir;
224+
ensure_server_not_running;
225+
226+
update_database;
227+
migrate_avatars;
228+
229+
move_old_customdir_outside;
230+
make_media_custom_symlink;
231+
upgrade_seafile_server_latest_symlink;
232+
233+
add_gunicorn_conf;
234+
235+
echo
236+
echo "-----------------------------------------------------------------"
237+
echo "Upgraded your seafile server successfully."
238+
echo "-----------------------------------------------------------------"
239+
echo

0 commit comments

Comments
 (0)