Making Gitea start automatically with systemd
Last time I managed to deploy my Gitea service, but had difficulties getting it to start automatically on system startup. (Oh, I really miss Windows Scheduler.)
I had a cobbled-together solution using cron's @reboot
option that ran a bash script that started a screen
session that kept the Gitea app running. (Yuck. 🤢) But it only worked maybe two or three times - most often the web simply didn't start and I've never been able to figure out why.
While doing something unrelated, I stumbled upon an article explaining how to define a simple systemd unit. I attempted to write one for Gitea, and it seems to work! Here is what I came up with:
[Unit]
Description=Gitea service
[Service]
WorkingDirectory=/home/gitea/
ExecStart=/home/gitea/gitea web
Restart=always
RestartSec=30
SyslogIdentifier=gitea-zblesk
User=gitea
After=multi-user.target network-online.target
I saved this as /etc/systemd/system/gitea.service
, then made sure it is owned by root and executable.
sudo chmod +x gitea.service
sudo chown root:root gitea.service
Last step: actually enabling the service.
sudo systemctl enable gitea.service
That's not only nicer and cleaner, but it also works. Even after a reboot, it seems. 😄