Search code examples
linuxserviceserverdaemonsystemd

Failed to start ~~~.service in linux18.04, systemd service Program


I'm setting up a new service program. I use systemctl. but when I authorized, enabled, started the service but it didn't work with error 'Failed to start ~~~.service.

I commanded this commands.

sudo systemctl daemon-reload
sudo systemctl start serverProgram.service
sudo systemctl enable serverProgram.service
sudo systemctl status serverProgram.service

and error code is like this.

serverProgram.service : Service hold-off time over, scheduling restart.
serverProgram.service : Scheduled restart job, restart counter is a 5. Stopped serverProgram.service.
serverProgram.service : Start request repeated too quickly.
serverProgram.service : Failed with result 'exit-code'.
Failed to start serverProgram.service.

I wrote serverProgram.service with nano. and the code is like this.

# serverProgram file

[Service]
WorkingDirectory=/home/Desktop/LSH/Study/C++/DaemonProgram
ExecStart=/home/Desktop/LSH/Study/C++/DaemonProgram/main
Restart=always

[Install]
WantedBy=multi-user.target

I want to activate main program automatically in reboot


Solution

  • It looks like the program you're trying to run is failing as soon as you try to run it. systemd is trying to restart it (because you have Restart=always), but it gives up if it detects a lot of restarts in a very short period.

    If your program is OK when you run it manually, remember that systemd will be trying to run it in a different role than you would normally (different user, different environment settings etc.)

    You should be able to see the output of your program using journalctl - this answer has a quick example on how to use it.