/etc/systemd/system/gitea.service 按照官方配置,无法启动。将其中 sype=notify 改成 type=simple 就可以启动

352 天前
 lhx888

官方推荐 gitea.service 内容:

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target

[Service]
RestartSec=2s
Type=notify
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
WatchdogSec=30s

[Install]
WantedBy=multi-user.target

执行 systemctl start gitea.service 之后几乎每分钟崩溃一次。日志如下:

5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 cmd/web.go:105:runWeb() [I] Starting Gitea on PID: 846
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 ...s/install/setting.go:21:PreloadSettings() [I] AppPath: /usr/local/bin/gitea
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 ...s/install/setting.go:22:PreloadSettings() [I] AppWorkPath: /var/lib/gitea
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 ...s/install/setting.go:23:PreloadSettings() [I] Custom path: /var/lib/gitea/custom
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 ...s/install/setting.go:24:PreloadSettings() [I] Log path: /var/lib/gitea/log
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 ...s/install/setting.go:25:PreloadSettings() [I] Configuration file: /etc/gitea/app.ini
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 ...s/install/setting.go:26:PreloadSettings() [I] Prepare to run install page
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 ...s/install/setting.go:29:PreloadSettings() [I] SQLite3 is supported
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 cmd/web.go:220:listen() [I] [64709e72-6] Listen: http://0.0.0.0:3000
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 cmd/web.go:224:listen() [I] [64709e72-6] AppURL(ROOT_URL): http://localhost:3000/
 5 月 26 19:56:34 computer88 gitea[846]: 2023/05/26 19:56:34 ...s/graceful/server.go:62:NewServer() [I] [64709e72-6] Starting new Web server: tcp:0.0.0.0:3000 on PID: 846
 5 月 26 19:58:04 computer88 gitea[846]: 2023/05/26 19:58:04 ...eful/manager_unix.go:149:handleSignals() [W] [64709e72-4] PID 846. Received SIGTERM. Shutting down...
 5 月 26 19:58:04 computer88 gitea[846]: 2023/05/26 19:58:04 .../graceful/manager.go:205:doHammerTime() [W] Setting Hammer condition
 5 月 26 19:58:04 computer88 gitea[846]: 2023/05/26 19:58:04 cmd/web.go:271:listen() [I] [64709e72-6] HTTP Listener: 0.0.0.0:3000 Closed
 5 月 26 19:58:04 computer88 gitea[846]: 2023/05/26 19:58:04 ...eful/server_hooks.go:46:doShutdown() [I] [64709e72-6] PID: 846 Listener ([::]:3000) closed.
 5 月 26 19:58:04 computer88 systemd[1]: gitea.service: start operation timed out. Terminating.
 5 月 26 19:58:05 computer88 gitea[846]: 2023/05/26 19:58:05 .../graceful/manager.go:224:doTerminate() [W] Terminating
 5 月 26 19:58:05 computer88 gitea[846]: 2023/05/26 19:58:05 ...eful/manager_unix.go:157:handleSignals() [W] PID: 846. Background context for manager closed - context canceled - Shutting down...
 5 月 26 19:58:05 computer88 gitea[846]: 2023/05/26 19:58:05 cmd/web.go:139:runWeb() [I] PID: 846 Gitea Web Finished
 5 月 26 19:58:05 computer88 systemd[1]: gitea.service: Failed with result 'timeout'.
 5 月 26 19:58:05 computer88 systemd[1]: Failed to start Gitea (Git with a cup of tea).
 5 月 26 19:58:07 computer88 systemd[1]: gitea.service: Scheduled restart job, restart counter is at 1.
 5 月 26 19:58:07 computer88 systemd[1]: Stopped Gitea (Git with a cup of tea).
 5 月 26 19:58:07 computer88 systemd[1]: Starting Gitea (Git with a cup of tea)...
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 cmd/web.go:105:runWeb() [I] Starting Gitea on PID: 1410
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 ...s/install/setting.go:21:PreloadSettings() [I] AppPath: /usr/local/bin/gitea
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 ...s/install/setting.go:22:PreloadSettings() [I] AppWorkPath: /var/lib/gitea
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 ...s/install/setting.go:23:PreloadSettings() [I] Custom path: /var/lib/gitea/custom
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 ...s/install/setting.go:24:PreloadSettings() [I] Log path: /var/lib/gitea/log
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 ...s/install/setting.go:25:PreloadSettings() [I] Configuration file: /etc/gitea/app.ini
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 ...s/install/setting.go:26:PreloadSettings() [I] Prepare to run install page
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 ...s/install/setting.go:29:PreloadSettings() [I] SQLite3 is supported
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 cmd/web.go:220:listen() [I] [64709ecf-6] Listen: http://0.0.0.0:3000
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 cmd/web.go:224:listen() [I] [64709ecf-6] AppURL(ROOT_URL): http://localhost:3000/
 5 月 26 19:58:07 computer88 gitea[1410]: 2023/05/26 19:58:07 ...s/graceful/server.go:62:NewServer() [I] [64709ecf-6] Starting new Web server: tcp:0.0.0.0:3000 on PID: 1410
 5 月 26 19:59:37 computer88 systemd[1]: gitea.service: start operation timed out. Terminating.
 5 月 26 19:59:37 computer88 gitea[1410]: 2023/05/26 19:59:37 ...eful/manager_unix.go:149:handleSignals() [W] [64709ecf-4] PID 1410. Received SIGTERM. Shutting down...
 5 月 26 19:59:37 computer88 gitea[1410]: 2023/05/26 19:59:37 .../graceful/manager.go:205:doHammerTime() [W] Setting Hammer condition
 5 月 26 19:59:37 computer88 gitea[1410]: 2023/05/26 19:59:37 cmd/web.go:271:listen() [I] [64709ecf-6] HTTP Listener: 0.0.0.0:3000 Closed
 5 月 26 19:59:37 computer88 gitea[1410]: 2023/05/26 19:59:37 ...eful/server_hooks.go:46:doShutdown() [I] [64709ecf-6] PID: 1410 Listener ([::]:3000) closed.
 5 月 26 19:59:38 computer88 gitea[1410]: 2023/05/26 19:59:38 .../graceful/manager.go:224:doTerminate() [W] Terminating
 5 月 26 19:59:38 computer88 gitea[1410]: 2023/05/26 19:59:38 cmd/web.go:139:runWeb() [I] PID: 1410 Gitea Web Finished
 5 月 26 19:59:38 computer88 systemd[1]: gitea.service: Failed with result 'timeout'.
 5 月 26 19:59:38 computer88 systemd[1]: Failed to start Gitea (Git with a cup of tea).

将 gitea.service 中的 Type=notify 改成 Type=simple 后,就可以正常启动,并且后台程序不再崩溃。 按理说官方的写法一定是最好的,应该不会给我一个小白都能发现的改动空间。不理解,请大佬答疑解惑,谢谢了。

1420 次点击
所在节点    程序员
6 条回复
lolizeppelin
352 天前
装 rpm 版
lolizeppelin
352 天前
notify 是因为你配置里没配置 systemd 通知 systemd 认为你进程启动未完成所以到默认通知超时时间后就干掉了你的进程
去配置里找 systemd notify 相关配置
feedcode
352 天前
flyqie
352 天前
最简单靠谱抄 gitea.service 的办法:

1. 选好你打算安装的版本

2. 去 github 看对应版本 tag 的代码库

3. 拿代码库里的 contrib/systemd/gitea.service 改。

绝对不会出问题。
lhx888
351 天前
@feedcode
@lolizeppelin 谢谢您的回复,有可能这是 ubuntu 使用的版本的原因吧,而我的系统是 debian,把 Type=notify 改成 Type=simple , 再删除 WatchdogSec=30s ,后台就可以稳定运行了。
lhx888
351 天前
@flyqie 嗯谢谢您的回复,我明白您的意思了。举一反三,以后使用任何 github 上下载的软件,都适用。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/943299

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX