Start Conky as a systemd service
More than a year ago I posted about Conky to show system stats on my desktop. Back then I used the Ubuntu "Startup Applications Preferences" app to start Conky on boot, well user logon really.
That didn't work prefectly all of the time. Sometimes some items weren't ready to load yet and during configuration of my config, I had to kill the program and restart the script. Not ideal at all.
So instead, with some help from LLM's, I created a systemd service.
conky.service
[Unit]
Description=Conky System Monitor
After=default.target
Wants=default.target
[Service]
ExecStartPre=/bin/sleep 5
ExecStart=/home/joep/repositories/joeplaa/joeplaa-conky/start_conky.sh
WorkingDirectory=/home/joep/repositories/joeplaa/joeplaa-conky
Environment=DISPLAY=:1
Restart=always
RestartSec=3
Type=simple
[Install]
WantedBy=default.target
- Find display:
echo $DISPLAY
- Create:
~/.config/systemd/user/conky.service
and copy content - Enable:
systemctl enable conky.service
- Start:
systemctl start conky.service
Don't remember if it was ChatGPT or Grok which advised me to create the bash script below to detect the display. I don't think it really matters as I define the display in the service file, but I don't have the time and motivation to find out. The current setup works.
start_conky.sh
#!/bin/bash
# Improved DISPLAY detection: Try common displays or fallback
timeout=30
while [ $timeout -gt 0 ] && [ -z "$DISPLAY" ]; do
# Check for active displays (adjust if needed)
for disp in :0 :1; do
if xset -display $disp q >/dev/null 2>&1; then
DISPLAY=$disp
break
fi
done
if [ -z "$DISPLAY" ]; then
sleep 1
timeout=$((timeout - 1))
fi
done
if [ -z "$DISPLAY" ]; then
echo "No DISPLAY found, exiting."
exit 1
fi
export DISPLAY
exec /usr/bin/conky -c conkyrc
Full repo on Github
GitHub - joeplaa/joeplaa-conky: joeplaa Conky config based on https://www.github.com/SZinedine/pomaria-side
joeplaa Conky config based on https://www.github.com/SZinedine/pomaria-side - joeplaa/joeplaa-conky