本文主要是介绍Ubuntu20.04使用systemd配置Gogs开机启动,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
先说现象,大家用sudo systemctl start gogs是不是和我一样?
ubuntu@raspberry-pi:~$ sudo systemctl status gogs
● gogs.service - GogsLoaded: 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 agoProcess: 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 - GogsLoaded: loaded (/lib/systemd/system/gogs.service; enabled; vendor preset: enabled)Active: active (running) since Fri 2024-09-06 09:53:16 CST; 9s agoMain PID: 4880 (gogs)Tasks: 8 (limit: 9254)CGroup: /system.slice/gogs.service└─4880 /www/wwwroot/gogs/gogs webSep 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权限。
这篇关于Ubuntu20.04使用systemd配置Gogs开机启动的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!