Upstart Script on Centos 6

Posted by MarcusMaximus on Super User See other posts from Super User or by MarcusMaximus
Published on 2012-11-19T22:22:16Z Indexed on 2012/11/19 23:08 UTC
Read the original article Hit count: 263

Filed under:
|
|
|
|

I'm trying to create an upstart script to run a python script on startup. In theory it looks simple enough but I just can't seem to get it to work. I'm using a skeleton script I found here and altered.

description "Used to start python script as a service"
author "Me <[email protected]>"

# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Start the process
script
  exec su nonrootuser -c "python /usr/local/scripts/script.py"
end script

The test script I want it to run is currently a simple python script that runs without any issue when run from a terminal.

#!/usr/bin/python2

import os, sys, time 
if __name__ == "__main__":  
    for i in range (10000):
        message = "shotgunUpstartTest " , i , time.asctime() , " - Username: " , os.getenv("USERNAME")
        #print message
    time.sleep(60)
        out = open("/var/log/scripts/scriptlogfile", "a")
        print >> out, message
        out.close()
  • The location/var/log/scripts has permissions 777
  • The file /usr/local/scripts/script.py has permissions 775
  • The upstart script /etc/init.d/pythonupstart.conf has permissions 755

© Super User or respective owner

Related posts about centos

Related posts about startup