Skip to content

NEWBIE CORNER: Can't start systemd service

I have a custom-made service that I want to run.

I've linked the service to /etc/systemd:

sudo ln -s $HOME/foo.service /etc/systemd/system/

But then I get:

[me@here ~]$ systemctl start foo
Failed to start foo.service: Unit foo.service not found.

SOLUTION:

The problem was that I had a typo in my service file's link (the ln command). (The path was convoluted enough for me not to notice despite staring at it a dozen times.) ¦ p I feel so dumb.

Thank you all!

Edited 18 Jul 2020. We only hold this version.

7 points11 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
7 · 74% up
Kind
Text
ID
htbda6

Author

2
posts
6
comments
0
media
View profile

11 comments

A unit file is a plain text ini-style file [1]

and not a symlink. It may be aliased by symlinking, but it is still have to lead

to the existing name in one of the unit search paths [1]

and $HOME/foo.service is not one of those paths.

[1] https://www.freedesktop.org/software/systemd/man/systemd.unit.html

12 points

I think this is incorrect.

With

sudo ln -s $HOME/foo.service /etc/systemd/system/

there is a link in /etc/systemd/system, which is in the System Unit Search Path.

The file linked to, $HOME/foo.service, does not need to be in the search paths (neither the System Unit one above or the User Unit one, /etc/systemd/user).

For example, my service now runs (I had a link typo), and it's linked in /etc/systemd/user from /home/0x340fa899/Dropbox/utility/backups/systems/evanauth/systemd/, not in the paths:

[▓▓▓▓▓▓▓ 14:40:21 ~]$ ls -al /etc/systemd/user
total 24
drwxr-xr-x 4 root root 4096 Jul 18 13:18 .
drwxr-xr-x 5 root root 4096 Jul 13 19:39 ..
drwxr-xr-x 2 root root 4096 Jul 13 23:05 default.target.wants
lrwxrwxrwx 1 root root   89 Jul 18 13:18 0x340fa899-nightly.service -> /home/0x340fa899/Dropbox/utility/backups/systems/evanauth/systemd/0x340fa899-nightly/0x340fa899-nightly.service
lrwxrwxrwx 1 root root   87 Jul 18 13:18 0x340fa899-nightly.timer -> /home/0x340fa899/Dropbox/utility/backups/systems/evanauth/systemd/0x340fa899-nightly/0x340fa899-nightly.timer
drwxr-xr-x 2 root root 4096 Jul 13 23:05 sockets.target.wants

Note that upon enabling the service, it was similarly linked in ~/.config/systemd/user/:

[▓▓▓▓▓▓▓ 14:41:23 ~]$ ls -al ~/.config/systemd/user/
total 16
drwxr-xr-x 3 0x340fa899 0x340fa899 4096 Jul 18 13:20 .
drwxr-xr-x 3 0x340fa899 0x340fa899 4096 Jul 18 13:20 ..
lrwxrwxrwx 1 0x340fa899 0x340fa899   87 Jul 18 13:20 0x340fa899-nightly.timer -> /home/0x340fa899/Dropbox/utility/backups/systems/evanauth/systemd/0x340fa899-nightly/0x340fa899-nightly.timer
drwxr-xr-x 2 0x340fa899 0x340fa899 4096 Jul 18 13:20 timers.target.wants
2 points

Might have different behavior for user services, it is just what man reads for system ones. Otherwise, thanks for your research!

1 points

This should help you, if it doesn't work after that, feel free to message me

5 points

For third-party reference, I've followed these instructions already (this service works on another distro).

feel free to message me

Assuming "message" means "DM", I will DM you.

4 points

sudo systemctl daemon-reload?
You are trying starting as a normal user, in that case I recommend using user systemd. Put your unit file in ~/.config/systemd/user and append --user in systemctl command.

3 points

sudo systemctl daemon-reload

This was not the problem.

You are trying starting as a normal user, in that case I recommend using user systemd. Put your unit file in ~/.config/systemd/user and append --user in systemctl command.

Thank you!

I actually did the latter upon learning it's the more correct way to run user-specific daemons, but the problem was a path typo in my link.

After linking service files correctly in /etc/systemd/system, systemctl commands work and find the service.

After linking service files correctly in /etc/systemd/user, systemctl --user commands work and find the service.

Is it better to use ~/.config/systemd/user instead of /etc/systemd/user? : o

1 points

What you put in /etc/systemd/user can be used by all users in systemctl --user, while ones in ~/.config is only by the user. I like the latter because I don't need root access at all. I think the former is meant more for admins or packagers.

2 points

Could it be that you just need to systemd enable foo before systemd start foo ?

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.