简体   繁体   中英

/etc/init.d sh script

I'm new to python. I want to create controlled script executed from /etc/init.d command like /etc/init.d something start/stop/restart

Any advise appreciated.

See this post on how to write a script to place in your /etc/init.d directory. The only difference is you must change the hash-bang line to point to python, and not bash:

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

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

And make the file executable

chmod +x myscript

If you're looking for a module for constructing daemons. I've used this: https://gist.github.com/slor/5946334

Pardus initialization (http://www.pardus.org.tr/eng/projects/comar/SpeedingUpLinuxWithPardus.html) is based on python and in theory you can even start system with windows executable (through Wine of course). You can see a sample initialisation script there doing almost same thing with shell script but in a pythonic way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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