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

2024-09-07 08:36

本文主要是介绍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开机启动的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1144583

相关文章

Pandas使用SQLite3实战

《Pandas使用SQLite3实战》本文主要介绍了Pandas使用SQLite3实战,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录1 环境准备2 从 SQLite3VlfrWQzgt 读取数据到 DataFrame基础用法:读

JSON Web Token在登陆中的使用过程

《JSONWebToken在登陆中的使用过程》:本文主要介绍JSONWebToken在登陆中的使用过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录JWT 介绍微服务架构中的 JWT 使用结合微服务网关的 JWT 验证1. 用户登录,生成 JWT2. 自定义过滤

Java中StopWatch的使用示例详解

《Java中StopWatch的使用示例详解》stopWatch是org.springframework.util包下的一个工具类,使用它可直观的输出代码执行耗时,以及执行时间百分比,这篇文章主要介绍... 目录stopWatch 是org.springframework.util 包下的一个工具类,使用它

Java使用Curator进行ZooKeeper操作的详细教程

《Java使用Curator进行ZooKeeper操作的详细教程》ApacheCurator是一个基于ZooKeeper的Java客户端库,它极大地简化了使用ZooKeeper的开发工作,在分布式系统... 目录1、简述2、核心功能2.1 CuratorFramework2.2 Recipes3、示例实践3

springboot security使用jwt认证方式

《springbootsecurity使用jwt认证方式》:本文主要介绍springbootsecurity使用jwt认证方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录前言代码示例依赖定义mapper定义用户信息的实体beansecurity相关的类提供登录接口测试提供一

go中空接口的具体使用

《go中空接口的具体使用》空接口是一种特殊的接口类型,它不包含任何方法,本文主要介绍了go中空接口的具体使用,具有一定的参考价值,感兴趣的可以了解一下... 目录接口-空接口1. 什么是空接口?2. 如何使用空接口?第一,第二,第三,3. 空接口几个要注意的坑坑1:坑2:坑3:接口-空接口1. 什么是空接

SpringBoot日志配置SLF4J和Logback的方法实现

《SpringBoot日志配置SLF4J和Logback的方法实现》日志记录是不可或缺的一部分,本文主要介绍了SpringBoot日志配置SLF4J和Logback的方法实现,文中通过示例代码介绍的非... 目录一、前言二、案例一:初识日志三、案例二:使用Lombok输出日志四、案例三:配置Logback一

springboot security快速使用示例详解

《springbootsecurity快速使用示例详解》:本文主要介绍springbootsecurity快速使用示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录创www.chinasem.cn建spring boot项目生成脚手架配置依赖接口示例代码项目结构启用s

Python如何使用__slots__实现节省内存和性能优化

《Python如何使用__slots__实现节省内存和性能优化》你有想过,一个小小的__slots__能让你的Python类内存消耗直接减半吗,没错,今天咱们要聊的就是这个让人眼前一亮的技巧,感兴趣的... 目录背景:内存吃得满满的类__slots__:你的内存管理小助手举个大概的例子:看看效果如何?1.

springboot security之前后端分离配置方式

《springbootsecurity之前后端分离配置方式》:本文主要介绍springbootsecurity之前后端分离配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的... 目录前言自定义配置认证失败自定义处理登录相关接口匿名访问前置文章总结前言spring boot secu