简体   繁体   English

重启后init.d自动启动python脚本(Centos)

[英]init.d autostart python script after reboot (Centos)

Has any one script for autostart python script after reboot (centos). 重启后具有任何一个用于自动启动python脚本的脚本(centos)。

I tryed this code, but it is not working 我尝试了这段代码,但是没有用

#! /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 script on chkconfig脚本在

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

The init process runs as root, and you have a relative path init进程以root身份运行,并且您具有相对路径

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

in your script. 在您的脚本中。

The root user may not be able to see that path. 超级用户可能看不到该路径。 I would suggest changing that path to an absolute path 我建议将路径更改为绝对路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM