2 hours ago · 9 min read1875 words · Tech · hide · 0 comments

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 separate steps, this is systemctl enable myserver and systemctl start myserver) Check its status: systemctl status myserver Tail its logs: journalctl -u myserver -f Don't like or subscribe…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.