Last time around I wrote about migrating my webs to an Ubuntu VM. One of the few things that were left to migrate was my private git repo hosting site. I'd used Bonobo Git Server and had always been satisfied with it. Since it doesn't target .Net Core, I didn't see any reasonable way to run it on Ubuntu. After some searching, I'd fortunately stumbled upon Gitea.
To get it up and running for the first time wasn't that difficult. I just had to:
sudo useradd -m gitea
wget https://dl.gitea.io/gitea/1.1.3/gitea-1.1.3-linux-amd64 -O gitea
chmod +x gitea
sudo chown gitea:gitea gitea
sudo mv gitea /home/gitea
which created a user I want to run the app under, downloaded Gitea, marked it as executable, and moved it to the user's home folder. When I wanted to run it, all I had to do was:
sudo su - gitea
That started the server at localhost:3000. After a first attempt at installation, it seemed it can't create its own DB table, so I quickly did that (with
mysql -u root -p):
CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'password here';
CREATE DATABASE gitea CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
grant all privileges on gitea.* to gitea@localhost;
After the DB was created, the installation went smoothly. Note, however, that if you change the port during the install process, you will be redirected to the new port, which will not work yet. You have to restart the Gitea web for the change to take effect.
Gitea also created some config files you can edit manually, in my case at
/home/gitea/custom/conf/app.ini. With everything set up, I configured nginx to serve the page, then secured it with Let's Encrypt's
certbot, but I went through that process last time, it was identical, so there's no need to repeat it here.
The last bit turned out to be the most time-consuming: how do I make the server actually start automatically, after a system reboot? After many failed experiments, I found a solution that works.
Basically, I made a script that will run Gitea under the
gitea user, placed it at
/etc/run-gitea.sh and made it executable (with
sudo su - gitea -c "/home/gitea/gitea web"
When I run the script manually, it works. After some failed attempts with
rc.local, I ended up using a cron job (added with
sudo crontab -e):
@reboot screen -d -m -S gitea.web bash /etc/run-gitea.sh
This makes sure that after a reboot, a screen session in which Gitea runs is started. In case I needed to take a look at the live system, I can SSH into the server and re-attach with
While Gitea looks and works great (and also exactly like Github, heh heh), there are parts that need more work. My favourite was this bit in the documentation of the Backup/restore procedure (emphasis mine):
Gitea currently has a
dumpcommand that will save your installation to a zip file. There will be a
restorecommand implemented at some point in the future.
Last but not least, thanks to networkgeekstuff.com for helping me out with many of these issues.
Though it probably took longer for me to realize I can have a passwordless user and then switch to it with sudo that it should have. 😇 ↩︎
Yes, writing scripts that would turn it into a service manageable via
systemdwould probably be cleaner, but I have no idea how to do that, and no time to waste right now. ↩︎