2

I am using Debian and I have a python script that I would like to run during rc.local so that it will run on boot. I already have it working with a test file that is meant to run and terminate.

The problem is that this file should eventually run indefinitely using Scheduler. It's job is to do serial reads, a small amount of processing on those reads, and inserts into a MySQL database. However, I am nervous about then not being able to cancel the script to get to my login prompt if changes need to be made since I was unable to terminate the test script early using Ctrl+C (^C).

My hope is that there is some command that I am just missing that will accomplish this. Is there another key command that I'm missing that will terminate the python script and end rc.local?

Thanks.

EDIT: Another possible solution that would help me here is if there is a way to start a python script in the background during boot. So it would start the script and then allow login while continuing to run the script in the background.

I'm starting to think this isn't something that's possible to accomplish so other suggestions to accomplish something similar to what I'm trying to do would be helpful as well.

Thanks again.

2
  • Ctrl+C should terminate a Python script normally, unless you are catching all exceptions or something silly like that (as Python interprets Ctrl+C as an InterruptException). Commented Dec 3, 2012 at 0:50
  • I can terminate the script just fine when running it from the shell after boot or via Idle. I cannot terminate the script when running it during boot via /etc/rc.local. When I press Ctrl+C, it displays a ^C in the shell but does not terminate. Commented Dec 3, 2012 at 3:12

2 Answers 2

1

Seems like it was just a dumb mistake on my part.

I realized the whole point of this was to allow the python script to run as a background process during boot so I added the " &" to the end of the script call like you would when running it from the shell and viola I can get to my password prompt by pressing "Enter".

I wanted to put this answer here just in case this would be something horribly wrong to do, but it accomplishes what I was looking for.

Sign up to request clarification or add additional context in comments.

Comments

0

Making scripts run at boot time with Debian

  1. Put your script in /etc/init.d/. So, if your script is in a file called my_script, it should be located at /etc/init.d/my_script.

  2. Run update-rc.d my_script defaults as root.

  3. Don't forget to make your script executable and include the shebang. That means the first line of the script should be #!/usr/bin/python.

1 Comment

Thanks. I prefer adding the script call to /etc/rc.local though so that it is the last thing called during boot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.