1.首先准备好启动脚本和设置好脚本的权限
$ vi /etc/init.d/mydemo
输入以下内容:
#!/bin/sh
echo "####Hello,MYZR###" > /dev/ttymxc1
wq保存结束输入
修改为可以执行权限
$ chmod +x /etc/init.d/mydemo
2.进入/etc/systemd/system目录,创建服务mydemo.service文件
$ vi /etc/systemd/system/mydemo.service
输入以下内容:
[Unit]
Description=just for test
After=banner.service
[Service]
ExecStart=/etc/init.d/mydemo
# 重新加载配置文件$ systemctl daemon-reload
$ systemctl enable mydemo.service
输出以下信息:
Synchronizing state of mydemo.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mydemo
System startup links for /etc/init.d/mydemo already exist.