创建一个服务文件:在 /etc/systemd/system/ 目录下创建一个以 .service 结尾的文件,比如 myservice.service
[Unit] Description=My Service After=network.target [Service] ExecStart=/path/to/your/service/executable WorkingDirectory=/path/to/your/service/directory User=your_username Group=your_groupname Restart=always [Install] WantedBy=default.target
重新加载 systemd 配置:sudo systemctl daemon-reload
设置开机自启动: sudo systemctl enable myservice
启动和管理服务:可以使用以下命令来启动、停止、重启和查看服务状态:
启动服务:sudo systemctl start myservice 停止服务:sudo systemctl stop myservice 重启服务:sudo systemctl restart myservice 查看服务状态:sudo systemctl status myservice
标签:服务,service,自定义,sudo,myservice,systemctl,添加,your From: https://www.cnblogs.com/yujian2022/p/18351429