Creating a gitea service

Updated on 28 Dec 2018

The instructions for creating a service for Gitea are also applicable for other services.

Create the service file

In the /etc/systemd/system directory, create a file called gitea.service.

/etc/systemd/system/gitea.service

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service

[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=brent
Group=brent
WorkingDirectory=/var/lib/gitea/
ExecStart=/var/lib/gitea/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=brent HOME=/mnt/git GITEA_WORK_DIR=/var/lib/gitea

# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

Some of these settings are fairly standard, infact you could almost copy it directly from the gitea.service sample, however there are some settings that we need to adjust for our purposes. In particular

  • User
  • Group
  • WorkingDirectory
  • ExecStart
  • Environment, HOME

Another item that I added was at the start, After=mysqld.service because my version of gitea was installed with MySQL.

Enabling and starting the Service

Once we have created the service file, the service needs to be enabled. enable means that the service will automatically start at boot.

sudo systemctl enable gitea
sudo systemctl start gitea

Notice that the first line in the screen shot, also corresponds with the Description in our gitea.service file we created in the earlier section.