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.

50 line
1.4KB

  1. # encoding:utf-8
  2. import os
  3. from config import conf, load_config
  4. from channel import channel_factory
  5. from common.log import logger
  6. from plugins import *
  7. import signal
  8. import sys
  9. def sigterm_handler_wrap(_signo):
  10. old_handler = signal.getsignal(_signo)
  11. def func(_signo, _stack_frame):
  12. logger.info("signal {} received, exiting...".format(_signo))
  13. conf().save_user_datas()
  14. if callable(old_handler): # check old_handler
  15. return old_handler(_signo, _stack_frame)
  16. signal.signal(_signo, func)
  17. def run():
  18. try:
  19. # load config
  20. load_config()
  21. # ctrl + c
  22. sigterm_handler_wrap(signal.SIGINT)
  23. # kill signal
  24. sigterm_handler_wrap(signal.SIGTERM)
  25. # create channel
  26. channel_name=conf().get('channel_type', 'wx')
  27. if "--cmd" in sys.argv:
  28. channel_name = 'terminal'
  29. if channel_name == 'wxy':
  30. os.environ['WECHATY_LOG']="warn"
  31. # os.environ['WECHATY_PUPPET_SERVICE_ENDPOINT'] = '127.0.0.1:9001'
  32. channel = channel_factory.create_channel(channel_name)
  33. if channel_name in ['wx','wxy','terminal','wechatmp','wechatmp_service']:
  34. PluginManager().load_plugins()
  35. # startup channel
  36. channel.startup()
  37. except Exception as e:
  38. logger.error("App startup failed!")
  39. logger.exception(e)
  40. if __name__ == '__main__':
  41. run()