赞
踩
在Ubuntu中配置开机自启服务(systemd.service)的步骤如下:
your_service_name.service
文件,其中 your_service_name
是你自定义的服务名称。your_service_name.service
文件中添加以下内容:- [Unit]
- Description=Your Service Description
- After=network.target
-
- [Service]
- Type=simple
- ExecStart=/path/to/your/service/executable
- Restart=on-failure
-
- [Install]
- WantedBy=multi-user.target
[Unit]
部分,填写你的服务描述。[Service]
部分,将 /path/to/your/service/executable
替换为你实际服务的可执行文件路径。[Install]
部分,设置服务启动的级别为 multi-user.target
,这将在多用户模式下启动服务。your_service_name.service
文件保存在 /etc/systemd/system/
目录下。sudo systemctl daemon-reload
- sudo systemctl enable your_service_name
- sudo systemctl start your_service_name
现在,你的服务将在Ubuntu开机时自动启动,并在之后的启动中持续运行。记得根据你的实际需求修改 your_service_name.service
文件中的相关信息。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。