seafile-containerized/scripts/start.py

57 lines
1.6 KiB
Python
Raw Normal View History

2018-04-03 02:58:14 +00:00
import os
import time
2018-05-18 09:12:14 +00:00
import json
from os.path import join, exists, dirname
2018-04-03 02:58:14 +00:00
from upgrade import check_upgrade
2018-05-18 09:12:14 +00:00
from utils import call, get_conf, get_script, get_command_output, get_install_dir
2018-04-03 02:58:14 +00:00
installdir = get_install_dir()
topdir = dirname(installdir)
def watch_controller():
maxretry = 4
retry = 0
while retry < maxretry:
controller_pid = get_command_output('ps aux | grep seafile-controller | grep -v grep || true').strip()
garbage_collector_pid = get_command_output('ps aux | grep /scripts/gc.sh | grep -v grep || true').strip()
if not controller_pid and not garbage_collector_pid:
retry += 1
else:
retry = 0
time.sleep(5)
print 'seafile controller exited unexpectedly.'
sys.exit(1)
def main():
2018-05-18 09:12:14 +00:00
call('/scripts/create_data_links.sh')
2018-04-03 02:58:14 +00:00
check_upgrade()
os.chdir(installdir)
2018-05-18 09:12:14 +00:00
call('service nginx start &')
2018-04-03 02:58:14 +00:00
admin_pw = {
'email': get_conf('SEAFILE_ADMIN_EMAIL', 'me@example.com'),
'password': get_conf('SEAFILE_ADMIN_PASSWORD', 'asecret'),
}
password_file = join(topdir, 'conf', 'admin.txt')
2018-05-18 09:12:14 +00:00
with open(password_file, 'w+') as fp:
2018-04-03 02:58:14 +00:00
json.dump(admin_pw, fp)
try:
call('{} start'.format(get_script('seafile.sh')))
call('{} start'.format(get_script('seahub.sh')))
finally:
if exists(password_file):
os.unlink(password_file)
print 'seafile server is running now.'
try:
watch_controller()
except KeyboardInterrupt:
print 'Stopping seafile server.'
sys.exit(0)
2018-05-18 09:12:14 +00:00
if __name__ == "__main__":
2018-04-03 02:58:14 +00:00
main()