Stuffing ten Environment= lines into a unit file works, but I’d much rather keep the settings next to the app and leave the unit alone. EnvironmentFile= reads them from a plain text file instead.
The file holds one KEY=value per line. Empty lines and lines starting with # or ; are ignored, so you can comment it. In the unit (or a drop-in from systemctl edit) you point at it:
[Service]
EnvironmentFile=-/etc/default/myapp
ExecStart=/usr/local/bin/myapp --port ${PORT}
And /etc/default/myapp could look like this:
# settings for myapp
PORT=8080
DATA_DIR=/mnt/user/appdata/myapp
LOG_LEVEL=info
The - in front of the path is the bit people miss. Without it, a missing or unreadable file makes the service fail to start. With it, systemd silently skips the file, which is handy for an optional override. You can list EnvironmentFile= more than once; every file is read. Changes are picked up the next time the service starts, because systemd reads the file just before it launches the process, so a systemctl restart myapp is enough. No daemon-reload needed for edits to the file itself.
Two caveats. The path doesn’t expand shell variables like $HOME (use the %h specifier), and the file is parsed with shell-style quoting but never executed, so command substitution in it won’t run. And don’t treat it as a vault for passwords: the systemd.exec manual warns that environment variables of a unit are visible to unprivileged clients over D-Bus and get passed down to child processes. For secrets, LoadCredential= is the better tool.
Further reading: systemd.exec(5) manual page