0

I have a python script which extracts continuous data from an incoming serial string and inserts the fields into an Sql database.

The python script can be run manually from an LX terminal and works successfully whilst the terminal remains open. This is easily tested by examining an associated web site where a PHP script is used to extract the data from the data base and display it in a HTML page.

I have tried a number of techniques to have the Python script executed automatically on restart. The closest I have got is for the terminal to open momentarily, start to run the python script and then close. I have tried delaying the opening on the terminal for a number of seconds to ensure there is no clash with the desktop or other applications starting, without luck.

The techniques that have been tried include:

  1. Creating a .desktop file in ~/.config/autostart to start the python script in an LX terminal. I have also tried delaying the start of the .desktop file via an .sh script with a 10 sec delay (sleep 10).
  2. Starting the Python script using the @reboot command in a cron job.
  3. Using Upstart with a .config file in /etc/init.
  4. Modifying the /etc/rc.local file to run the Python script.

I don't believe this is a permissions issue as the /usr/bin/python ~/user/file.py command and .desktop file can be run manually OK.

Any help will be greatly appreciated.

The environment is an UDOO Quad SBC running Ubuntu on the ARM processor, with the embedded Arduino Due capturing sensor data and transferring the string of data to the ARM processor.

1 Answer 1

0

Write a shell script that initiates your Python script and add that SHELL script in start-up program list for starting it automatically every time you reboot.
Shell Script: Execute a python program from within a shell script.
One more helpful Link : How to run the Python program in the background in Ubuntu machine?

To run it every time on reboot : How to run a shell script at startup.

2
  • Thanks for your suggestions, however, I had tried this without luck.
    – HenryOx
    Feb 11, 2015 at 3:54
  • I finally solved the problem using the Supervisor package, which turned out to be better than just starting at power-up as it allows you to start and stop via a cron job and dump/truncate the sql db.
    – HenryOx
    Feb 11, 2015 at 3:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .