Linux systemd 自启动脚本无法正常运行(求助分析方向)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux systemd 自启动脚本无法正常运行(求助分析方向)相关的知识,希望对你有一定的参考价值。

在RHEL8.0上,通过systemd service用以下脚本来实现登录后自动切换壁纸。

服务为test.service, bash脚本为test.sh

单独运行Set_background.sh 没有问题,但是当通过test.service去调用的时候,只能设置一次。
设置壁纸的命令成功,但是重置的命令失败。
考虑是因为通过test.service去调用test.sh时,线程出现问题。
请高手指教从哪里去分析。

test.service内容如下:
[Unit]
Description=Change Desktop background

[Service]
ExecStart=/home/test/Desktop/Set_background.sh
After=gdm.service

[Install]
WantedBy=graphical.target

Set_background.sh内容如下:
#!/bin/bash
while true
do
/usr/bin/gsettings set org.gnome.desktop.background picture-uri 'file:///home/test/Desktop/8-dark.xml'
sleep 3
/usr/bin/gsettings reset org.gnome.desktop.background picture-uri
sleep 3

done

参考技术A chmod +X /etc/rc.d/rc.local

以上是关于Linux systemd 自启动脚本无法正常运行(求助分析方向)的主要内容,如果未能解决你的问题,请参考以下文章

centos 7 rc.local 不启动

Linux 初始化之 Systemd机制

尝试使用 systemd 启动 python 脚本,但它在 Raspberry Pi 上不起作用

Ubuntu20.04设置开机自启脚本开机自启命令(ubuntu自启,ubuntu开机自启)rc(run command)(systemd)(/etc/rc.local)(开机启动原理)开机自启动

Ubuntu20.04设置开机自启脚本开机自启命令(ubuntu自启,ubuntu开机自启)rc(run command)(systemd)(/etc/rc.local)(开机启动原理)

树莓派进阶之路 (033) - 开机启动自定义脚本