server.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2015 breakwall
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License. You may obtain
  8. # a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. # License for the specific language governing permissions and limitations
  16. # under the License.
  17. import time
  18. import sys
  19. import threading
  20. import os
  21. if __name__ == '__main__':
  22. import inspect
  23. os.chdir(os.path.dirname(os.path.realpath(inspect.getfile(inspect.currentframe()))))
  24. import server_pool
  25. import db_transfer
  26. from shadowsocks import shell
  27. from configloader import load_config, get_config
  28. class MainThread(threading.Thread):
  29. def __init__(self, obj):
  30. super(MainThread, self).__init__()
  31. self.daemon = True
  32. self.obj = obj
  33. def run(self):
  34. self.obj.thread_db(self.obj)
  35. def stop(self):
  36. self.obj.thread_db_stop()
  37. def main():
  38. shell.check_python()
  39. if False:
  40. db_transfer.DbTransfer.thread_db()
  41. else:
  42. if get_config().API_INTERFACE == 'mudbjson':
  43. thread = MainThread(db_transfer.MuJsonTransfer)
  44. elif get_config().API_INTERFACE == 'sspanelv2':
  45. thread = MainThread(db_transfer.DbTransfer)
  46. else:
  47. thread = MainThread(db_transfer.Dbv3Transfer)
  48. thread.start()
  49. try:
  50. while thread.is_alive():
  51. time.sleep(10)
  52. except (KeyboardInterrupt, IOError, OSError) as e:
  53. import traceback
  54. traceback.print_exc()
  55. thread.stop()
  56. if __name__ == '__main__':
  57. main()