|
123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- # encoding:utf-8
-
- import os
- from config import conf, load_config
- from channel import channel_factory
- from common.log import logger
- from plugins import *
- import signal
- import sys
-
- def sigterm_handler_wrap(_signo):
- old_handler = signal.getsignal(_signo)
- def func(_signo, _stack_frame):
- logger.info("signal {} received, exiting...".format(_signo))
- conf().save_user_datas()
- return old_handler(_signo, _stack_frame)
- signal.signal(_signo, func)
-
- def run():
- try:
- # load config
- load_config()
- # ctrl + c
- sigterm_handler_wrap(signal.SIGINT)
- # kill signal
- sigterm_handler_wrap(signal.SIGTERM)
-
- # create channel
- channel_name=conf().get('channel_type', 'wx')
- if channel_name == 'wxy':
- os.environ['WECHATY_LOG']="warn"
- # os.environ['WECHATY_PUPPET_SERVICE_ENDPOINT'] = '127.0.0.1:9001'
-
- channel = channel_factory.create_channel(channel_name)
- if channel_name in ['wx','wxy','wechatmp']:
- PluginManager().load_plugins()
-
- # startup channel
- channel.startup()
- except Exception as e:
- logger.error("App startup failed!")
- logger.exception(e)
-
- if __name__ == '__main__':
- run()
|