当前位置:   article > 正文

Ubuntu开机自启服务systemd.service配置教程_ubuntu service 开机启动

ubuntu service 开机启动

Ubuntu中配置开机自启服务(systemd.service)的步骤如下:

  1. 创建一个新的 your_service_name.service文件,其中 your_service_name是你自定义的服务名称。
  2. 在 your_service_name.service文件中添加以下内容:
  1. [Unit]
  2. Description=Your Service Description
  3. After=network.target
  4. [Service]
  5. Type=simple
  6. ExecStart=/path/to/your/service/executable
  7. Restart=on-failure
  8. [Install]
  9. WantedBy=multi-user.target
  1. 在 [Unit]部分,填写你的服务描述。
  2. 在 [Service]部分,将 /path/to/your/service/executable替换为你实际服务的可执行文件路径。
  3. 在 [Install]部分,设置服务启动的级别为 multi-user.target,这将在多用户模式下启动服务。
  4. 将编辑好的 your_service_name.service文件保存在 /etc/systemd/system/目录下。
  5. 在终端中,运行以下命令使配置生效:
sudo systemctl daemon-reload
  1. 启动你的服务并设置为开机自启:
  1. sudo systemctl enable your_service_name
  2. sudo systemctl start your_service_name

现在,你的服务将在Ubuntu开机时自动启动,并在之后的启动中持续运行。记得根据你的实际需求修改 your_service_name.service文件中的相关信息。

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号