5

I have this script in my home folder (pi): server.py.

How could I make Debian run this script at startup so I don't need to log in and run it manually?

2 Answers 2

4

At the time that this answer was first written, Debian (as installed by default) used "SysV" rc scripts with the start-stop-daemon binary. There was an example script, in the file /etc/init.d/skeleton, that one could as a base for one's rc script. Once one had one's rc script and it was marked as executable, the update-rc.d command could be used to add it to desired run levels.

As the years have gone by, things have changed. In 2014, in particular, two things changed:

  • The /etc/init.d/skeleton script was superseded by the example script in the init-d-script(5) manual page, which later in 2018 became the only available base when /etc/init.d/skeleton was done away with completely. The content of the skeleton also changed significantly, no longer needing people to write calls to start-stop-daemon or indeed to write much more than some variable assignments. (See https://unix.stackexchange.com/a/480897/5132 .)
  • The installed default changed to systemd, and one instead had to write systemd service unit files (which did not have to be marked executable) and enable them with systemctl enable. There was no example unit file, though. (See https://github.com/systemd/systemd/issues/10572 .)

So as of 2018 you need to write a systemd service unit file that (at the very least) names your script (using an absolute pathname) in an ExecStart setting. You might be wanting, although the question does not specify one way or another, to use a User setting to have the script run under the aegis of your user account and not the superuser's. And you might, again depending from things not specified in the question, need to coördinate the relative order of invoking your script and the (auto)mounting of your home directory if it is separately mounted.

4
  • 1
    oh jesus christ. that skeleton file is 150+ lines. just to get that script running :/
    – Jason94
    Jul 6, 2012 at 20:43
  • 3
    That's 150 lines that you don't have to write.
    – jordanm
    Jul 6, 2012 at 20:58
  • unix.stackexchange.com/a/480897/5132 /etc/init.d/skeleton is not the way.
    – JdeBP
    Nov 10, 2018 at 4:41
  • @JdeBP Yes, this answer is 6 years old and quite dated.
    – jordanm
    Nov 10, 2018 at 6:16
1

Put su -c 'SCRIPT' USER into /etc/rc.local.

1

You must log in to answer this question.

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