From f7007d41faaca662a09d229e179b3cf6f9c15ea6 Mon Sep 17 00:00:00 2001 From: Jiaqiang Xu Date: Fri, 16 May 2014 15:24:06 +0800 Subject: [PATCH 1/4] Improve object and block writting performance. --- common/block-backend-fs.c | 5 +++++ common/obj-backend-fs.c | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/common/block-backend-fs.c b/common/block-backend-fs.c index b74abf22..63a18446 100644 --- a/common/block-backend-fs.c +++ b/common/block-backend-fs.c @@ -141,6 +141,11 @@ create_parent_path (const char *path) if (!dir) return -1; + if (g_file_test (dir, G_FILE_TEST_EXISTS)) { + g_free (dir); + return 0; + } + if (g_mkdir_with_parents (dir, 0777) < 0) { seaf_warning ("Failed to create object parent path: %s.\n", dir); g_free (dir); diff --git a/common/obj-backend-fs.c b/common/obj-backend-fs.c index ed890cb7..6022b085 100644 --- a/common/obj-backend-fs.c +++ b/common/obj-backend-fs.c @@ -266,6 +266,11 @@ create_parent_path (const char *path) if (!dir) return -1; + if (g_file_test (dir, G_FILE_TEST_EXISTS)) { + g_free (dir); + return 0; + } + if (g_mkdir_with_parents (dir, 0777) < 0) { seaf_warning ("Failed to create object parent path: %s.\n", dir); g_free (dir); @@ -289,15 +294,15 @@ obj_backend_fs_write (ObjBackend *bend, id_to_path (bend->priv, obj_id, path, repo_id, version); + /* GTimeVal s, e; */ + + /* g_get_current_time (&s); */ + if (create_parent_path (path) < 0) { seaf_warning ("[obj backend] Failed to create path for obj %s.\n", obj_id); return -1; } - /* GTimeVal s, e; */ - - /* g_get_current_time (&s); */ - if (save_obj_contents (path, data, len, need_sync) < 0) { seaf_warning ("[obj backend] Failed to write obj %s.\n", obj_id); return -1; @@ -305,8 +310,8 @@ obj_backend_fs_write (ObjBackend *bend, /* g_get_current_time (&e); */ - /* seaf_message ("write obj time: %ldms.\n", */ - /* ((e.tv_sec*1000000+e.tv_usec) - (s.tv_sec*1000000+s.tv_usec))/1000); */ + /* seaf_message ("write obj time: %ldus.\n", */ + /* ((e.tv_sec*1000000+e.tv_usec) - (s.tv_sec*1000000+s.tv_usec))); */ return 0; } From 08b639fa046d01e4e56e13b5a7e22c9d5cc75343 Mon Sep 17 00:00:00 2001 From: lins05 Date: Mon, 19 May 2014 11:37:40 +0800 Subject: [PATCH 2/4] [scripts] show error detail when gunicorn failed to start --- scripts/seahub.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/seahub.sh b/scripts/seahub.sh index 17b391a7..4220878d 100755 --- a/scripts/seahub.sh +++ b/scripts/seahub.sh @@ -161,7 +161,7 @@ function start_seahub () { before_start; echo "Starting seahub at port ${port} ..." check_init_admin; - $PYTHON "${manage_py}" run_gunicorn -c "${gunicorn_conf}" -b "0.0.0.0:${port}" + $PYTHON "${manage_py}" run_gunicorn -c "${gunicorn_conf}" -b "0.0.0.0:${port}" --preload # Ensure seahub is started successfully sleep 5 From 793fe6c2b865e8634cc77b7abec2e66cdbcc1bc4 Mon Sep 17 00:00:00 2001 From: poetwang Date: Wed, 21 May 2014 10:38:20 +0800 Subject: [PATCH 3/4] v3.0.4 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d7782747..120f2bc5 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT([seafile], [3.0.2], [freeplant@gmail.com]) +AC_INIT([seafile], [3.0.4], [freeplant@gmail.com]) AC_CONFIG_HEADER([config.h]) AC_CONFIG_MACRO_DIR([m4]) From b598f82ca5c95b3f25115dca39a0b79b67aa7e1d Mon Sep 17 00:00:00 2001 From: lins05 Date: Wed, 21 May 2014 17:37:19 +0800 Subject: [PATCH 4/4] [scripts] fixed creating admin account in seafile-admin --- tools/seafile-admin | 171 ++++++-------------------------------------- 1 file changed, 23 insertions(+), 148 deletions(-) diff --git a/tools/seafile-admin b/tools/seafile-admin index e127d555..e6257675 100755 --- a/tools/seafile-admin +++ b/tools/seafile-admin @@ -22,10 +22,7 @@ import re import shutil import subprocess import argparse -import sqlite3 import uuid -import hashlib -import getpass try: import readline @@ -433,79 +430,6 @@ accesslog = os.path.join(runtime_dir, 'access.log') except: error('Failed to write seahub config') -def get_admin_email_password(): - info('') - info("Now let\'s create the admin account of seahub") - info('') - def validate(email): - # whitespace is not allowed - if re.match(r'[\s]', email): - return False - # must be a valid email address - if not re.match(r'^.+@.*\..+$', email): - return False - return True - - key = 'admin email' - question = 'What is the ' + highlight('email') + ' for the admin account' - admin_email = ask_question(question, - key=key, - validate=validate) - - key = 'admin password' - question = 'What is the ' + highlight('password') + ' for the admin account' - admin_password = ask_question(question, - key=key) - - key = 'admin password again' - question = 'Enter the password again' - invalidate_msg = 'Password mismatch' - def validate_again(password): - return password == admin_password - ask_question(question, - key=key, - validate=validate_again, - invalidate_msg=invalidate_msg) - - info('This is your admin account email/password:\n') - info('------------------------------------------') - info('admin email: %s' % admin_email) - info('admin password: %s' % admin_password) - info('------------------------------------------') - info('Press ENTER if the config is right, or anything else to re-config admin account') - - if raw_input() != '': - get_admin_email_password() - else: - sha1 = hashlib.sha1(admin_password) - conf[CONF_ADMIN_EMAIL] = admin_email - conf[CONF_ADMIN_PASSWORD] = sha1.hexdigest() - -def create_seahub_admin(): - - peermgr_dir = os.path.join(conf[CONF_CCNET_DIR], 'PeerMgr') - usermgr_db = os.path.join(peermgr_dir, 'usermgr.db') - - if os.path.exists(usermgr_db): - return - - if not os.path.exists(peermgr_dir): - os.mkdir(peermgr_dir) - - get_admin_email_password() - - conn = sqlite3.connect(usermgr_db) - c = conn.cursor() - - sql = 'CREATE TABLE IF NOT EXISTS EmailUser (id INTEGER NOT NULL PRIMARY KEY, email TEXT, passwd TEXT, is_staff bool NOT NULL, is_active bool NOT NULL, ctime INTEGER)' - c.execute(sql) - sql = r'INSERT INTO EmailUser(email, passwd, is_staff, is_active, ctime) VALUES ("%s", "%s", 1, 1, 0)' \ - % (conf[CONF_ADMIN_EMAIL], conf[CONF_ADMIN_PASSWORD]) - c.execute(sql) - conn.commit() - - info('Successfully created your admin account') - def gen_seahub_secret_key(): data = str(uuid.uuid4()) + str(uuid.uuid4()) return data[:40] @@ -555,7 +479,6 @@ def init_seahub(): info('done') - create_seahub_admin() move_avatar() create_gunicorn_conf() @@ -739,7 +662,7 @@ def read_seafile_data_dir(ccnet_conf_dir): return seafile_data_dir -def check_config(args): +def check_layout(args): def error_not_found(path): error('%s not found' % path) ccnet_conf_dir = os.path.join(cwd, 'ccnet') @@ -767,6 +690,17 @@ def check_config(args): if not os.path.exists(seahub_conf): error_not_found(seahub_dir) + conf[CONF_CCNET_DIR] = ccnet_conf_dir + conf[CONF_SEAFILE_DIR] = seafile_data_dir + conf[CONF_SEAHUB_DIR] = seahub_dir + conf[CONF_SEAHUB_CONF] = seahub_conf + conf[CONF_SEAHUB_PIDFILE] = os.path.join(runtime_dir, 'seahub.pid') + conf[CONF_SEAHUB_OUTLOG] = os.path.join(runtime_dir, 'access.log') + conf[CONF_SEAHUB_ERRLOG] = os.path.join(runtime_dir, 'error.log') + +def check_config(args): + check_layout(args) + try: port = int(args.port) except ValueError: @@ -775,14 +709,7 @@ def check_config(args): if port <= 0 or port > 65535: error('invalid port: %s' % args.port) - conf[CONF_CCNET_DIR] = ccnet_conf_dir - conf[CONF_SEAFILE_DIR] = seafile_data_dir - conf[CONF_SEAHUB_DIR] = seahub_dir - conf[CONF_SEAHUB_CONF] = seahub_conf conf[CONF_SEAHUB_PORT] = port - conf[CONF_SEAHUB_PIDFILE] = os.path.join(runtime_dir, 'seahub.pid') - conf[CONF_SEAHUB_OUTLOG] = os.path.join(runtime_dir, 'access.log') - conf[CONF_SEAHUB_ERRLOG] = os.path.join(runtime_dir, 'error.log') def check_directory_layout(): seaf_server_dir = os.path.join(cwd, 'seafile-server') @@ -888,71 +815,16 @@ def stop_seafile(dummy): info('done') -def reset_admin(dummy): +def reset_admin(args): '''reset seafile admin account''' - # Get .ccnet directory from argument or user input - ccnet_dir = os.path.join(cwd, 'ccnet') + check_layout(args) + env = get_seahub_env() - # Test usermgr.db exists - usermgr_db = os.path.join(ccnet_dir, 'PeerMgr/usermgr.db') - if not os.path.exists(usermgr_db): - error('%s NOT exists. FAILED' % usermgr_db) + argv = [PYTHON, 'manage.py', 'createsuperuser'] - conn = sqlite3.connect(usermgr_db) - c = conn.cursor() - - # Check whether admin user exists - sql = 'SELECT email FROM EmailUser WHERE is_staff = 1' - try: - c.execute(sql) - except sqlite3.Error, e: - error('An error orrured: %s' % e.args[0]) - - staff_list = c.fetchall() - if staff_list: - print 'Admin is already in database. Email as follows: ' - print '--------------------' - for e in staff_list: - print e[0] - print '--------------------' - choice = raw_input('Previous admin would be deleted, would you like to continue?[y/n] ') - if choice == 'y': - sql = 'DELETE FROM EmailUser WHERE is_staff = 1' - try: - c.execute(sql) - except sqlite3.Error, e: - error('An error orrured: %s' % e.args[0]) - else: - info('Previous admin is deleted') - else: - conn.close() - sys.exit(0) - - # Create admin user - choice = raw_input('Would you like to create admin user?[y/n]') - if choice != 'y': - conn.close() - sys.exit(0) - - username = raw_input('E-mail address:') - passwd = getpass.getpass('Password:') - passwd2 = getpass.getpass('Password (again):') - if passwd != passwd2: - error('Two passwords are not the same') - - enc_passwd = hashlib.sha1(passwd).hexdigest() - sql = "INSERT INTO EmailUser(email, passwd, is_staff, is_active, ctime) VALUES ('%s', '%s', 1, 1, '%d');" % (username, enc_passwd, time.time()*1000000) - try: - c = conn.cursor() - c.execute(sql) - conn.commit() - except sqlite3.Error, e: - error('An error orrured: %s' % e.args[0]) - else: - info('Admin user created successfully') - - # Close db - conn.close() + env = get_seahub_env() + seahub_dir = conf[CONF_SEAHUB_DIR] + run_argv(argv, cwd=seahub_dir, env=env) def main(): check_seafile_install() @@ -980,8 +852,11 @@ def main(): parser_reset_admin = subparsers.add_parser('reset-admin', help='reset seafile admin account') parser_reset_admin.set_defaults(func=reset_admin) + parser_create_admin = subparsers.add_parser('create-admin', help='create seafile admin account') + parser_create_admin.set_defaults(func=reset_admin) + args = parser.parse_args() args.func(args) if __name__ == '__main__': - main() \ No newline at end of file + main()