@JS's Notes

Site with notes from my work.

Gitea with sqlite3 on Ubuntu 20.04

2020-07-16 System Programing @JS

My test platform: Ubuntu Server 20.04

Requirements: user with root privileges or non-root user with sudo privileges.

Gitea installation
$ sudo apt update; sudo apt upgrade -y
$ sudo apt install git wget tree sqlite3 -y
$ sudo adduser --system --shell /bin/bash --gecos 'User for Gitea' --group --disabled-password --home /home/gitea gitea
$ mkdir download; cd download
$ wget -O gitea https://dl.gitea.io/gitea/1.12.1/gitea-1.12.1-linux-amd64
$ chmod +x gitea
$ sudo mkdir -p /var/lib/gitea/{custom,data,log}
$ sudo chown -R gitea: /var/lib/gitea/
$ sudo chmod -R 750 /var/lib/gitea/
$ sudo mkdir /etc/gitea
$ sudo chown root:gitea /etc/gitea
$ sudo chmod 770 /etc/gitea
$ sudo cp gitea /usr/local/bin/gitea

NOTE: /etc/gitea is temporary set with write rights for user gitea so that Web Installer could write configuration file. After installation is done, it is recommended to set rights to read-only using:

chmod 750 /etc/gitea
chmod 640 /etc/gitea/app.ini
Creating a gitea.service file

Copy the sample gitea.service file to /etc/systemd/system/gitea.service:

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
###
# Don't forget to add the database service requirements
###
#
#Requires=mysql.service
#Requires=mariadb.service
#Requires=postgresql.service
#Requires=memcached.service
#Requires=redis.service
#
###
# If using socket activation for main http/s
###
#
#After=gitea.main.socket
#Requires=gitea.main.socket
#
###
# (You can also provide gitea an http fallback and/or ssh socket too)
#
# An example of /etc/systemd/system/gitea.main.socket
###
##
## [Unit]
## Description=Gitea Web Socket
## PartOf=gitea.service
##
## [Socket]
## Service=gitea.service
## ListenStream=<some_port>
## NoDelay=true
##
## [Install]
## WantedBy=sockets.target
##
###

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=gitea
Group=gitea
WorkingDirectory=/var/lib/gitea/
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
#RuntimeDirectory=gitea
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024, uncomment
# the two values below, or use socket activation to pass Gitea its ports as above
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
###

[Install]
WantedBy=multi-user.target

Enable and start gitea.service at boot:

$ sudo systemctl enable gitea.service --now
$ sudo systemctl status gitea.service
Firewall configuration
$ sudo ufw allow 3000/tcp comment 'accept Gitea connections'
$ sudo ufw status

Reference: Gitea DOCS.