code.gitea.io/gitea@v1.22.3/docs/content/installation/run-as-service-in-ubuntu.zh-cn.md (about) 1 --- 2 date: "2017-07-21T12:00:00+02:00" 3 title: "在 Linux 中以 service 方式运行" 4 slug: "linux-service" 5 sidebar_position: 40 6 toc: false 7 draft: false 8 aliases: 9 - /zh-cn/linux-service 10 menu: 11 sidebar: 12 parent: "installation" 13 name: "在Linux中以service方式运行" 14 sidebar_position: 40 15 identifier: "linux-service" 16 --- 17 18 ### 在 Ubuntu 16.04 LTS 中以 service 方式运行 19 20 #### systemd 方式 21 22 在 terminal 中执行以下命令: 23 24 ``` 25 sudo vim /etc/systemd/system/gitea.service 26 ``` 27 28 接着拷贝示例代码 [gitea.service](https://github.com/go-gitea/gitea/blob/main/contrib/systemd/gitea.service) 并取消对任何需要运行在主机上的服务部分的注释,譬如 MySQL。 29 30 修改 user,home 目录以及其他必须的初始化参数,如果使用自定义端口,则需修改 PORT 参数,反之如果使用默认端口则需删除 -p 标记。 31 32 激活 gitea 并将它作为系统自启动服务: 33 34 ``` 35 sudo systemctl enable gitea 36 sudo systemctl start gitea 37 ``` 38 39 #### 使用 supervisor 40 41 在 terminal 中执行以下命令安装 supervisor: 42 43 ``` 44 sudo apt install supervisor 45 ``` 46 47 为 supervisor 配置日志路径: 48 49 ``` 50 # assuming gitea is installed in /home/git/gitea/ 51 mkdir /home/git/gitea/log/supervisor 52 ``` 53 54 在文件编辑器中打开 supervisor 的配置文件: 55 56 ``` 57 sudo vim /etc/supervisor/supervisord.conf 58 ``` 59 60 增加如下示例配置 61 [supervisord config](https://github.com/go-gitea/gitea/blob/main/contrib/supervisor/gitea)。 62 63 将 user(git) 和 home(/home/git) 设置为与上文部署中匹配的值。如果使用自定义端口,则需修改 PORT 参数,反之如果使用默认端口则需删除 -p 标记。 64 65 最后激活 supervisor 并将它作为系统自启动服务: 66 67 ``` 68 sudo systemctl enable supervisor 69 sudo systemctl start supervisor 70 ```