现有一个一次性脚本,需要在开机时以特定用户和组执行(执行后该脚本相当于以后台守护的方式执行)。
现在有以下几种方案:
rc.local:写进去是写进去了但是不知道为什么死活不生效。- SystemD:创建了 Service 配置文件,但是会报错,也没有正确启动。
目前已经确认的是rc.local已经加了对应的权限:
[root@testbench-C ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Sep 18 23:46 /etc/rc.local -> rc.d/rc.local
[root@testbench-C ~]# ll /etc/rc.d/rc.local
-rwxr--r--. 1 root root 542 Oct 17 22:04 /etc/rc.d/rc.local
SystemD 配置文件:
[Unit]
Description=myservice
After=syslog.target
After=network.target
[Service]
Type=oneshot
User=myuser
Group=myuser
ExecStart=/home/tsh2/my.sh start
[Install]
WantedBy=multi-user.target
