Ubuntu – Start systemctl service on user login

systemdUbuntu

I'm trying to create a service that runs at user login.

As a non-root user, I've created a file:

> cat ~/.local/share/systemd/user/voodoo.service

[Unit]
Description=User service test

[Service]
RemainAfterExit=yes
Type=simple
ExecStart=/bin/bash -c "touch /tmp/ok123"

[Install]
WantedBy=default.target

But, systemctl does not recognize it,

> systemctl --user restart voodoo.service
Failed to connect to bus: No such file or directory

Any ideas?

Best Answer

I think you have to enable the service first:

systemctl --user enable voodoo.service
Created symlink /home/andreatsh/.config/systemd/user/default.target.wants/voodoo.service → /home/andreatsh/.local/share/systemd/user/voodoo.service

As you can see, this simply create a symlink in the appropriate folder. Then I run:

systemctl --user restart voodoo.service 

and the service worked fine.