You are not logged in.

#1 2019-11-19 20:02:47

Archlinuxomane
Member
Registered: 2012-05-18
Posts: 19

[SOLVED] systemd --user service enabled but not autostarting

Hi there, I'm trying to get a program to run automatically on login using systemd --user

this is the service file:

$ cat ~/.config/systemd/user/foo.service 
[Unit]
Description=foo
Wants=network-online.target
After=network-online.target
 
[Service]
Type=simple 
ExecStart=foo
 
[Install]
WantedBy=multi-user.target

the service is enabled:

$ systemctl --user is-enabled foo
enabled

after logging in over ssh the service is neither already loaded nor in the course of starting up, and I don't get an error message:

$ systemctl --user status foo
foo.service - foo
   Loaded: loaded (/home/user/.config/systemd/user/foo.service; enabled; vendor preset: enabled)
   Active: inactive (dead)

manually running the service works:

$ systemctl --user start foo
$ systemctl --user status foo
foo.service - foo
   Loaded: loaded (/home/user/.config/systemd/user/foo.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-11-19 20:54:15; 1min 22s ago
 Main PID: 457 (java)
   CGroup: /user.slice/user-1000.slice/user@1000.service/foo.service
           └─457 foo

Eventually, I'll want the service to run upon boot and not just when the user is logged in, so I already enabled lingering (though I don't think this has anything to do with my current problem

loginctl enable-linger user

Last edited by Archlinuxomane (2019-11-20 06:41:05)

Offline

#2 2019-11-19 20:30:30

loqs
Member
Registered: 2014-03-06
Posts: 18,736

Re: [SOLVED] systemd --user service enabled but not autostarting

network-online.target is a system target I do not believe there is an equivalent user target.
As the target is never reached the Wants and After requirements are never true so the service does not start.

Offline

#3 2019-11-19 20:40:44

Archlinuxomane
Member
Registered: 2012-05-18
Posts: 19

Re: [SOLVED] systemd --user service enabled but not autostarting

Thanks for the info! I reused a service file I found on the net which was meant for "regular" (non-user) systemd and didn't realize that I didn't need the targets. Still, even when I remove the wants/after lines, the service doesn't start.

Last edited by Archlinuxomane (2019-11-19 20:43:02)

Offline

#4 2019-11-19 20:52:08

loqs
Member
Registered: 2014-03-06
Posts: 18,736

Re: [SOLVED] systemd --user service enabled but not autostarting

See `ls /usr/lib/systemd/user/*.target` what if you replace multi-user.target with default.target or basic.target?
You may have to clean up the symlinks.

Offline

#5 2019-11-19 21:09:40

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] systemd --user service enabled but not autostarting

Yeah, you need to have WantedBy=default.target and make sure the symlink exists in ~/.config/systemd/user/default.target/ after reinstalling the service.

Offline

#6 2019-11-20 06:40:32

Archlinuxomane
Member
Registered: 2012-05-18
Posts: 19

Re: [SOLVED] systemd --user service enabled but not autostarting

It works! There was no multi-user.target in /usr/lib/systemd/user/ so I switched to default.target, reenabled the service and now it's starting up on boot.
Thanks everyone!

Offline

Board footer

Powered by FluxBB