ubuntu18.04以上版本使用systemd 开启自启动服务

进入/etc/systemd/system/目录,创建myscript.service,并赋予权限

sudo vim /etc/systemd/system/myscript.service

Unit

Description=My Script Service

After=network.target

Service

User=root

ExecStart=/home/start.sh

Restart=always

Install

【其中User是开发板的用户名,米尔为root,
否则查看运行状态显示 myscript.service: Failed to determine user credentials: No such process
ExecStart是执行脚本,使用绝对路径表示】

输入一下指令:

sudo systemctl daemon-reload

sudo systemctl start myscript.service

sudo systemctl enable myscript.service

重启开发板后查看服务开启状态

sudo systemctl status myscript.service

关闭自启动服务

sudo systemctl stop myscript.service

sudo systemctl disable myscript.service

相关推荐
Yyyy482几秒前
Nginx负载均衡集群实验步骤
运维·nginx·负载均衡
绿箭柠檬茶38 分钟前
Ubuntu 服务器配置转发网络访问
服务器·网络·ubuntu
獭.獭.1 小时前
Linux -- 信号【上】
linux·运维·服务器
hashiqimiya1 小时前
centos配置环境变量jdk
linux·运维·centos
hashiqimiya1 小时前
权限更改centos中系统文件无法创建文件夹,使用命令让普通用户具备操作文件夹
linux
路由侠内网穿透2 小时前
本地部署 GPS 跟踪系统 Traccar 并实现外部访问
运维·服务器·网络·windows·tcp/ip
傻傻虎虎4 小时前
【Docker】常用帮忙、镜像、容器、其他命令合集(2)
运维·docker·容器
ZERO_pan5 小时前
服务器装机遇到的问题
运维·服务器
逆小舟5 小时前
【Linux】人事档案——用户及组管理
linux·c++
青草地溪水旁5 小时前
pthread_mutex_lock函数深度解析
linux·多线程·pthread