How do I setup a systemd service to be started by a non root user as a user daemon?

  • Hi,


    I'm using a OneDrive free client (https://github.com/skilion/onedrive) to synchronize some dir between my OMV storagePool and some users' OneDrive accounts.
    Let's say that I have 2 users for the example.
    The OneDrive client is configured and running for both in a user ssh session.


    I now want to run the client for both as a background service with systemd. Unfortunatly, my systemd knowlegde is relatively poor at the moment... :(


    I setup a service file for that.


    But when I try to enable the service, I have this error.


    Code
    root@home-server:/opt/onedrive# systemctl --user enable onedrive@.service
    Failed to connect to bus: No such file or directory


    Any help by a systemd king is welcome ;)


    Thanks

    Lian Li PC-V354 (with Be Quiet! Silent Wings 3 fans)
    ASRock Rack x470D4U | AMD Ryzen 5 3600 | Crucial 16GB DDR4 2666MHz ECC | Intel x550T2 10Gb NIC

    1 x ADATA 8200 Pro 256MB NVMe for System/Caches/Logs/Downloads
    5 x Western Digital 10To HDD in RAID 6 for Datas
    1 x Western Digital 2To HDD for Backups

    Powered by OMV v5.6.26 & Linux kernel 5.10.x

    • Offizieller Beitrag

    But when I try to enable the service, I have this error.

    You have specify a user:


    systemctl enable onedrive@sbocquet.service

    omv 7.0.4-2 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.10 | compose 7.1.2 | k8s 7.0-6 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Thanks a lot Aaron.

    Code
    root@home-server:/opt/onedrive# systemctl --user start onedrive@sbocquet.service
    Failed to connect to bus: Aucun fichier ou dossier de ce type

    Feel like a noob ;(

    I assume that it would be run with the user sbocquet at run start ?

    Lian Li PC-V354 (with Be Quiet! Silent Wings 3 fans)
    ASRock Rack x470D4U | AMD Ryzen 5 3600 | Crucial 16GB DDR4 2666MHz ECC | Intel x550T2 10Gb NIC

    1 x ADATA 8200 Pro 256MB NVMe for System/Caches/Logs/Downloads
    5 x Western Digital 10To HDD in RAID 6 for Datas
    1 x Western Digital 2To HDD for Backups

    Powered by OMV v5.6.26 & Linux kernel 5.10.x

    2 Mal editiert, zuletzt von sbocquet ()

    • Offizieller Beitrag

    I assume that it would be run with the user sbocquet at run start ?

    It should. That is how the syncthing plugin works.

    omv 7.0.4-2 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.10 | compose 7.1.2 | k8s 7.0-6 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • OK, so I start the service with:


    systemctl start onedrive@sbocquet.service


    check it with:


    systemctl list-units


    onedrive@sbocquet.service loaded activating auto-restart OneDrive Free Client
    onedrive@vbocquet.service loaded activating auto-restart OneDrive Free Client


    It seems that it is not active, still trying to activate...


    Any idea ?

    Lian Li PC-V354 (with Be Quiet! Silent Wings 3 fans)
    ASRock Rack x470D4U | AMD Ryzen 5 3600 | Crucial 16GB DDR4 2666MHz ECC | Intel x550T2 10Gb NIC

    1 x ADATA 8200 Pro 256MB NVMe for System/Caches/Logs/Downloads
    5 x Western Digital 10To HDD in RAID 6 for Datas
    1 x Western Digital 2To HDD for Backups

    Powered by OMV v5.6.26 & Linux kernel 5.10.x

    • Offizieller Beitrag

    Hard to say. What user are you executing the systemctl start command with?

    omv 7.0.4-2 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.10 | compose 7.1.2 | k8s 7.0-6 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • I was connected as root...


    I'm searching some log in the journal too

    Lian Li PC-V354 (with Be Quiet! Silent Wings 3 fans)
    ASRock Rack x470D4U | AMD Ryzen 5 3600 | Crucial 16GB DDR4 2666MHz ECC | Intel x550T2 10Gb NIC

    1 x ADATA 8200 Pro 256MB NVMe for System/Caches/Logs/Downloads
    5 x Western Digital 10To HDD in RAID 6 for Datas
    1 x Western Digital 2To HDD for Backups

    Powered by OMV v5.6.26 & Linux kernel 5.10.x

    • Offizieller Beitrag

    I was connected as root...

    That should be ok. Seems like something with the onedrive client and/or the config file in the user's home directory.

    omv 7.0.4-2 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.10 | compose 7.1.2 | k8s 7.0-6 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • That's what I was thinking about... and I tried to run the client with my user to be sure.
    I works fine..

    Code
    sbocquet@home-server:/StoragePool/Documents$ onedrive --monitor --confdir=/home/sbocquet/.config/onedrive
    Deleting Documents/test4.txt
    Deleting Documents/test5.txt
    Deleting Documents/test2.txt
    Deleting Documents/test3.txt
    Deleting Documents/test1.txt

    So it can't be access right or Something like this...


    Unfortunatly when I run it from the service with root, I have no log in journalctl :(


    Code
    root@home-server:/StoragePool/Documents# journalctl --user-unit onedrive.service -f


    I'm a little lost at the moment...

    Lian Li PC-V354 (with Be Quiet! Silent Wings 3 fans)
    ASRock Rack x470D4U | AMD Ryzen 5 3600 | Crucial 16GB DDR4 2666MHz ECC | Intel x550T2 10Gb NIC

    1 x ADATA 8200 Pro 256MB NVMe for System/Caches/Logs/Downloads
    5 x Western Digital 10To HDD in RAID 6 for Datas
    1 x Western Digital 2To HDD for Backups

    Powered by OMV v5.6.26 & Linux kernel 5.10.x

    • Offizieller Beitrag

    I'm wondering if you removed the restart and confdir (it might default to that location?) lines from the unit file, if it would work?

    omv 7.0.4-2 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.10 | compose 7.1.2 | k8s 7.0-6 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Tried without the confdir option and it's the same, so put it back to be sure...


    root@home-server:/opt/onedrive# service onedrive@sbocquet start
    root@home-server:/opt/onedrive# service onedrive@sbocquet status
    ● onedrive@sbocquet.service - OneDrive Free Client
    Loaded: loaded (/lib/systemd/system/onedrive@.service; enabled; vendor preset: enabled)
    Active: activating (auto-restart) (Result: exit-code) since Mon 2018-04-09 16:41:03 CEST; 2s ago
    Docs: https://github.com/skilion/onedrive
    Process: 5043 ExecStart=/usr/local/bin/onedrive --monitor --confdir=//.config/onedrive/ (code=exited, status=1/FAILURE)
    Main PID: 5043 (code=exited, status=1/FAILURE)
    avril 09 16:41:03 home-server systemd[1]: onedrive@sbocquet.service: Main process exited, code=exited, status=1/FAILURE
    avril 09 16:41:03 home-server systemd[1]: onedrive@sbocquet.service: Unit entered failed state.
    avril 09 16:41:03 home-server systemd[1]: onedrive@sbocquet.service: Failed with result 'exit-code'.


    And the log...


    avril 09 16:42:52 home-server systemd[1]: Started OneDrive Free Client.
    avril 09 16:42:52 home-server onedrive[5189]: std.file.FileException@std/file.d(2506): //.config: Permission denied
    avril 09 16:42:52 home-server onedrive[5189]: ----------------
    avril 09 16:42:52 home-server onedrive[5189]: ??:? @safe bool std.file.cenforce!(bool).cenforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x2f8f08db]
    avril 09 16:42:52 home-server onedrive[5189]: ??:? @safe bool std.file.ensureDirExists!().ensureDirExists(const(char[])) [0x2f93b9cd]
    avril 09 16:42:52 home-server onedrive[5189]: ??:? @safe void std.file.mkdirRecurse(const(char[])) [0x2f93a384]
    avril 09 16:42:52 home-server onedrive[5189]: ??:? @safe void std.file.mkdirRecurse(const(char[])) [0x2f93a357]
    avril 09 16:42:52 home-server onedrive[5189]: ??:? _Dmain [0x2f8f6e57]
    avril 09 16:42:52 home-server systemd[1]: onedrive@sbocquet.service: Main process exited, code=exited, status=1/FAILURE
    avril 09 16:42:52 home-server systemd[1]: onedrive@sbocquet.service: Unit entered failed state.
    avril 09 16:42:52 home-server systemd[1]: onedrive@sbocquet.service: Failed with result 'exit-code'.


    Seems like a right problem with the .confdir but for me it's alright...


    root@home-server:/opt/onedrive# ls -al /home/sbocquet/
    total 28
    drwxr-xr-x 3 sbocquet users 4096 avril 7 15:57 .
    drwxr-xr-x 4 root root 4096 mars 31 21:09 ..
    -rw------- 1 sbocquet users 1241 avril 9 16:38 .bash_history
    -rw-r--r-- 1 sbocquet users 220 mars 31 21:09 .bash_logout
    -rw-r--r-- 1 sbocquet users 3526 mars 31 21:09 .bashrc
    drwxr-xr-x 3 sbocquet users 4096 avril 7 15:57 .config
    -rw-r--r-- 1 sbocquet users 675 mars 31 21:09 .profile


    EDIT: same with chmod 777 on /home/sbocquet/.config ;(


    EDIT 2 : OK, got it work ! I wasn't editing the right onedrive@.service file (/lib/systemd/system/onedrive@.service)
    and the %h var isn't working, I have to replace it by



    Code
    ExecStart=/usr/local/bin/OneDrive --monitor --confdir=/%h/.config/OneDrive/
    
    
    ExecStart=/usr/local/bin/OneDrive --monitor --confdir=/home/%i/.config/OneDrive/

    Lian Li PC-V354 (with Be Quiet! Silent Wings 3 fans)
    ASRock Rack x470D4U | AMD Ryzen 5 3600 | Crucial 16GB DDR4 2666MHz ECC | Intel x550T2 10Gb NIC

    1 x ADATA 8200 Pro 256MB NVMe for System/Caches/Logs/Downloads
    5 x Western Digital 10To HDD in RAID 6 for Datas
    1 x Western Digital 2To HDD for Backups

    Powered by OMV v5.6.26 & Linux kernel 5.10.x

    2 Mal editiert, zuletzt von sbocquet ()

    • Offizieller Beitrag

    OK, got it work ! I wasn't editing the right onedrive@.service file (/lib/systemd/system/onedrive@.service)
    and the %h var isn't working, I have to replace it by

    You shouldn't edit that file unless you are creating it. If the package creates it, it will be overwritten on updates. You can override it in /etc/systemd/system/. You can also override individual items in /etc/systemd/system/servicename.service.d/.


    I wonder why %h isn't working. From the docs I read, it looks like it should. But, glad it is working.

    omv 7.0.4-2 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.10 | compose 7.1.2 | k8s 7.0-6 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • As you said, I was creating it, because the app is not creating it at all.


    Don't know why %h does not work, I will have more tests tomorrow... because the service runs for my users and root! And I don't want it to run for root...

    Lian Li PC-V354 (with Be Quiet! Silent Wings 3 fans)
    ASRock Rack x470D4U | AMD Ryzen 5 3600 | Crucial 16GB DDR4 2666MHz ECC | Intel x550T2 10Gb NIC

    1 x ADATA 8200 Pro 256MB NVMe for System/Caches/Logs/Downloads
    5 x Western Digital 10To HDD in RAID 6 for Datas
    1 x Western Digital 2To HDD for Backups

    Powered by OMV v5.6.26 & Linux kernel 5.10.x

    Einmal editiert, zuletzt von sbocquet ()

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!