Gogs无法通过systemd启动服务


#1

Gogs 版本:0.11.66
系统类型及版本:CentOS 7.4.1708
数据库:SQLlitev3
问题描述:Gogs无法通过systemd启动

gogs已经初始化,但是无法通过systemd启动服务。
我是将scripts/systemd下的gogs.service,根据实际情况只更改了WorkingDirectory和ExecStart。然后将其放入到/etc/systemd/system/下,通过systemctl start gogs执行。
gogs.service如下:

[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=mariadb.service mysqld.service postgresql.service memcached.service 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
Type=simple
User=git
Group=git
WorkingDirectory=/usr/local/gogs
ExecStart=/usr/local/gogs/gogs web
Restart=always
Environment=USER=git HOME=/home/git

#Some distributions may not support these hardening directives. If you cannot start the service due
#to an unknown option, comment out the ones not supported by your version of systemd.
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

从systemctl status gogs的输出来看,gogs是启动成功了的,但在启动之后马上就退出了。输出如下:

● gogs.service - LSB: Start gogs at boot time.
Loaded: loaded (/etc/rc.d/init.d/gogs; bad; vendor preset: disabled)
Active: active (exited) since Sat 2018-09-29 15:58:03 CST; 50s ago
Docs: man:systemd-sysv-generator(8)
Process: 12216 ExecStop=/etc/rc.d/init.d/gogs stop (code=exited, status=0/SUCCESS)
Process: 12228 ExecStart=/etc/rc.d/init.d/gogs start (code=exited, status=0/SUCCESS)

Sep 29 15:58:03 devtestserver gogs[12228]: NAME:
Sep 29 15:58:03 devtestserver gogs[12228]: gogs web - Start web server
Sep 29 15:58:03 devtestserver gogs[12228]: USAGE:
Sep 29 15:58:03 devtestserver gogs[12228]: gogs web [command options] [arguments…]
Sep 29 15:58:03 devtestserver gogs[12228]: DESCRIPTION:
Sep 29 15:58:03 devtestserver gogs[12228]: Gogs web server is the only thing you need to run,
Sep 29 15:58:03 devtestserver gogs[12228]: and it takes care of all the other things for you
Sep 29 15:58:03 devtestserver gogs[12228]: OPTIONS:
Sep 29 15:58:03 devtestserver gogs[12228]: --port value, -p value Temporary port number to prevent conflict (default: “3000”)
Sep 29 15:58:03 devtestserver gogs[12228]: --config value, -c value Custom configuration file path (default: “custom/conf/app.ini”)

有人跟我一样遇到过这样的情况么?


#2

还是得看gogs自己的日志 log/gogs.log


#3

log中有如下信息:

2018/09/30 10:00:30 [TRACE] Log Mode: File (Trace)
2018/09/30 10:00:30 [ INFO] Gogs 0.11.66.0916
2018/09/30 10:00:30 [ INFO] Cache Service Enabled
2018/09/30 10:00:30 [ INFO] Session Service Enabled
2018/09/30 10:00:30 [ INFO] Git Version: 2.19.0
2018/09/30 10:00:30 [FATAL] […gogs/gogs/cmd/web.go:171 runWeb()] Fail to execute ‘git config --global core.quotepath false’: error: could not lock config file /home/git/.gitconfig: Read-only file system

但是我检查了/home/git/.gitconfig,信息如下:

ll -al
total 52
drwx------ 5 git git 4096 Sep 30 10:00 .
drwxr-xr-x. 14 root root 4096 Sep 28 11:57 …
-rw------- 1 git git 134 Sep 29 17:37 .bash_history
-rw-r–r-- 1 git git 18 Sep 7 2017 .bash_logout
-rw-r–r-- 1 git git 193 Sep 7 2017 .bash_profile
-rw-r–r-- 1 git git 231 Sep 7 2017 .bashrc
drwxrwxr-x 3 git git 4096 Sep 29 17:25 data
-rwxrwxrwx 1 git git 73 Sep 30 10:00 .gitconfig
-rw------- 1 git git 5756 Sep 29 17:29 nohup.out
drwxr-xr-x 5 git git 4096 Sep 29 15:49 repositories
drwxr-xr-x 2 git git 4096 Sep 28 15:56 .ssh
-rw------- 1 git git 750 Sep 29 15:53 .viminfo


#4

Gogs 在被 systemd 启动的时候没有给写权限


#5

/home/git的文件夹以及其下的文件权限都是git:git,还需要什么权限呢?


#6

应该是 systemd 的文件配置有误吧,下面是我用的:

[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=mysqld.service

[Service]
User=git
Group=git
WorkingDirectory=/home/git/apps/gogs
ExecStart=/home/git/apps/gogs/gogs web
Restart=always
Environment="USER=git","HOME=/home/git"

[Install]
WantedBy=multi-user.target

#7

我想这里的注释说明了情况


#8

额,果然是这个问题,把这些给注释掉就行了,非常感谢!