【问题标题】:How can i run a python file as service python3我如何将 python 文件作为服务 python3 运行
【发布时间】:2018-01-30 04:09:12
【问题描述】:

我有一个 python 脚本,我必须作为服务/后台进程运行,我尝试了 python-daemon 但它给了我错误是否有任何好的方法可以将它作为服务运行以便脚本可以运行在后台接受消息和处理文件?

【问题讨论】:

  • 你能提供你收到的错误吗?
  • os.umask(022) # 不允许别人写
  • 这是我尝试过的“pypi.python.org/pypi/python-daemon
  • 再次请提供您尝试过的代码示例以及您收到的错误?

标签: python-3.x python-daemon


【解决方案1】:

我在 /lib/systemed/system 中创建了一个 sytemctl 服务文件 文件内容是

[Unit]
Description=RPC SERVER
After=network.target

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/
Type=simple
ExecStart=/usr/bin/ python3 /home/ubuntu/rpc.py


[Install]
WantedBy=multi-user.target

/home/ubuntu/rpc.py 是我的python脚本路径 我将文件保存为 rpcservertest.service 所以我可以使用 sudo systemctl start rpcservertest.service 停止 sudo systemctl stop rpcservertest.service 并获得状态 sudo systemctl status rpcservertest.service

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-18
    • 2020-08-15
    • 2011-01-29
    • 2012-04-15
    • 1970-01-01
    • 2010-11-28
    • 2015-08-13
    • 2012-05-14
    相关资源
    最近更新 更多