Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a Python script that I would like to have run on startup in Ubuntu. Is there an easy way to do this?

share|improve this question

migrated from stackoverflow.com Sep 22 '10 at 18:56

This question came from our site for professional and enthusiast programmers.

add comment

6 Answers 6

In Ubuntu, the recommended method of doing this is to use Upstart. In order for this to work, you must create a job file placed in:

/etc/init

The exact structure of the script, can be found at:

http://www.linux.com/archive/feature/125977?theme=print

A brief example, however, could look like this:

start on runlevel 2
script
   echo "Started"
end script

In this example, when the system switches into runlevel 2, upstart will emet a "runlevel 2" event. All jobs in the /etc/init directory which have a start or stop trigger for runlevel 2 will run. This script is triggered to start on this event, and will do so by echoing "Started". It then exits the script, and will run again the next time the system enters runlevel 2.

A decent tutorial can also be found here:

http://www.linuxplanet.com/linuxplanet/tutorials/7033/1/

share|improve this answer
add comment

I would suggest using a cronjob for it. There is a scheduling event to run on startup.

share|improve this answer
    
Not all versions of cron support @reboot syntax. –  Daenyth Sep 22 '10 at 22:12
add comment

You could create an init.d script UbuntoBootupHowto

share|improve this answer
add comment

Create a file rc.local and chmod it to make it executable, then stick in the python script

#!/bin/sh
python_cmd

The usage of rc.local is distribution dependent, it may be in /etc/init.d or in /etc/rc.d/

share|improve this answer
add comment

Your Answer

 
discard

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.