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

ops/2024/9/23 8:46:48/

先说现象,大家用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权限。


http://www.ppmy.cn/ops/109569.html

相关文章

vue3项目监听浏览器的返回按键事件

有这样一个需求,当在用户在浏览器点击返回按钮的时候,需要弹出当前组件的退出确认框。并且如果当前页面有个已经打开了的弹窗时,弹窗还没关闭就点击浏览器的返回按钮,要求点击返回时,弹窗要关闭。 解决: …

使用Python实现多个PDF文件的合并

使用Python可以很方便地实现多个PDF文件的合并。我们可以使用PyPDF2库来完成这个任务。以下是一个实现PDF合并的Python脚本: import os from PyPDF2 import PdfMergerdef merge_pdfs(input_dir, output_filename):# 创建一个PdfMerger对象merger PdfMerger()# 获取…

【深度学习】Pytorch基础

目录 梯度下降算法(Gradient Descent)代码实现 梯度下降算法(Gradient Descent) 梯度下降算法在机器学习中应用十分的广泛,不论是在线性回归还是Logistic回归中,它的主要目的是通过迭代找到目标函数的最小…

【网络安全】古典密码体制概述

1. 古典密码体制概述 1.1 定义与历史背景 古典密码体制是指在计算机科学和信息安全技术出现之前的传统加密方法。这些方法主要包括替换和易位两种基本形式。古典密码体制的特点是简单、易用,但安全性不高,容易被破解。在古代,人们使用纸、笔…

java发送邮件报错,Could not connect to SMTP host: smtp.exmail.qq.com, port: 465

发现问题 我使用的 docker 运行的 jdk 环境,服务调用发送邮件报错 javax.mail.MessagingException: Could not connect to SMTP host: smtp.exmail.qq.com, port: 465;nested exception is:javax.net.ssl.SSLHandshakeException: No appropriate protocol (protoc…

【数据结构】排序算法系列——希尔排序(附源码+图解)

希尔排序 算法思想 希尔排序(Shell Sort)是一种改进的插入排序算法,希尔排序的创造者Donald Shell想出了这个极具创造力的改进。其时间复杂度取决于步长序列(gap)的选择。我们在插入排序中,会发现是对整体…

店匠科技携手Stripe共谋电商支付新篇章

在全球电商行业蓬勃发展的背景下,支付环节作为交易闭环的核心,其重要性日益凸显。随着消费者对支付体验要求的不断提高,以及跨境电商的迅猛发展,支付市场正经历着前所未有的变革与挑战。在这一充满机遇与竞争的领域,店匠科技(Shoplazza)凭借其创新的嵌入式支付解决方案—— Sho…

Apache SeaTunnel基础介绍

一、什么是Apache SeaTunnel? Apache SeaTunnel(最初名为Waterdrop)是一个开源的分布式数据集成平台,专为大规模数据处理设计。SeaTunnel可以从多种数据源读取数据,进行实时流式处理或批处理,然后将处理后…