gogs git NSSM 安装弹窗配置

本文详细介绍了如何使用NSSM在Windows环境下将Gogs安装为系统服务的过程,包括配置路径、日志输出、错误处理及环境变量设置,确保Gogs能够作为自托管Git服务稳定运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Use NSSM

Get the nssm.exe needed for your machine (32 or 64 bit; they’re packaged together in Iain’s zip file), and place it in a directory that is in (or will be added to) your %PATH% environment variable.

Open a command line as administrator and do following command to configure Gogs as a service:

C:\>nssm install gogs

“NSSM service installer” will appear. Configure it as follows:

Application tab:

  • Path: C:\gogs\gogs.exe  为gogs的exe文件所在位置
  • Startup directory: C:\gogs
  • Arguments: web

Details tab:

  • Display name: Gogs
  • Description: A painless self-hosted Git service.
  • Startup type: Automatic (Delayed Start)

Note that we’ve chosen delayed start, so that the service will not impact the early boot time. Gogs will start two minutes after the non-delayed services.

I/O tab:

  • Output (stdout): C:\gogs\log\gogs-nssm.txt
  • Error (stderr): C:\gogs\log\gogs-nssm.txt

That will capture all text output that you would normally receive from Gogs on the command line console, and log it to that file instead.

File rotation tab:

  • Check: Rotate files
  • Restrict rotation to files bigger than: 1000000 bytes

Environment tab:

  • Environment variables: PATH=%PATH%;C:\gogs;C:\Program Files (x86)\Git\bin

That is a guarantee that both gogs.exe and git.exe will be on the Gogs service’s path variable during runtime.

Click “Install service”, and you should be confirmed that it succeeded.

If it failed, refer back to the command line console you started, for the error message. When it succeeds, go to command line and do:

nssm start gogs

You should see:

gogs: START: The operation completed successfully.

Check that this is true by opening C:\gogs\log\gogs-nssm.txt. You should see Gogs’ start up procedures, ending with:

timestamp [I] Run Mode: Production
timestamp [I] Listen: http://127.0.1.1:80

Now point your web browser at http://gogs/ and log in.

Gogs is running as a service, and will not need to be run manually, unless something goes wrong. NSSM will attempt to restart the service for you, if the Gogs server crashes.

When you need to restart it after app.ini changes, go to an administrator command line after the changes, and do:

nssm restart gogs

See the configuration cheat sheet for reference of the custom\conf\app.ini settings.

An example of the logging and error handling in action:

[log]
ROOT_PATH = C:\gogs\log

At the time of writing this line, it will cause the following to print in C:\gogs\log\gogs-nssm.txt:

timestamp [T] Custom path: C:/gogs/custom
timestamp [T] Log path: C:\gogs\log
timestamp [I] Gogs x.y.z
timestamp [log.go:294 Error()] [E] Fail to set logger(file): invalid character 'g' in string escape code

This is what was expected in C:\custom\conf\app.ini:

ROOT_PATH = C:/gogs/log

And this was the nssm interaction while solving it:

C:\>nssm restart gogs
gogs: STOP: The operation completed successfully.
gogs: Unexpected status SERVICE_PAUSED in response to START control.

C:\>nssm start gogs
gogs: START: An instance of the service is already running.

C:\>nssm stop gogs
gogs: STOP: The operation completed successfully.

C:\>nssm start gogs
gogs: Unexpected status SERVICE_PAUSED in response to START control.

C:\>nssm restart gogs
gogs: STOP: The operation completed successfully.
gogs: START: The operation completed successfully.
### 创建 Git 仓库于 Gogs #### 准备工作 为了确保能够顺利创建 Git 仓库,在此之前需确认已成功安装并运行 Gogs 应用程序。通常情况下,这涉及创建 `git` 用户以及设置必要的权限和路径。 对于环境准备部分,命令如下所示: ```bash sudo useradd git sudo passwd git sudo chmod -R 700 /usr/local/gogs sudo chown -R git:git /usr/local/gogs mkdir -p /data/gogs/repositories chown -R git:git /data/gogs/ ``` 这些指令用于初始化系统账户、调整文件夹访问控制列表,并指定存储库的位置[^1]。 #### 登录 Web 界面 完成上述准备工作之后,通过浏览器访问 Gogs 的管理面板地址(通常是 http://your_server_ip_or_domain:3000),登录管理员账号进入后台管理系统。 #### 新建仓库流程 在 Gogs 中创建新的 Git 项目非常直观简单: - 导航至页面顶部菜单栏中的 “New Repository” 或者点击左侧边栏里的相应选项来启动向导; - 输入想要赋予该仓库的名字和其他描述信息; - 设置是否公开共享此资源还是仅限私人可见; - 如果希望自动填充 `.gitignore` 文件或 LICENSE 文档,则可以选择对应的模板; - 完成表单填写后提交即可立即建立一个新的空版本控制系统空间供开发者们协作开发使用[^4]。 #### 初始化本地副本并与远程连接 一旦在线端完成了新建操作,下一步就是在个人计算机上克隆这份空白的 Git 仓库作为工作的起点。打开终端窗口执行下面给出的一系列 Git 命令序列可以实现这一点: ```bash cd path/to/work/directory git init . touch README.md git remote add origin ssh://git@your_gogs_host:port/username/repository.git git pull origin master --allow-unrelated-histories git push -u origin master ``` 以上脚本片段展示了怎样关联远端服务器上的裸仓库存储区到当前所在的工作目录,并推送初始提交记录上去[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值