我是swaywm的新用户,在创建自己的自定义systemd services方面相当新手。我之前使用Openbox、feh和systemd创建了一个脚本墙纸,每隔30分钟更换一次。下面是一个在openbox中运行良好的foo.service:
[Unit]
Description=wallpaper rotate service
RefuseManualStart=no
RefuseManualStop=no
[Service]
Type=oneshot
User=trentonknight
ExecStart=/bin/sh -c 'DISPLAY=:0.0 feh --recursive --randomize --bg-fill /home/trentonknight/Pictures/Wallpaper/*'这是每30分钟运行一次的计时器:
[Unit]
Description=wallpaper rotate timer
RefuseManualStart=no
RefuseManualStop=no
[Timer]
Persistent=false
OnCalendar=*:0/30
Unit=wrotate.service
[Install]
WantedBy=default.targetSwaywm使用Wayland合成器,非常棒。然而,feh只适用于X。没有feh,我可以使用swaywm原生的这个简单命令轻松地更改我的墙纸:
swaymsg output DP-3 bg foo_background.pngDP-3是之前运行此命令的结果:
swaymsg -t get_outputs在bash脚本中使用上面的output命令,我可以在目录中自动为墙纸随机选择图像。当从命令行运行时没有问题时,这是有效的:
#!/bin/bash
NEW=$(ls ~/Pictures/Wallpaper/ | shuf -n 1)
NEW_SWAY_BACK="~/Pictures/Wallpaper/"$NEW
swaymsg output DP-3 bg $NEW_SWAY_BACK fill但是,如果我尝试从以下自定义服务调用此bash脚本,则会失败。下面是首先提供的服务:
[Unit]
Description=swaymsg output rotate wallpaper service
RefuseManualStart=no
RefuseManualStop=no
[Service]
WorkingDirectory=/usr/share/backgrounds/sway/
Type=forking
User=trentonknight
ExecStart=/usr/bin/bash sway_backgroud_changer.sh
KillMode=process这是我尝试过的许多版本中的一个,但它们在启动后都具有相同的状态:
[trentonknight@archboX system]$ sudo systemctl status swaywallr.service
* swaywallr.service - swaymsg output rotate wallpaper service
Loaded: loaded (/etc/systemd/system/swaywallr.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2018-05-12 18:37:17 EDT; 5s ago
Process: 30491 ExecStart=/usr/bin/bash sway_backgroud_changer.sh (code=exited, status=1/FAILURE)
May 12 18:37:17 archboX systemd[1]: Starting swaymsg output rotate wallpaper service...
May 12 18:37:17 archboX bash[30491]: sway socket not detected.
May 12 18:37:17 archboX bash[30491]: E: 05/12/18 18:37:17 - [ipc-client.c:37] Unable to connect to
May 12 18:37:17 archboX systemd[1]: swaywallr.service: Control process exited, code=exited status=1
May 12 18:37:17 archboX systemd[1]: swaywallr.service: Failed with result 'exit-code'.
May 12 18:37:17 archboX systemd[1]: Failed to start swaymsg output rotate wallpaper service.
[Install]
WantedBy=multi-user.target我看到SWAYSOCK如下所示:
[trentonknight@archboX system]$ echo $SWAYSOCK
/run/user/1000/sway-ipc.1000.527.sock我不知道如何正确地调用它。或者即使这就是问题所在?此外,我正在运行以下程序:
[trentonknight@archboX system]$ uname -a
Linux archboX 4.16.8-1-ARCH #1 SMP PREEMPT Wed May 9 11:25:02 UTC 2018 x86_64 GNU/Linux我也对其他方法持开放态度。我看到有一个swaybg,但运行时给出了以下打印输出,并且手册页根本不包含swaybg:
[trentonknight@archboX sway]$ swaybg
05/12/18 18:43:26 - [main.c:63] Do not run this program manually. See man 5 sway and look for output options.我猜它还在开发中。
发布于 2018-05-14 08:51:37
感谢#sway on freenode的男孩和女孩,我能够通过简单地使用以下命令来解决这个问题:
systemctl --user我没有意识到用户级服务与系统服务是分开的。最后,我的脚本是非常基本的运行方式:
.config/systemd/user/我不得不补充一下:
systemctl --user import-environment暂时复制到我的.bashrc,直到我可以分析丢失了哪条路径。无论如何,如果你遇到类似的情况,请查看:
https://wiki.archlinux.org/index.php/Systemd/User
如果任何人感兴趣的自动改变他们的桌面墙纸在摇摆,以下工作。创建以下目录和文件,并按您认为适合服务的名称命名:
mkdir -p ~/.config/systemd/user
touch ~/.config/systemd/user/foo.service
touch ~/.config/systemd/user/foo.timerfoo.service
[Unit]
Description=swaymsg output rotate wallpaper service
[Service]
ExecStart=/usr/share/backgrounds/sway/sway_backgroud_changer.sh
[Install]
WantedBy=multi-user.targetfoo.timer将时间设置为您想要的时间。下面是59分钟。
[Unit]
Description=wallpaper rotate timer
RefuseManualStart=no
RefuseManualStop=no
[Timer]
Persistent=false
OnCalendar=*:0/59
Unit=foo.service
[Install]
WantedBy=default.target旋转墙纸的Bash脚本:
[trentonknight@archboX user]$ cat /usr/share/background/sway/sway_backgroud_changer.sh
#!/bin/bash
NEW=$(ls ~/Pictures/Wallpaper/ | shuf -n 1)
NEW_SWAY_BACK="~/Pictures/Wallpaper/"$NEW
swaymsg -s $SWAYSOCK output DP-3 bg $NEW_SWAY_BACK fill我还没有确定一个更好的方法来确保在这个服务运行之前设置好路径,至少今晚是这样,所以把这个附加到你的.bashrc中,或者使用Arch linux教程来改进它:
[trentonknight@archboX ~]$ cat .bashrc
systemctl --user import-environment在下次登录前运行以启用:
systemctl --user enable foo.timer如果您想在计时器之前进行测试:
systemctl --user start foo.service最后一件事。请确保在~/Pictures/Wallpaper中或您编辑路径的位置有一些高质量的图像,以便从中加载图像。DP-3是我的输出验证您是否使用:
swaymsg -t get_outputshttps://stackoverflow.com/questions/50311320
复制相似问题