brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemctl show-environment shows the variables every systemd service starts with

Systemd
~/tips/tip-systemd-show-environment

systemctl show-environment

Check which PATH and other variables services get, since they never read your shell profile.

A script that works in your shell and fails as a service is very often an environment problem. Services do not read .bashrc or /etc/profile; they start from the block the service manager hands out.

Print that block:

systemctl show-environment

On a fresh Ubuntu container it holds little more than LANG=C.UTF-8 and a short PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin. So a tool installed in ~/.local/bin or /opt/something/bin is simply not found, and anything you exported in your profile, like a proxy or an API endpoint, is missing too.

The man page notes that per unit settings are not included. Environment= and EnvironmentFile= lines come on top of this block, so check those with systemctl show myapp -p Environment.

You can change the block at runtime:

sudo systemctl set-environment HTTPS_PROXY=http://proxy.example.com:3128
sudo systemctl unset-environment HTTPS_PROXY

The variable shows up in show-environment right after the first command and is gone after the second. Services started after that inherit it.

I would not use set-environment as a fix, though. It is lost at reboot and affects every service at once. Put what one service needs in its own unit with Environment=, and use full paths in ExecStart=.

Further reading: systemctl man page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link