I have a python script to switch light/dark mode.
At the end there's this line:
process = subprocess.Popen(binDir + "/polybar.sh")
That script it points to is this:
#!/bin/env bash
# Terminate already running bar instances
killall -q polybar
polybar >/dev/null 2>/dev/null
If I execute the light/dark script from terminal it works perfectly, polybar gets killed and then relaunched.
However, I want a service to automatically switch depending on the time of the day, so I made some systemd timers. The light/dark script gets executed, most of the stuff in it works, but this in particular doesn't, it just kills polybar and it doesn't launch again. The systemd service is a user service.
I don't know how to troubleshoot this, systemctl status
is not providing any info.
Why would a script work fine when launched from terminal, but not from systemd?
Here is the service file:
[Unit]
Type=simple
Description=dark mode
Environment="PATH=/home/{{ user }}/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/{{ user }}/bin"
WorkingDirectory=/home/{{ user }}/bin
[Service]
ExecStartPre=/usr/bin/brightnessctl s 200
ExecStart=/usr/bin/python /home/ger/bin/nutra.py dark
And the timer:
[Unit]
Description=Turn screen dark/light at certain times
[Timer]
OnCalendar=*-*-* 18:13:00
Persistent=true
[Install]
WantedBy=timers.target
bindir
defined in the python script and is$PATH
set differently between the systemd and interactive environments?binDir = os.path.expanduser('~') + "/bin"
After reading a stackexchange answer, I added this to the systemd service:Environment="PATH=/home/{{ user }}/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/{{ user }}/bin"
However it didn't help.The light/dark script gets executed, most of the stuff in it works, but this in particular doesn't, it just kills polybar and it doesn't launch again. The systemd service is a user service. I don't know how to troubleshoot this, systemctl status is not providing any info.
To properly answer that you should provide the contents of both the timer and service units you used.\ My educated guess is that you usedRemainAfterExit=true
in the service file.polybar > /home/username/polybar.log
instead ofpolybar &>/dev/null
). Most GUI applications require the environment varDISPLAY=:0
Try to addexport DISPLAY=:0
to your shell script below the shebang.polybar --reload
is enough to reload new settings ... To get the results withjournalctl -t polybar
. Runpolybar --reload | systemd-cat -t polybar