Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A systemd service that will not load and shows bad-setting

ErrorLoaded: bad-setting

Short answer

bad-setting is the load state systemd gives a unit when an essential setting in its file could not be parsed or is not allowed. Run systemd-analyze verify on the file first. The usual causes are a service with no ExecStart, a relative path in ExecStart, several commands in a non-oneshot service, or Restart=always on a oneshot.

  • Applies to systemd 255, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Let systemd check the file itself. It prints a line number for every directive it could not accept; read those lines before changing anything.

    systemd-analyze verify /etc/systemd/system/myapp.service
  2. 2Match what you see, then jump to its fix

    1. 1The [Service] section has no ExecStart= or ExecStop= line, or the key is misspelledThe service has no ExecStart= and no ExecStop=Fix
    2. 2systemd-analyze verify reports the ExecStart line, or ExecStart= starts with ./ or a bare relative pathExecStart= does not start with an absolute pathFix
    3. 3The unit has two or more ExecStart= lines and Type is simple, exec, forking or notifyMore than one ExecStart= in a service that is not Type=oneshotFix
    4. 4Type=oneshot together with Restart=always (or Restart=on-success)Restart=always or on-success on a Type=oneshot serviceFix

What does the error look like?

  • Loaded: bad-setting
  • bad-setting in the LOAD column of systemctl list-units
  • Unknown key name 'ExecStar' in section 'Service', ignoring.

Cause 1 of 4

The service has no ExecStart= and no ExecStop=

1Check

A service unit that defines neither ExecStart= nor ExecStop= is not valid. A typo in the key name (for example ExecStar=) leaves the section without a command, because unknown keys are only warned about and then skipped.

grep -n -E "^(ExecStart|ExecStop)" /etc/systemd/system/myapp.service
systemd-analyze verify /etc/systemd/system/myapp.service

2Fix

Add the command that runs your program. If the unit really only runs a stop command, it must also set RemainAfterExit=yes.

[Service]
ExecStart=/usr/bin/node /srv/myapp/server.js

3Verify

Reload the manager and read the Loaded line again.

sudo systemctl daemon-reload
systemctl status myapp.service

Confirmed by man7.org

Did this fix it?

Cause 2 of 4

ExecStart= does not start with an absolute path

1Check

The first word of an ExecStart= command must be an absolute path (or a plain program name that systemd can find in its fixed search path). A relative path such as ./run.sh or app/run.sh is not valid.

grep -n "^ExecStart" /etc/systemd/system/myapp.service
command -v node

2Fix

Replace the value with the full path to the executable. Use command -v to get it.

[Service]
ExecStart=/usr/bin/node /srv/myapp/server.js

3Verify

Verify the file and reload.

systemd-analyze verify /etc/systemd/system/myapp.service
sudo systemctl daemon-reload

Confirmed by man7.org

Did this fix it?

Cause 3 of 4

More than one ExecStart= in a service that is not Type=oneshot

1Check

Unless Type= is oneshot, exactly one command may be given in ExecStart=. Copy-pasted unit files often leave two lines in place.

grep -n -E "^(Type|ExecStart)" /etc/systemd/system/myapp.service

2Fix

Keep one ExecStart= line. Put the extra commands in ExecStartPre= or ExecStartPost=, or write a small wrapper script and start that.

[Service]
ExecStartPre=/usr/bin/mkdir -p /run/myapp
ExecStart=/usr/bin/node /srv/myapp/server.js

3Verify

Reload and start the unit.

sudo systemctl daemon-reload
sudo systemctl start myapp.service

Confirmed by man7.org

Did this fix it?

Cause 4 of 4

Restart=always or on-success on a Type=oneshot service

1Check

systemd rejects always and on-success for oneshot services, and a oneshot service is never restarted after a clean exit.

grep -n -E "^(Type|Restart)=" /etc/systemd/system/myapp.service

2Fix

Use Restart=on-failure for a oneshot job, or change Type= if the program is a long-running daemon. For something that must run again on a schedule, use a timer unit instead of Restart=.

[Service]
Type=oneshot
Restart=on-failure

3Verify

Reload and read the status.

sudo systemctl daemon-reload
systemctl status myapp.service

Confirmed by man7.org

Did this fix it?

How do I stop it coming back?

  • Run systemd-analyze verify on every unit file before you copy it into /etc/systemd/system.
  • Always use absolute paths in ExecStart=, and find them with command -v.
  • Run sudo systemctl daemon-reload after every edit of a unit file.
  • Start from a small unit with one ExecStart= and add settings one at a time.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

systemctl shows code=exited, status=217/USER

Main process exited, code=exited, status=217/USER

Exit status 217/USER means systemd could not find or switch to the account named in User= before starting the program.

2 causes, each with a fix

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.