Ubuntu20.04使用systemd配置Gogs开机启动

先说现象,大家用sudo systemctl start gogs是不是和我一样?

ubuntu@raspberry-pi:~$ sudo systemctl status gogs
● gogs.service - Gogs
     Loaded: loaded (/lib/systemd/system/gogs.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2024-09-06 09:48:34 CST; 3s ago
    Process: 4706 ExecStart=/www/wwwroot/gogs/gogs web (code=exited, status=1/FAILURE)
   Main PID: 4706 (code=exited, status=1/FAILURE)

Sep 06 09:48:34 raspberry-pi systemd[1]: gogs.service: Scheduled restart job, restart counter is at 5.
Sep 06 09:48:34 raspberry-pi systemd[1]: Stopped Gogs.
Sep 06 09:48:34 raspberry-pi systemd[1]: gogs.service: Start request repeated too quickly.
Sep 06 09:48:34 raspberry-pi systemd[1]: gogs.service: Failed with result 'exit-code'.
Sep 06 09:48:34 raspberry-pi systemd[1]: Failed to start Gogs.

那么要怎么搞呢?看下面

Step 0x01

cp YouCustomGogsDir/script/systemd/gogs.service /usr/lib/systemd/system

Setp 0x02

sudo vim /usr/lib/systemd/system/gogs.service

Setp 0x03
把其中的
User和Group修改为:root
WorkingDirectory修改为:你自己的路径
ExecStart修改为:你自己的路径
Environment修改为:Environment=USER=root HOME=/root

修改以后的gogs.script

[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=mariadb.service mysql.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=root
Group=root
WorkingDirectory=/www/wwwroot/gogs
ExecStart=/www/wwwroot/gogs/gogs web
Restart=always
Environment=USER=root HOME=/root

# 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

Setp 0x04

sudo systemctl enable gogs#设置开机启动
sudo systemctl start gogs#启动gogs
sudo systemctl status gogs#查看状态
ubuntu@raspberry-pi:/root$ sudo systemctl status gogs
● gogs.service - Gogs
     Loaded: loaded (/lib/systemd/system/gogs.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2024-09-06 09:53:16 CST; 9s ago
   Main PID: 4880 (gogs)
      Tasks: 8 (limit: 9254)
     CGroup: /system.slice/gogs.service
             └─4880 /www/wwwroot/gogs/gogs web

Sep 06 09:53:16 raspberry-pi systemd[1]: Started Gogs.
Sep 06 09:53:16 raspberry-pi gogs[4880]: 2024/09/06 09:53:16 [TRACE] Log mode: File (Info)

启动成功
最后讲讲是什么问题导致Gogs启动失败。
根本的原因还是因为gogs启动需要root权限。

  • 9
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值