betaveros.bearblog.dev · 5d · discuss
On a modern Linux computer, systemd lets you run a program and automatically restart it when the computer reboots and/or the program crashes. (Among many, many other things.) tl;drSave a file like the following to /etc/systemd/system/myserver.service: [Unit] Description=My Python server [Service] User=brian WorkingDirectory=/home/brian/myserver ExecStart=/home/brian/myserver/.venv/bin/python /home/brian/myserver/myserver.py Restart=always [Install] WantedBy=multi-user.target This is a unit file. It's best to specify the command executable as an absolute path, as I've done here. Then (with sudo as appropriate): Make systemd reread unit files: systemctl daemon-reload Enable the service (so future reboots will automatically start it) and also start it immediately: systemctl enable --now myserver (As...