Gitea Service is not starting

Hi, I am new to gitea and not a Linux expert. I managed to install gitea on Ubuntu 18.04 with Apache more or less follwing this tutorial
When I start gitea with sudo /usr/local/bin/gitea web -c /opt/gitea/app.ini, then the page for setting up configuration at my server is available. But when I try to do this via a service it does not work.
sudo service gitea start and sudo service gitea status give me

● gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Wed 2019-04-24 11:27:17 CEST; 1s ago
  Process: 32532 ExecStart=/usr/local/bin/gitea web -c /opt/gitea/app.ini (code=exited, status=1/FAILURE)
 Main PID: 32532 (code=exited, status=1/FAILURE)

and in the browser I see a 503 Service unavailable.

more details gives me journalctl -b 0 -u gitea:

Apr 19 13:20:30 Ubuntu-1804-bionic-64-minimal systemd[1]: Started Gitea (Git with a cup of tea).
Apr 19 13:20:30 Ubuntu-1804-bionic-64-minimal gitea[22399]: panic: Git version missing: exec: "git": executable file not found in $PATH
Apr 19 13:20:30 Ubuntu-1804-bionic-64-minimal gitea[22399]: goroutine 1 [running]:
Apr 19 13:20:30 Ubuntu-1804-bionic-64-minimal gitea[22399]: code.gitea.io/gitea/vendor/code.gitea.io/git.init.0()
Apr 19 13:20:30 Ubuntu-1804-bionic-64-minimal gitea[22399]:         /go/src/code.gitea.io/gitea/vendor/code.gitea.io/git/git.go:76 +0x1a3
Apr 19 13:20:30 Ubuntu-1804-bionic-64-minimal systemd[1]: gitea.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Apr 19 13:20:30 Ubuntu-1804-bionic-64-minimal systemd[1]: gitea.service: Failed with result 'exit-code'.
Apr 19 13:20:32 Ubuntu-1804-bionic-64-minimal systemd[1]: gitea.service: Service hold-off time over, scheduling restart.
Apr 19 13:20:32 Ubuntu-1804-bionic-64-minimal systemd[1]: gitea.service: Scheduled restart job, restart counter is at 1.
Apr 19 13:20:32 Ubuntu-1804-bionic-64-minimal systemd[1]: Stopped Gitea (Git with a cup of tea).

So why is git executable not found?
sudo git --version returns git version 2.17.1
I really googled a lot to find out but here I’m stuck.
My Service configuration looks like this

[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=git
Group=git
WorkingDirectory=/opt/gitea/
ExecStart=/usr/local/bin/gitea web -c /opt/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/opt/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

About the PATH:
which git returns /usr/bin/git and sudo env | grep ^PATH returns PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

Odd. Have you tried explicitly setting the path inside the unit file?

If it still doesn’t work, you should wrap the ExecStart command with a shell, echo PATH to stdout before gitea runs, and then inspect systemd logs.

Thanks for your answer. I tried the solution you provided and it worked. The I removed it again (since it really should be unnecessary) and it still worked. No idea what I did wrong in the first place, but thanks a lot anyways.

I am still running into problems with letsencrypt resp. reverse proxy config though, but I think better start a new thread for that one.

If anybody else hits this thread, I had a similar issue, but unfortunately I wasn’t that fortunate to see that gitea wasn’t seeing git.

My journalctl -b 0 -u gitea only said


Jun 17 13:01:42 gitea.example.org systemd[1]: Started Gitea gitlabselfhost instance.
Jun 17 13:01:42 gitea.example.org systemd[1]: giteaselfhost.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Jun 17 13:01:42 gitea.example.org systemd[1]: Unit giteaselfhost.service entered failed state.
Jun 17 13:01:42 gitea.example.org systemd[1]: giteaselfhost.service failed.

The problem was that my ‘git’ is in a custom path, so the adding the path in the service worked for me.
I suspect that maybe the person above forgot to daemon-reload systemd so that’s why it’s still working ?