You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

run-as-service-in-ubuntu.zh-cn.md 1.7KB

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