V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lhx888
V2EX  ›  程序员

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

  •  
  •   lhx888 · 2023-05-26 20:36:16 +08:00 · 1605 次点击
    这是一个创建于 547 天前的主题,其中的信息可能已经有所发展或是发生改变。

    官方推荐 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 后,就可以正常启动,并且后台程序不再崩溃。 按理说官方的写法一定是最好的,应该不会给我一个小白都能发现的改动空间。不理解,请大佬答疑解惑,谢谢了。

    6 条回复    2023-05-27 14:21:24 +08:00
    lolizeppelin
        1
    lolizeppelin  
       2023-05-26 21:09:40 +08:00
    装 rpm 版
    lolizeppelin
        2
    lolizeppelin  
       2023-05-26 21:11:54 +08:00
    notify 是因为你配置里没配置 systemd 通知 systemd 认为你进程启动未完成所以到默认通知超时时间后就干掉了你的进程
    去配置里找 systemd notify 相关配置
    feedcode
        3
    feedcode  
       2023-05-26 21:22:27 +08:00   ❤️ 1
    flyqie
        4
    flyqie  
       2023-05-26 23:06:23 +08:00
    最简单靠谱抄 gitea.service 的办法:

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

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

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

    绝对不会出问题。
    lhx888
        5
    lhx888  
    OP
       2023-05-27 14:18:17 +08:00
    @feedcode
    @lolizeppelin 谢谢您的回复,有可能这是 ubuntu 使用的版本的原因吧,而我的系统是 debian,把 Type=notify 改成 Type=simple , 再删除 WatchdogSec=30s ,后台就可以稳定运行了。
    lhx888
        6
    lhx888  
    OP
       2023-05-27 14:21:24 +08:00
    @flyqie 嗯谢谢您的回复,我明白您的意思了。举一反三,以后使用任何 github 上下载的软件,都适用。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2605 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 04:37 · PVG 12:37 · LAX 20:37 · JFK 23:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.