Run Gogs as service


I try to use the init script provided in the Github repo to run Gogs on startup as a service on my Centos 6.7 VPS. However, it does not work and I get the following error in the log file:

“[…s/setting/setting.go:419 NewContext()] [E] Expect user(root) but current user is:”

I try to run the service as root and I set the environment variable USER and USERNAME correctly in the script, but this won’t fix the error. How can I autostart Gogs after boot and run it in the background?

Hi, please dump your script here.

Hi, I have pasted the code here:


Can you try not run as root, and this is not recommended anyway…

shall I use a new user, e.g. git?

Yes, that’s a common practice.

Thank you, it works now. Now I have another problem, but I’ll make a new topic for that.

I’ve got a similar error, but I’m already running gogs as user ‘git’…
But still getting following error:

$ git push -u origin master
Host key fingerprint is SHA256:bULsg3QjH4uoIIuR/phiVD1XfnLnJXtJe064LPes/0E
Counting objects: 46, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (46/46), 8.05 KiB | 0 bytes/s, done.
Total 46 (delta 9), reused 0 (delta 0)
remote: 2017/05/23 17:57:44 [FATAL] [...s/setting/setting.go:532 NewContext()] Expect user 'root' but current user is: git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ''
1 Like

I have encountered the same problem. Is there any solution?

What is the “same problem”? I suggest to open a new thread with full details.