【问题标题】:init.d autostart python script after reboot (Centos)init.d 重启后自动启动 python 脚本(Centos)
【发布时间】:2014-04-13 01:38:59
【问题描述】:

重启后有任何一个用于自动启动python脚本的脚本(centos)。

我试过这段代码,但它不起作用

#! /bin/sh
# chkconfig: 2345 95 20
# description: almagest
# What your script does (not sure if this is necessary though)
# processname: www-almagest
# /etc/init.d/www-almagest start

case "$1" in
  start)
    echo "Starting almagest"
    # run application you want to start
    python ~almagest_clinic/app.py &> /dev/null &
    ;;
  stop)
    echo "Stopping example"
    # kill application you want to stop
    kill -9 $(sudo lsof -t -i:8002)
    ;;
  *)
    echo "Usage: /etc/init.d/www-private{start|stop}"
    exit 1
    ;;
esac

exit 0

chkconfig 脚本开启

【问题讨论】:

标签: python linux centos init.d


【解决方案1】:

init进程以root身份运行,你有一个相对路径

python $HOME/almagest_clinic/app.py &> /dev/null & 

在你的脚本中。

root 用户可能无法看到该路径。我建议将该路径更改为绝对路径

【讨论】:

  • 感谢您的回复!脚本正确启动和停止 python 进程。但重启后它不会自动启动
  • 我仍然会使用绝对路径进行测试。也可能是 python 脚本需要一些 init 尚未启动的东西。我看到您已将 chkconfig 命令更改为 95,但可能还为时过早。将 STDOUT 从 python 发送到您可以在启动后读取的日志文件。
【解决方案2】:

我找到了解决方案https://github.com/frdmn/service-daemons/blob/master/centos 使用绝对路径它对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-07
    • 2013-06-30
    • 2018-12-04
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    相关资源
    最近更新 更多