2010-11-10 116 views
1

我是新来的python。我想创建从/etc/init.d命令执行像/etc/init.d控制的脚本东西启动/停止/重新启动/etc/init.d sh脚本

任何意见赞赏。

+2

这些脚本应该在shell中编程,而不是在Python中编写。 http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/tocsysinit.html – 2010-11-10 14:10:39

+0

为什么?我相信你,但我想知道理由是什么,特别是我可以遇到什么麻烦。 – mjhm 2010-11-10 14:27:32

+1

为了完整起见,我问了关于ServerFault的问题:http://serverfault.com/questions/200424/init-d-scripts-written-in-python – mjhm 2010-11-10 20:43:26

回答

1

如果您正在寻找构建守护程序的模块。我用过这个:https://gist.github.com/slor/5946334

+1

这里给出了一个很好的例子。 – invert 2010-11-10 14:16:38

+0

链接中断 – 2017-07-14 23:42:15

+0

谢谢 - 更新 – mjhm 2017-07-15 05:20:02

3

请参阅this post关于如何编写脚本以放置在/etc/init.d目录中。唯一的区别是,你必须改变散列砰行指向蟒蛇,而不是bash下

#!/usr/bin/python 
def myfunc(): 
    print 'myfunct()' 

if __name__ == '__main__': 
    print 'running python script' 
    myfunc() 

,使文件的可执行

chmod +x myscript 
1

金钱豹初始化(HTTP://www.pardus .org.tr/eng/projects/comar/SpeedingUpLinuxWithPardus.html)基于python,理论上你甚至可以用windows可执行文件启动系统(通过Wine当然)。你可以看到一个示例初始化脚本,它使用shell脚本执行几乎相同的事情,但是采用pythonic方式。