• 欢迎访问吴爸爸的技术小木屋

ubuntu18.04使用systemd设置开机启动

ubuntu wutianjun5858@163.com 4年前 (2021-05-31) 2116次浏览 0个评论

pic

1. 创建service文件

  1. sudo touch /etc/systemd/system/test.service

test.service中的test根据你的要求进行修改。

2. 向service文件添加内容

可以使用nano或者vim或者gedit打开xxx.service

  1. [Unit]
  2. Description=[程序的描述]
  3. [Service]
  4. Type=simple
  5. User=[程序的用户]
  6. ExecStart=[程序路径]
  7. Restart=on-failure
  8. [Install]
  9. WantedBy=multi-user.target
描述
程序的描述 就是对这个service的描述
程序的用户 可以是root也可以是你自己的用户名
程序的路径 就是bin文件或者shell脚本放在的路径

示例:

  1. [Unit]
  2. Description=test daemon
  3. [Service]
  4. Type=simple
  5. User=root
  6. ExecStart=/opt/test/test1
  7. Restart=on-failure
  8. [Install]
  9. WantedBy=multi-user.target

3. 激活service

  1. sudo systemctl daemon-reload
  2. sudo systemctl enable test
  3. sudo systemctl start test
  4. sudo systemctl status test #查看test.service的状态

吴爸爸的技术小木屋 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:ubuntu18.04使用systemd设置开机启动
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址