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?
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:
/etc/init.d/skeletonscript 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/skeletonwas done away with completely. The content of the skeleton also changed significantly, no longer needing people to write calls to
start-stop-daemonor indeed to write much more than some variable assignments. (See https://unix.stackexchange.com/a/480897/5132 .)
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.
su -c 'SCRIPT' USER into