You are not logged in.

#1 2021-11-06 09:55:41

mortenbo
Member
Registered: 2021-11-06
Posts: 2

[SOLVED] systemd --user, script not executed on boot

Hi
Systemd is a little confusing to me. I am trying to have a script executed during boot and so I have created this test script, "foo"

   #!/bin/sh
   touch foobar

in my home directory and made it executable. Then I have created the file .config/systemd/user/foo.service

  [Unit]
  Description=touch foobar

  [Service]                                                                                                                             
  Type=oneshot
  ExecStart=/home/mojo/foo                                                                                                           
  WorkingDirectory=/home/mojo/

  [Install]
  WantedBy=multi-user.target

and then

  $ systemctl --user enable foo

  $ systemctl --user list-unit-files --type service | grep foo
    foo.service                                                                   enabled   enabled

But the script is not executed on boot. What am I doing wrong?

Thanks,
Morten

Last edited by mortenbo (2021-11-06 11:10:18)

Offline

#2 2021-11-06 10:40:18

stanczew
Member
Registered: 2021-03-02
Posts: 114

Re: [SOLVED] systemd --user, script not executed on boot

You installed your service into multi-user.target, but there is no such target for user sessions.
Look in /usr/lib/systemd/user; you'll probably want to install the service into default.target.

Offline

#3 2021-11-06 10:42:20

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,300

Re: [SOLVED] systemd --user, script not executed on boot

Welcome to the boards, please wrap outputs and text files in code tags

--user services need to have WantedBy on default.target , see https://wiki.archlinux.org/title/System … user_units

Offline

#4 2021-11-06 11:08:51

ua4000
Member
Registered: 2015-10-14
Posts: 562

Re: [SOLVED] systemd --user, script not executed on boot

Also have a look at
"Automatic start-up of systemd user instances" https://wiki.archlinux.org/title/System … _instances

Offline

#5 2021-11-06 11:09:05

mortenbo
Member
Registered: 2021-11-06
Posts: 2

Re: [SOLVED] systemd --user, script not executed on boot

Bingo! Thanks to the both of you. I'll remember the code tags.

Offline

Board footer

Powered by FluxBB