Unrecognised Service for existing, working service - Ubuntu 18.04
Solution 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
As you have noted in your comment, when running per-user instances of systemd
the User
directive should be absent
Solution 2
Note:
In other instances that you get the same error:
The service
command puts the object first !
service foo start
The systemctl
command does the opposite:
systemctl start foo
Also, in service, you cannot add ".service", while you can if you use systemctl.
Related videos on Youtube
Clearsite - Remon Pel
42 year old veteran in web development, working for Clearsite Webdesigners in the Netherlands, with a newly discovered taste for 3D printing. Trying to expand my knowledge into server management.
Updated on September 18, 2022Comments
-
Clearsite - Remon Pel over 1 year
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 run: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
My question is: What am I doing wrong? How can I start this service on boot?
-
cEz almost 5 yearsHave you tried using the real command, systemctl enable my-service?
-
Clearsite - Remon Pel almost 5 yearsI think I must be dyslexic. I tried that command over an over again, because most articles refer to that. But reading my command history I used servicectl instead of systemctl. There's 3 days I'll never get back... THANKS.
-
cEz almost 5 yearsGreat, I've added an answer with some extra info
-
Clearsite - Remon Pel almost 5 yearsI noticed, thank you! Question answered and improved upon :)
-
-
Clearsite - Remon Pel almost 5 yearsWow. Thanks! Even better! But just a side note: when using the second option (avoiding sudo), the line "User=the-user" should be removed from the service file, to prevent "Failed to determine supplementary groups: Operation not permitted" error.