分类目录归档:python

web.py注册为服务(centos7)

命令行脚本:

/usr/bin/python /mnt/www/xxx/scripts/mq.py

创建服务文件(服务名xxx)

vim /usr/lib/systemd/system/xxx.service

xxx.service 文件内容

[Unit]
Description=The doufu python message queue server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
#PIDFile=
#ExecStartPre=
#ExecStartPre=
ExecStart=/usr/bin/python /mnt/www/xxx/scripts/mq.py
ExecReload=/usr/bin/python /mnt/www/xxx/scripts/mq.py
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target
# 启用服务(开机自动启动)
systemctl enable xxx.service
# 查看服务状态
systemctl status xxx.service
# 开始服务
systemctl start xxx.service
# 查看服务状态
systemctl status xxx.service

mrq: ImportError: No module named coros

故障现象:

运行mrq示例(mrq-run tasks.Fetch url http://www.google.com),报错

[root@web4 test-mrq]# mrq-run tasks.Fetch url http://www.google.com
Traceback (most recent call last):
  File "/bin/mrq-run", line 9, in 
    load_entry_point('mrq==0.1.18', 'console_scripts', 'mrq-run')()
  File "/usr/lib/python2.7/site-packages/mrq/bin/mrq_run.py", line 33, in main
    set_current_config(cfg)
  File "/usr/lib/python2.7/site-packages/mrq/context.py", line 82, in set_current_config
    patch_import()
  File "/usr/lib/python2.7/site-packages/mrq/monkey.py", line 127, in patch_import
    import gevent.coros
  File "/usr/lib64/python2.7/site-packages/gevent/builtins.py", line 93, in __import__
    result = _import(*args, **kwargs)
ImportError: No module named coros

解决方法:

yum install python-gevent