1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-07-31 06:49:58 +00:00

Update minor upgrade script.

This commit is contained in:
ly1217 2019-10-10 01:02:27 -07:00
parent 0c874defc9
commit f0cf80aa5f
7 changed files with 13 additions and 1030 deletions

View File

@ -1,378 +0,0 @@
# coding: UTF-8
import sys
import os
import ConfigParser
import glob
HAS_MYSQLDB = True
try:
import MySQLdb
except ImportError:
HAS_MYSQLDB = False
HAS_SQLITE3 = True
try:
import sqlite3
except ImportError:
HAS_SQLITE3 = False
class EnvManager(object):
def __init__(self):
self.upgrade_dir = os.path.dirname(__file__)
self.install_path = os.path.dirname(self.upgrade_dir)
self.top_dir = os.path.dirname(self.install_path)
self.ccnet_dir = os.environ['CCNET_CONF_DIR']
self.seafile_dir = os.environ['SEAFILE_CONF_DIR']
self.central_config_dir = os.environ.get('SEAFILE_CENTRAL_CONF_DIR')
env_mgr = EnvManager()
class Utils(object):
@staticmethod
def highlight(content, is_error=False):
'''Add ANSI color to content to get it highlighted on terminal'''
if is_error:
return '\x1b[1;31m%s\x1b[m' % content
else:
return '\x1b[1;32m%s\x1b[m' % content
@staticmethod
def info(msg):
print Utils.highlight('[INFO] ') + msg
@staticmethod
def warning(msg):
print Utils.highlight('[WARNING] ') + msg
@staticmethod
def error(msg):
print Utils.highlight('[ERROR] ') + msg
sys.exit(1)
@staticmethod
def read_config(config_path, defaults):
if not os.path.exists(config_path):
Utils.error('Config path %s doesn\'t exist, stop db upgrade' %
config_path)
cp = ConfigParser.ConfigParser(defaults)
cp.read(config_path)
return cp
class MySQLDBInfo(object):
def __init__(self, host, port, username, password, db, unix_socket=None):
self.host = host
self.port = port
self.username = username
self.password = password
self.db = db
self.unix_socket = unix_socket
class DBUpdater(object):
def __init__(self, version, name):
self.sql_dir = os.path.join(env_mgr.upgrade_dir, 'sql', version, name)
pro_path = os.path.join(env_mgr.install_path, 'pro')
self.is_pro = os.path.exists(pro_path)
@staticmethod
def get_instance(version):
'''Detect whether we are using mysql or sqlite3'''
ccnet_db_info = DBUpdater.get_ccnet_mysql_info(version)
seafile_db_info = DBUpdater.get_seafile_mysql_info(version)
seahub_db_info = DBUpdater.get_seahub_mysql_info()
if ccnet_db_info and seafile_db_info and seahub_db_info:
Utils.info('You are using MySQL')
if not HAS_MYSQLDB:
Utils.error('Python MySQLdb module is not found')
updater = MySQLDBUpdater(version, ccnet_db_info, seafile_db_info, seahub_db_info)
elif (ccnet_db_info is None) and (seafile_db_info is None) and (seahub_db_info is None):
Utils.info('You are using SQLite3')
if not HAS_SQLITE3:
Utils.error('Python sqlite3 module is not found')
updater = SQLiteDBUpdater(version)
else:
def to_db_string(info):
if info is None:
return 'SQLite3'
else:
return 'MySQL'
Utils.error('Error:\n ccnet is using %s\n seafile is using %s\n seahub is using %s\n'
% (to_db_string(ccnet_db_info),
to_db_string(seafile_db_info),
to_db_string(seahub_db_info)))
return updater
def update_db(self):
ccnet_sql = os.path.join(self.sql_dir, 'ccnet.sql')
seafile_sql = os.path.join(self.sql_dir, 'seafile.sql')
seahub_sql = os.path.join(self.sql_dir, 'seahub.sql')
seafevents_sql = os.path.join(self.sql_dir, 'seafevents.sql')
if os.path.exists(ccnet_sql):
Utils.info('updating ccnet database...')
self.update_ccnet_sql(ccnet_sql)
if os.path.exists(seafile_sql):
Utils.info('updating seafile database...')
self.update_seafile_sql(seafile_sql)
if os.path.exists(seahub_sql):
Utils.info('updating seahub database...')
self.update_seahub_sql(seahub_sql)
if os.path.exists(seafevents_sql):
self.update_seafevents_sql(seafevents_sql)
@staticmethod
def get_ccnet_mysql_info(version):
config_path = env_mgr.central_config_dir
ccnet_conf = os.path.join(config_path, 'ccnet.conf')
defaults = {
'HOST': '127.0.0.1',
'PORT': '3306',
'UNIX_SOCKET': '',
}
config = Utils.read_config(ccnet_conf, defaults)
db_section = 'Database'
if not config.has_section(db_section):
return None
type = config.get(db_section, 'ENGINE')
if type != 'mysql':
return None
try:
host = config.get(db_section, 'HOST')
port = config.getint(db_section, 'PORT')
username = config.get(db_section, 'USER')
password = config.get(db_section, 'PASSWD')
db = config.get(db_section, 'DB')
unix_socket = config.get(db_section, 'UNIX_SOCKET')
except ConfigParser.NoOptionError, e:
Utils.error('Database config in ccnet.conf is invalid: %s' % e)
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
return info
@staticmethod
def get_seafile_mysql_info(version):
config_path = env_mgr.central_config_dir
seafile_conf = os.path.join(config_path, 'seafile.conf')
defaults = {
'HOST': '127.0.0.1',
'PORT': '3306',
'UNIX_SOCKET': '',
}
config = Utils.read_config(seafile_conf, defaults)
db_section = 'database'
if not config.has_section(db_section):
return None
type = config.get(db_section, 'type')
if type != 'mysql':
return None
try:
host = config.get(db_section, 'host')
port = config.getint(db_section, 'port')
username = config.get(db_section, 'user')
password = config.get(db_section, 'password')
db = config.get(db_section, 'db_name')
unix_socket = config.get(db_section, 'unix_socket')
except ConfigParser.NoOptionError, e:
Utils.error('Database config in seafile.conf is invalid: %s' % e)
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
return info
@staticmethod
def get_seahub_mysql_info():
sys.path.insert(0, env_mgr.top_dir)
if env_mgr.central_config_dir:
sys.path.insert(0, env_mgr.central_config_dir)
try:
import seahub_settings # pylint: disable=F0401
except ImportError, e:
Utils.error('Failed to import seahub_settings.py: %s' % e)
if not hasattr(seahub_settings, 'DATABASES'):
return None
try:
d = seahub_settings.DATABASES['default']
if d['ENGINE'] != 'django.db.backends.mysql':
return None
host = d.get('HOST', '127.0.0.1')
port = int(d.get('PORT', 3306))
username = d['USER']
password = d['PASSWORD']
db = d['NAME']
unix_socket = host if host.startswith('/') else None
except KeyError:
Utils.error('Database config in seahub_settings.py is invalid: %s' % e)
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
return info
def update_ccnet_sql(self, ccnet_sql):
raise NotImplementedError
def update_seafile_sql(self, seafile_sql):
raise NotImplementedError
def update_seahub_sql(self, seahub_sql):
raise NotImplementedError
def update_seafevents_sql(self, seafevents_sql):
raise NotImplementedError
class CcnetSQLiteDB(object):
def __init__(self, ccnet_dir):
self.ccnet_dir = ccnet_dir
def get_db(self, dbname):
dbs = (
'ccnet.db',
'GroupMgr/groupmgr.db',
'misc/config.db',
'OrgMgr/orgmgr.db',
'PeerMgr/usermgr.db',
)
for db in dbs:
if os.path.splitext(os.path.basename(db))[0] == dbname:
return os.path.join(self.ccnet_dir, db)
class SQLiteDBUpdater(DBUpdater):
def __init__(self, version):
DBUpdater.__init__(self, version, 'sqlite3')
self.ccnet_db = CcnetSQLiteDB(env_mgr.ccnet_dir)
self.seafile_db = os.path.join(env_mgr.seafile_dir, 'seafile.db')
self.seahub_db = os.path.join(env_mgr.top_dir, 'seahub.db')
self.seafevents_db = os.path.join(env_mgr.top_dir, 'seafevents.db')
def update_db(self):
super(SQLiteDBUpdater, self).update_db()
for sql_path in glob.glob(os.path.join(self.sql_dir, 'ccnet', '*.sql')):
self.update_ccnet_sql(sql_path)
def apply_sqls(self, db_path, sql_path):
with open(sql_path, 'r') as fp:
lines = fp.read().split(';')
with sqlite3.connect(db_path) as conn:
for line in lines:
line = line.strip()
if not line:
continue
else:
conn.execute(line)
def update_ccnet_sql(self, sql_path):
dbname = os.path.splitext(os.path.basename(sql_path))[0]
self.apply_sqls(self.ccnet_db.get_db(dbname), sql_path)
def update_seafile_sql(self, sql_path):
self.apply_sqls(self.seafile_db, sql_path)
def update_seahub_sql(self, sql_path):
self.apply_sqls(self.seahub_db, sql_path)
def update_seafevents_sql(self, sql_path):
if self.is_pro:
Utils.info('seafevents do not support sqlite3 database')
class MySQLDBUpdater(DBUpdater):
def __init__(self, version, ccnet_db_info, seafile_db_info, seahub_db_info):
DBUpdater.__init__(self, version, 'mysql')
self.ccnet_db_info = ccnet_db_info
self.seafile_db_info = seafile_db_info
self.seahub_db_info = seahub_db_info
def update_ccnet_sql(self, ccnet_sql):
self.apply_sqls(self.ccnet_db_info, ccnet_sql)
def update_seafile_sql(self, seafile_sql):
self.apply_sqls(self.seafile_db_info, seafile_sql)
def update_seahub_sql(self, seahub_sql):
self.apply_sqls(self.seahub_db_info, seahub_sql)
def update_seafevents_sql(self, seafevents_sql):
if self.is_pro:
Utils.info('updating seafevents database...')
self.apply_sqls(self.seahub_db_info, seafevents_sql)
def get_conn(self, info):
kw = dict(
user=info.username,
passwd=info.password,
db=info.db,
)
if info.unix_socket:
kw['unix_socket'] = info.unix_socket
else:
kw['host'] = info.host
kw['port'] = info.port
try:
conn = MySQLdb.connect(**kw)
except Exception, e:
if isinstance(e, MySQLdb.OperationalError):
msg = str(e.args[1])
else:
msg = str(e)
Utils.error('Failed to connect to mysql database %s: %s' % (info.db, msg))
return conn
def execute_sql(self, conn, sql):
cursor = conn.cursor()
try:
cursor.execute(sql)
conn.commit()
except Exception, e:
msg = str(e)
Utils.warning('Failed to execute sql: %s' % msg)
def apply_sqls(self, info, sql_path):
with open(sql_path, 'r') as fp:
lines = fp.read().split(';')
conn = self.get_conn(info)
for line in lines:
line = line.strip()
if not line:
continue
else:
self.execute_sql(conn, line)
def main():
skipdb = os.environ.get('SEAFILE_SKIP_DB_UPGRADE', '').lower()
if skipdb in ('1', 'true', 'on'):
print 'Database upgrade skipped because SEAFILE_SKIP_DB_UPGRADE=%s' % skipdb
sys.exit()
version = sys.argv[1]
db_updater = DBUpdater.get_instance(version)
db_updater.update_db()
return 0
if __name__ == '__main__':
main()

View File

@ -1,115 +0,0 @@
#!/bin/bash
SCRIPT=$(readlink -f "$0") # haiwen/seafile-server-1.3.0/upgrade/upgrade_xx_xx.sh
UPGRADE_DIR=$(dirname "$SCRIPT") # haiwen/seafile-server-1.3.0/upgrade/
INSTALLPATH=$(dirname "$UPGRADE_DIR") # haiwen/seafile-server-1.3.0/
TOPDIR=$(dirname "${INSTALLPATH}") # haiwen/
echo
echo "-------------------------------------------------------------"
echo "This script would do the minor upgrade for you."
echo "Press [ENTER] to contiune"
echo "-------------------------------------------------------------"
echo
read dummy
media_dir=${INSTALLPATH}/seahub/media
orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
seafile_server_symlink=${TOPDIR}/seafile-server-latest
seahub_data_dir=${TOPDIR}/seahub-data
function migrate_avatars() {
echo
echo "------------------------------"
echo "migrating avatars ..."
echo
# move "media/avatars" directory outside
if [[ ! -d ${dest_avatar_dir} ]]; then
echo
echo "Error: avatars directory \"${dest_avatar_dir}\" does not exist" 2>&1
echo
exit 1
elif [[ ! -L ${orig_avatar_dir} ]]; then
mv "${orig_avatar_dir}"/* "${dest_avatar_dir}" 2>/dev/null 1>&2
rm -rf "${orig_avatar_dir}"
ln -s ../../../seahub-data/avatars "${media_dir}"
fi
echo
echo "DONE"
echo "------------------------------"
echo
}
function make_media_custom_symlink() {
media_symlink=${INSTALLPATH}/seahub/media/custom
if [[ -L "${media_symlink}" ]]; then
return
elif [[ ! -e "${media_symlink}" ]]; then
ln -s ../../../seahub-data/custom "${media_symlink}"
return
elif [[ -d "${media_symlink}" ]]; then
cp -rf "${media_symlink}" "${seahub_data_dir}/"
rm -rf "${media_symlink}"
ln -s ../../../seahub-data/custom "${media_symlink}"
fi
}
function move_old_customdir_outside() {
# find the path of the latest seafile server folder
if [[ -L ${seafile_server_symlink} ]]; then
latest_server=$(readlink -f "${seafile_server_symlink}")
else
return
fi
old_customdir=${latest_server}/seahub/media/custom
# old customdir is already a symlink, do nothing
if [[ -L "${old_customdir}" ]]; then
return
fi
# old customdir does not exist, do nothing
if [[ ! -e "${old_customdir}" ]]; then
return
fi
# media/custom exist and is not a symlink
cp -rf "${old_customdir}" "${seahub_data_dir}/"
}
function update_latest_symlink() {
# update the symlink seafile-server to the new server version
echo
echo "updating seafile-server-latest symbolic link to ${INSTALLPATH} ..."
echo
if ! rm -f "${seafile_server_symlink}"; then
echo "Failed to remove ${seafile_server_symlink}"
echo
exit 1;
fi
if ! ln -s "$(basename ${INSTALLPATH})" "${seafile_server_symlink}"; then
echo "Failed to update ${seafile_server_symlink} symbolic link."
echo
exit 1;
fi
}
migrate_avatars;
move_old_customdir_outside;
make_media_custom_symlink;
update_latest_symlink;
echo "DONE"
echo "------------------------------"
echo

View File

@ -1,58 +0,0 @@
ALTER TABLE `file_tags_filetags` DROP FOREIGN KEY `file_tags_filetags_parent_folder_uuid_i_df56f09b_fk_tags_file`;
ALTER TABLE `file_tags_filetags` DROP `parent_folder_uuid_id`;
DROP TABLE drafts_reviewcomment;
DROP TABLE drafts_reviewreviewer;
DROP TABLE drafts_draftreview;
DROP TABLE drafts_draft;
CREATE TABLE IF NOT EXISTS `drafts_draft` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created_at` datetime(6) NOT NULL,
`updated_at` datetime(6) NOT NULL,
`username` varchar(255) NOT NULL,
`origin_repo_id` varchar(36) NOT NULL,
`origin_file_version` varchar(100) NOT NULL,
`draft_file_path` varchar(1024) NOT NULL,
`origin_file_uuid` char(32) NOT NULL,
`publish_file_version` varchar(100) DEFAULT NULL,
`status` varchar(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `drafts_draft_origin_file_uuid_id_f150319e_fk_tags_file` (`origin_file_uuid`),
KEY `drafts_draft_created_at_e9f4523f` (`created_at`),
KEY `drafts_draft_updated_at_0a144b05` (`updated_at`),
KEY `drafts_draft_username_73e6738b` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `drafts_draftreviewer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`reviewer` varchar(255) NOT NULL,
`draft_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `drafts_draftreviewer_reviewer_e4c777ac` (`reviewer`),
KEY `drafts_draftreviewer_draft_id_4ea59775_fk_drafts_draft_id` (`draft_id`),
CONSTRAINT `drafts_draftreviewer_draft_id_4ea59775_fk_drafts_draft_id` FOREIGN KEY (`draft_id`) REFERENCES `drafts_draft` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `organizations_orgsettings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`org_id` int(11) NOT NULL,
`role` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `organizations_orgsettings_org_id_630f6843_uniq` (`org_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP INDEX `profile_profile_contact_email_0975e4bf_uniq` ON `profile_profile`;
ALTER TABLE `profile_profile` ADD CONSTRAINT `profile_profile_contact_email_0975e4bf_uniq` UNIQUE (`contact_email`);
CREATE TABLE IF NOT EXISTS `social_auth_usersocialauth` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`provider` varchar(32) NOT NULL,
`uid` varchar(150) NOT NULL,
`extra_data` longtext NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `social_auth_usersocialauth_provider_uid_e6b5e668_uniq` (`provider`,`uid`),
KEY `social_auth_usersocialauth_username_3f06b5cf` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -1 +0,0 @@
ALTER TABLE RepoInfo ADD COLUMN status INTEGER DEFAULT 0;

View File

@ -1,239 +0,0 @@
#!/bin/bash
SCRIPT=$(readlink -f "$0") # haiwen/seafile-server-1.3.0/upgrade/upgrade_xx_xx.sh
UPGRADE_DIR=$(dirname "$SCRIPT") # haiwen/seafile-server-1.3.0/upgrade/
INSTALLPATH=$(dirname "$UPGRADE_DIR") # haiwen/seafile-server-1.3.0/
TOPDIR=$(dirname "${INSTALLPATH}") # haiwen/
default_ccnet_conf_dir=${TOPDIR}/ccnet
default_conf_dir=${TOPDIR}/conf
default_pids_dir=${TOPDIR}/pids
default_logs_dir=${TOPDIR}/logs
seafile_server_symlink=${TOPDIR}/seafile-server-latest
seahub_data_dir=${TOPDIR}/seahub-data
seahub_settings_py=${TOPDIR}/seahub_settings.py
manage_py=${INSTALLPATH}/seahub/manage.py
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
export SEAFILE_CENTRAL_CONF_DIR=${default_conf_dir}
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
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seafile/lib64/python2.7/site-packages:$PYTHONPATH
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
prev_version=1.0
current_version=1.1
echo
echo "-------------------------------------------------------------"
echo "This script would upgrade your seafile server from ${prev_version} to ${current_version}"
echo "Press [ENTER] to contiune"
echo "-------------------------------------------------------------"
echo
read dummy
function check_python_executable() {
if [[ "$PYTHON" != "" && -x $PYTHON ]]; then
return 0
fi
if which python2.7 2>/dev/null 1>&2; then
PYTHON=python2.7
elif which python27 2>/dev/null 1>&2; then
PYTHON=python27
else
echo
echo "Can't find a python executable of version 2.7 or above in PATH"
echo "Install python 2.7+ before continue."
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
echo
exit 1
fi
}
function read_seafile_data_dir () {
seafile_ini=${default_ccnet_conf_dir}/seafile.ini
if [[ ! -f ${seafile_ini} ]]; then
echo "${seafile_ini} not found. Now quit"
exit 1
fi
seafile_data_dir=$(cat "${seafile_ini}")
if [[ ! -d ${seafile_data_dir} ]]; then
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
echo "Please check it first, or create this directory yourself."
echo ""
exit 1;
fi
export SEAFILE_CONF_DIR=$seafile_data_dir
}
function ensure_server_not_running() {
# test whether seafile server has been stopped.
if pgrep seaf-server 2>/dev/null 1>&2 ; then
echo
echo "seafile server is still running !"
echo "stop it using scripts before upgrade."
echo
exit 1
elif pgrep -f "${manage_py} run_gunicorn" 2>/dev/null 1>&2 \
|| pgrep -f "seahub.wsgi:application" 2>/dev/null 1>&2; then
echo
echo "seahub server is still running !"
echo "stop it before upgrade."
echo
exit 1
elif pgrep -f "${manage_py} runfcgi" 2>/dev/null 1>&2 ; then
echo
echo "seahub server is still running !"
echo "stop it before upgrade."
echo
exit 1
fi
}
function migrate_avatars() {
echo
echo "migrating avatars ..."
echo
media_dir=${INSTALLPATH}/seahub/media
orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
# move "media/avatars" directory outside
if [[ ! -d ${dest_avatar_dir} ]]; then
mkdir -p "${TOPDIR}/seahub-data"
mv "${orig_avatar_dir}" "${dest_avatar_dir}" 2>/dev/null 1>&2
ln -s ../../../seahub-data/avatars "${media_dir}"
elif [[ ! -L ${orig_avatar_dir} ]]; then
mv "${orig_avatar_dir}"/* "${dest_avatar_dir}" 2>/dev/null 1>&2
rm -rf "${orig_avatar_dir}"
ln -s ../../../seahub-data/avatars "${media_dir}"
fi
echo "Done"
}
function update_database() {
echo
echo "Updating seafile/seahub database ..."
echo
db_update_helper=${UPGRADE_DIR}/db_update_helper.py
if ! $PYTHON "${db_update_helper}" 1.1.0; then
echo
echo "Failed to upgrade your database"
echo
exit 1
fi
echo "Done"
}
function upgrade_seafile_server_latest_symlink() {
# update the symlink seafile-server to the new server version
if [[ -L "${seafile_server_symlink}" || ! -e "${seafile_server_symlink}" ]]; then
echo
printf "updating \033[33m${seafile_server_symlink}\033[m symbolic link to \033[33m${INSTALLPATH}\033[m ...\n\n"
echo
if ! rm -f "${seafile_server_symlink}"; then
echo "Failed to remove ${seafile_server_symlink}"
echo
exit 1;
fi
if ! ln -s "$(basename ${INSTALLPATH})" "${seafile_server_symlink}"; then
echo "Failed to update ${seafile_server_symlink} symbolic link."
echo
exit 1;
fi
fi
}
function make_media_custom_symlink() {
media_symlink=${INSTALLPATH}/seahub/media/custom
if [[ -L "${media_symlink}" ]]; then
return
elif [[ ! -e "${media_symlink}" ]]; then
ln -s ../../../seahub-data/custom "${media_symlink}"
return
elif [[ -d "${media_symlink}" ]]; then
cp -rf "${media_symlink}" "${seahub_data_dir}/"
rm -rf "${media_symlink}"
ln -s ../../../seahub-data/custom "${media_symlink}"
fi
}
function move_old_customdir_outside() {
# find the path of the latest seafile server folder
if [[ -L ${seafile_server_symlink} ]]; then
latest_server=$(readlink -f "${seafile_server_symlink}")
else
return
fi
old_customdir=${latest_server}/seahub/media/custom
# old customdir is already a symlink, do nothing
if [[ -L "${old_customdir}" ]]; then
return
fi
# old customdir does not exist, do nothing
if [[ ! -e "${old_customdir}" ]]; then
return
fi
# media/custom exist and is not a symlink
cp -rf "${old_customdir}" "${seahub_data_dir}/"
}
function add_gunicorn_conf() {
gunicorn_conf=${default_conf_dir}/gunicorn.conf
if ! $(cat > ${gunicorn_conf} <<EOF
import os
daemon = True
workers = 5
# default localhost:8000
bind = "127.0.0.1:8000"
# Pid
pids_dir = '$default_pids_dir'
pidfile = os.path.join(pids_dir, 'seahub.pid')
# for file upload, we need a longer timeout value (default is only 30s, too short)
timeout = 1200
limit_request_line = 8190
EOF
); then
echo "failed to generate gunicorn.conf";
fi
}
#################
# The main execution flow of the script
################
check_python_executable;
read_seafile_data_dir;
ensure_server_not_running;
update_database;
migrate_avatars;
move_old_customdir_outside;
make_media_custom_symlink;
upgrade_seafile_server_latest_symlink;
add_gunicorn_conf;
echo
echo "-----------------------------------------------------------------"
echo "Upgraded your seafile server successfully."
echo "-----------------------------------------------------------------"
echo

View File

@ -1,239 +0,0 @@
#!/bin/bash
SCRIPT=$(readlink -f "$0") # haiwen/seafile-server-1.3.0/upgrade/upgrade_xx_xx.sh
UPGRADE_DIR=$(dirname "$SCRIPT") # haiwen/seafile-server-1.3.0/upgrade/
INSTALLPATH=$(dirname "$UPGRADE_DIR") # haiwen/seafile-server-1.3.0/
TOPDIR=$(dirname "${INSTALLPATH}") # haiwen/
default_ccnet_conf_dir=${TOPDIR}/ccnet
default_conf_dir=${TOPDIR}/conf
default_pids_dir=${TOPDIR}/pids
default_logs_dir=${TOPDIR}/logs
seafile_server_symlink=${TOPDIR}/seafile-server-latest
seahub_data_dir=${TOPDIR}/seahub-data
seahub_settings_py=${TOPDIR}/seahub_settings.py
manage_py=${INSTALLPATH}/seahub/manage.py
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
export SEAFILE_CENTRAL_CONF_DIR=${default_conf_dir}
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
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seafile/lib64/python2.7/site-packages:$PYTHONPATH
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
prev_version=1.1
current_version=1.2
echo
echo "-------------------------------------------------------------"
echo "This script would upgrade your seafile server from ${prev_version} to ${current_version}"
echo "Press [ENTER] to contiune"
echo "-------------------------------------------------------------"
echo
read dummy
function check_python_executable() {
if [[ "$PYTHON" != "" && -x $PYTHON ]]; then
return 0
fi
if which python2.7 2>/dev/null 1>&2; then
PYTHON=python2.7
elif which python27 2>/dev/null 1>&2; then
PYTHON=python27
else
echo
echo "Can't find a python executable of version 2.7 or above in PATH"
echo "Install python 2.7+ before continue."
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
echo
exit 1
fi
}
function read_seafile_data_dir () {
seafile_ini=${default_ccnet_conf_dir}/seafile.ini
if [[ ! -f ${seafile_ini} ]]; then
echo "${seafile_ini} not found. Now quit"
exit 1
fi
seafile_data_dir=$(cat "${seafile_ini}")
if [[ ! -d ${seafile_data_dir} ]]; then
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
echo "Please check it first, or create this directory yourself."
echo ""
exit 1;
fi
export SEAFILE_CONF_DIR=$seafile_data_dir
}
function ensure_server_not_running() {
# test whether seafile server has been stopped.
if pgrep seaf-server 2>/dev/null 1>&2 ; then
echo
echo "seafile server is still running !"
echo "stop it using scripts before upgrade."
echo
exit 1
elif pgrep -f "${manage_py} run_gunicorn" 2>/dev/null 1>&2 \
|| pgrep -f "seahub.wsgi:application" 2>/dev/null 1>&2; then
echo
echo "seahub server is still running !"
echo "stop it before upgrade."
echo
exit 1
elif pgrep -f "${manage_py} runfcgi" 2>/dev/null 1>&2 ; then
echo
echo "seahub server is still running !"
echo "stop it before upgrade."
echo
exit 1
fi
}
function migrate_avatars() {
echo
echo "migrating avatars ..."
echo
media_dir=${INSTALLPATH}/seahub/media
orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
# move "media/avatars" directory outside
if [[ ! -d ${dest_avatar_dir} ]]; then
mkdir -p "${TOPDIR}/seahub-data"
mv "${orig_avatar_dir}" "${dest_avatar_dir}" 2>/dev/null 1>&2
ln -s ../../../seahub-data/avatars "${media_dir}"
elif [[ ! -L ${orig_avatar_dir} ]]; then
mv "${orig_avatar_dir}"/* "${dest_avatar_dir}" 2>/dev/null 1>&2
rm -rf "${orig_avatar_dir}"
ln -s ../../../seahub-data/avatars "${media_dir}"
fi
echo "Done"
}
function update_database() {
echo
echo "Updating seafile/seahub database ..."
echo
db_update_helper=${UPGRADE_DIR}/db_update_helper.py
if ! $PYTHON "${db_update_helper}" 1.2.0; then
echo
echo "Failed to upgrade your database"
echo
exit 1
fi
echo "Done"
}
function upgrade_seafile_server_latest_symlink() {
# update the symlink seafile-server to the new server version
if [[ -L "${seafile_server_symlink}" || ! -e "${seafile_server_symlink}" ]]; then
echo
printf "updating \033[33m${seafile_server_symlink}\033[m symbolic link to \033[33m${INSTALLPATH}\033[m ...\n\n"
echo
if ! rm -f "${seafile_server_symlink}"; then
echo "Failed to remove ${seafile_server_symlink}"
echo
exit 1;
fi
if ! ln -s "$(basename ${INSTALLPATH})" "${seafile_server_symlink}"; then
echo "Failed to update ${seafile_server_symlink} symbolic link."
echo
exit 1;
fi
fi
}
function make_media_custom_symlink() {
media_symlink=${INSTALLPATH}/seahub/media/custom
if [[ -L "${media_symlink}" ]]; then
return
elif [[ ! -e "${media_symlink}" ]]; then
ln -s ../../../seahub-data/custom "${media_symlink}"
return
elif [[ -d "${media_symlink}" ]]; then
cp -rf "${media_symlink}" "${seahub_data_dir}/"
rm -rf "${media_symlink}"
ln -s ../../../seahub-data/custom "${media_symlink}"
fi
}
function move_old_customdir_outside() {
# find the path of the latest seafile server folder
if [[ -L ${seafile_server_symlink} ]]; then
latest_server=$(readlink -f "${seafile_server_symlink}")
else
return
fi
old_customdir=${latest_server}/seahub/media/custom
# old customdir is already a symlink, do nothing
if [[ -L "${old_customdir}" ]]; then
return
fi
# old customdir does not exist, do nothing
if [[ ! -e "${old_customdir}" ]]; then
return
fi
# media/custom exist and is not a symlink
cp -rf "${old_customdir}" "${seahub_data_dir}/"
}
function add_gunicorn_conf() {
gunicorn_conf=${default_conf_dir}/gunicorn.conf
if ! $(cat > ${gunicorn_conf} <<EOF
import os
daemon = True
workers = 5
# default localhost:8000
bind = "127.0.0.1:8000"
# Pid
pids_dir = '$default_pids_dir'
pidfile = os.path.join(pids_dir, 'seahub.pid')
# for file upload, we need a longer timeout value (default is only 30s, too short)
timeout = 1200
limit_request_line = 8190
EOF
); then
echo "failed to generate gunicorn.conf";
fi
}
#################
# The main execution flow of the script
################
check_python_executable;
read_seafile_data_dir;
ensure_server_not_running;
update_database;
migrate_avatars;
move_old_customdir_outside;
make_media_custom_symlink;
upgrade_seafile_server_latest_symlink;
add_gunicorn_conf;
echo
echo "-----------------------------------------------------------------"
echo "Upgraded your seafile server successfully."
echo "-----------------------------------------------------------------"
echo

13
scripts/upgrade/minor-upgrade.sh Executable file → Normal file
View File

@ -18,6 +18,7 @@ orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
seafile_server_symlink=${TOPDIR}/seafile-server-latest
seahub_data_dir=${TOPDIR}/seahub-data
elasticsearch_config_file=${seafile_server_symlink}/pro/elasticsearch/config/jvm.options
function migrate_avatars() {
echo
@ -102,11 +103,23 @@ function update_latest_symlink() {
fi
}
function move_old_elasticsearch_config_to_latest() {
# Move the elasticsearch's configuration file from the old version to the new version
echo
echo "Moving the elasticsearch's configuration file ..."
echo
if [[ -f ${elasticsearch_config_file} ]]; then
/bin/cp -avf ${elasticsearch_config_file} ${INSTALLPATH}/pro/elasticsearch/config/jvm.options
fi
}
migrate_avatars;
move_old_customdir_outside;
make_media_custom_symlink;
move_old_elasticsearch_config_to_latest;
update_latest_symlink;