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

相关文章

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

Springboot项目启动失败提示找不到dao类的解决

《Springboot项目启动失败提示找不到dao类的解决》SpringBoot启动失败,因ProductServiceImpl未正确注入ProductDao,原因:Dao未注册为Bean,解决:在启... 目录错误描述原因解决方法总结***************************APPLICA编

MySQL中EXISTS与IN用法使用与对比分析

《MySQL中EXISTS与IN用法使用与对比分析》在MySQL中,EXISTS和IN都用于子查询中根据另一个查询的结果来过滤主查询的记录,本文将基于工作原理、效率和应用场景进行全面对比... 目录一、基本用法详解1. IN 运算符2. EXISTS 运算符二、EXISTS 与 IN 的选择策略三、性能对比

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

使用Python构建智能BAT文件生成器的完美解决方案

《使用Python构建智能BAT文件生成器的完美解决方案》这篇文章主要为大家详细介绍了如何使用wxPython构建一个智能的BAT文件生成器,它不仅能够为Python脚本生成启动脚本,还提供了完整的文... 目录引言运行效果图项目背景与需求分析核心需求技术选型核心功能实现1. 数据库设计2. 界面布局设计3

使用IDEA部署Docker应用指南分享

《使用IDEA部署Docker应用指南分享》本文介绍了使用IDEA部署Docker应用的四步流程:创建Dockerfile、配置IDEADocker连接、设置运行调试环境、构建运行镜像,并强调需准备本... 目录一、创建 dockerfile 配置文件二、配置 IDEA 的 Docker 连接三、配置 Do

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

python使用try函数详解

《python使用try函数详解》Pythontry语句用于异常处理,支持捕获特定/多种异常、else/final子句确保资源释放,结合with语句自动清理,可自定义异常及嵌套结构,灵活应对错误场景... 目录try 函数的基本语法捕获特定异常捕获多个异常使用 else 子句使用 finally 子句捕获所

Debian系和Redhat系防火墙配置方式

《Debian系和Redhat系防火墙配置方式》文章对比了Debian系UFW和Redhat系Firewalld防火墙的安装、启用禁用、端口管理、规则查看及注意事项,强调SSH端口需开放、规则持久化,... 目录Debian系UFW防火墙1. 安装2. 启用与禁用3. 基本命令4. 注意事项5. 示例配置R

C++11右值引用与Lambda表达式的使用

《C++11右值引用与Lambda表达式的使用》C++11引入右值引用,实现移动语义提升性能,支持资源转移与完美转发;同时引入Lambda表达式,简化匿名函数定义,通过捕获列表和参数列表灵活处理变量... 目录C++11新特性右值引用和移动语义左值 / 右值常见的左值和右值移动语义移动构造函数移动复制运算符