Unrecognised Service for existing, working service - Ubuntu 18.04

by Clearsite - Remon Pel   Last Updated June 12, 2019 07:02 AM

I'm trying to load a script on boot in Ubuntu Server 18.04. My .service script is installed in /etc/systemd/system, and I can service my-service start and service my-service stop but when I try to run at boot (which according to the web I should do) with service my-service enable the system responds with my-service: unrecognised service

Searching the web only tells me how to do it in older versions of Ubuntu which do not apply to 18.04 and I am unable to determine the correct terminology to find the answer.

the script:

# filename: /etc/systemd/system/my-service.service
[Unit]
Description=My Service
After=network.target
After=mysqld.service

[Service]
User=the-user
WorkingDirectory=/home/the-user/path-to-script
ExecStart=/home/the-user/path-to-script/start.sh
SuccessExitStatus=0
TimeoutStopSec=10
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

The question (obviously) is: What am I doing wrong? How can I start this service on boot?

Thanks in advance

Remon



Answers 1


Use the real command, which for systemd would be:

sudo systemctl enable my-service

For reference, you do not have to use the main system directory for the unit file if you want it to run for a normal user, e.g. your own. You can create it in a directory such as:

~/.config/systemd/user/

Then you can do:

systemctl --user enable my-service

This avoids the need for sudo

Cez
Cez
June 12, 2019 06:41 AM

Related Questions


Updated April 20, 2015 06:01 AM

Updated December 16, 2016 09:00 AM

Updated October 05, 2015 10:01 AM

Updated February 12, 2018 08:02 AM

Updated April 23, 2015 22:00 PM