0

I would like to find out how to write Python code which sets up a process to run on startup, in this case level two.

I have done some reading, yet it has left me unclear as to which method is most reliable on different systems. I originally thought I would just edit /etc/inittab with pythons fileIO, but then I found out that my computers inittab was empty.

What should I do? Which method of setting something to startup on boot is most reliable? Does anyone have any code snippets lying around?

tshepang
  • 12,111
  • 21
  • 91
  • 136
64bit_twitchyliquid
  • 894
  • 2
  • 10
  • 22
  • What version of Linux are you using? – oathead Dec 09 '12 at 04:05
  • Ubuntu 10.10. I think the empty inittab is probably because the box is a VPS, and hence runs inside openVZ. – 64bit_twitchyliquid Dec 09 '12 at 04:11
  • I don't have a 10.10 instance around to test on, but I think that's using upstart to manage what's started at boot. You should be able to create a script in /etc/init. Take a look at the [upstart docs](http://upstart.ubuntu.com/cookbook/) – oathead Dec 09 '12 at 04:23
  • I was hoping to create a script that would work on all versions of linux. Not just Ubuntu – 64bit_twitchyliquid Dec 09 '12 at 07:39
  • I'm not sure if there will ever be one standard way to do startup scripts, but upstart seems to be the standard on many recent linux distros. Older versions of RedHat don't use it, but RHEL 6 has it. So you should be able to get lots of Linux distros if you go the upstart route. Here's a post that goes into a little more detail on [python daemons](http://stackoverflow.com/questions/4705564/python-script-as-linux-service-daemon) – oathead Dec 10 '12 at 03:40

1 Answers1

0

I may as well answer my own question with my findings.

On Debian,Ubuntu,CentOS systems there is a file named /etc/rc.local. If you use pythons' FileIO to edit that file, you can put a command that will be run at the end of all the multi-user boot levels. This facility is still present on systems that use upstart.

On BSD I have no idea. If you know how to make something go on startup please comment to improve this answer.

Archlinux and Fedora use systemd to start daemons - see the Arch wiki page for systemd. Basically you need to create a systemd service and symlink it. (Thanks Emil Ivanov)

64bit_twitchyliquid
  • 894
  • 2
  • 10
  • 22
  • Archlinux and Fedora use `systemd` to start daemons - see the [Arch wiki page for systemd](https://wiki.archlinux.org/index.php/Systemd). Basically you need to create a systemd service and symlink it. – Emil Ivanov Dec 14 '12 at 09:59