Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 <>"

# Stanzas
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here:

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

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

# Automatically restart process if crashed

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

# Start the process
  exec python /usr/local/scripts/
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.


import os, sys, time 
if __name__ == "__main__":  
    for i in range (10000):
        message = "UpstartTest " , i , time.asctime() , " - Username: " , os.getenv("USERNAME")
        #print message
        out = open("/var/log/scripts/scriptlogfile", "a")
        print >> out, message
  • The location/var/log/scripts has permissions 777
  • The file /usr/local/scripts/ has permissions 775
  • The upstart script /etc/init.d/pythonupstart.conf has permissions 755
share|improve this question
Your test script is not fork()ing so your expect line is probably wrong. Are you really sure you want to respawn? – Zoredache Nov 22 '12 at 0:46
This is just a test script I will want the script I plan to run in production to respawn. I'll take out the fork() and see how I go. – MarcusMaximus Nov 22 '12 at 3:35
share|improve this answer
/var/log/upstart isn't there but upstart is installed. /sbin/initctl --version returns "initctl (upstart 0.6.5) Copyright (C) 2010 Canonical Ltd." Does Upstart need to be configured to start at startup or is it automatic, I didn't install it. It was there when I installed the OS. – MarcusMaximus Nov 27 '12 at 3:21
sudo /etc/init.d/script.conf gives the following output line 3: description: command not found line 4: author: command not found start: Unknown job: on stop: Unknown job: on line 18: respawn: command not found Script started, file is typescript – MarcusMaximus Nov 27 '12 at 6:51
Upstart scripts go in /etc/init not /etc/init.d :( – MarcusMaximus Dec 11 '12 at 3:29
up vote 0 down vote accepted

Upstart scripts go in /etc/init not /etc/init.d, It was a long week that week. :(

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.