You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
63 lines
1.4 KiB
8 years ago
|
#!/usr/bin/env python3
|
||
8 years ago
|
#
|
||
|
# Copyright (c) 2016, Neil Booth
|
||
|
#
|
||
|
# All rights reserved.
|
||
|
#
|
||
|
# See the file "LICENCE" for information about the copyright
|
||
8 years ago
|
# and warranty status of this software.
|
||
|
|
||
8 years ago
|
'''Script to kick off the server.'''
|
||
|
|
||
|
|
||
8 years ago
|
import asyncio
|
||
|
import logging
|
||
|
import os
|
||
|
import traceback
|
||
|
|
||
|
from server.env import Env
|
||
8 years ago
|
from server.controller import Controller
|
||
8 years ago
|
|
||
|
|
||
|
def main_loop():
|
||
|
'''Get tasks; loop until complete.'''
|
||
|
if os.geteuid() == 0:
|
||
|
raise Exception('DO NOT RUN AS ROOT! Create an unpriveleged user '
|
||
|
'account and use that')
|
||
|
|
||
|
env = Env()
|
||
|
logging.info('switching current directory to {}'.format(env.db_dir))
|
||
|
os.chdir(env.db_dir)
|
||
|
|
||
|
loop = asyncio.get_event_loop()
|
||
8 years ago
|
#loop.set_debug(True)
|
||
|
|
||
8 years ago
|
controller = Controller(loop, env)
|
||
|
controller.start()
|
||
8 years ago
|
|
||
|
tasks = asyncio.Task.all_tasks(loop)
|
||
8 years ago
|
try:
|
||
|
loop.run_until_complete(asyncio.gather(*tasks))
|
||
8 years ago
|
except asyncio.CancelledError:
|
||
|
logging.warning('task cancelled; asyncio event loop closing')
|
||
8 years ago
|
finally:
|
||
8 years ago
|
controller.stop()
|
||
8 years ago
|
loop.close()
|
||
|
|
||
|
|
||
|
def main():
|
||
|
'''Set up logging, enter main loop.'''
|
||
|
logging.basicConfig(level=logging.INFO)
|
||
|
logging.info('ElectrumX server starting')
|
||
|
try:
|
||
|
main_loop()
|
||
|
except Exception:
|
||
|
traceback.print_exc()
|
||
|
logging.critical('ElectrumX server terminated abnormally')
|
||
|
else:
|
||
|
logging.info('ElectrumX server terminated normally')
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|