ubuntu 创建一个服务程序
- 编写服务单元文件
创建一个新的服务单元文件通常在 /etc/systemd/system/ 目录下,文件扩展名为 .service。例如,你可以创建一个名为 my_service.service 的文件。
1 | [Unit] |
- 启动服务
1 | sudo systemctl daemon-reload |
- 设置服务为开机自启动
1 | sudo systemctl enable my_service.service |
- 检查服务状态
1 | sudo systemctl status my_service.service |
- 停止和禁用服务
1 | sudo systemctl stop my_service.service |
- 查询服务
1 | sudo systemctl list-units --type=service |