You are not logged in.

#1 2020-04-22 20:44:50

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Error loading a systemd service (Rclone to mount OneDrive)

I installed rclone and managed to mount my OneDrive (personal account) to a local folder.

I did this with the line (in terminal):

rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive

(onedrive being the name of my rclone "profile", and OneDrive is the type supported by rclone)

Good thing is that it worked! BUT unfortunately it does not work after a reboot of the system.

So I decided I want to mount it via systemd. I made the following mount-onedrive.service in directory: /etc/systemd/system/

# mount-onedrive.service
[Unit]
Description=OneDrive Mount on Startup
#Requires=network.target
#After=network.target

[Service]
ExecStart=/usr/local/sbin/mount-onedrive.sh

[Install]
WantedBy=multi-user.target

... which calls an executable mount-onedrive.sh located in /usr/local/sbin/

# mount-onedrive.sh
rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive

Doesn't work. sad Meaning there are no files present in my local folder. (this is my test method).

Tried enabling the service manually via

sudo systemctl enable mount-onedrive

Upon checking the status of the service I see:

● mount-onedrive.service - OneDrive Mount on Startup
     Loaded: loaded (/etc/systemd/system/mount-onedrive.service; enabled; vendor preset: disabled)
     Active: inactive (dead)

Any ideas on a next step to resolve this, any tips will help. Thanks in advance!

[EDIT
Rebooted again, and checked systemctl status of mount-onedrive.service, got this:

● mount-onedrive.service - OneDrive Mount on Startup
     Loaded: loaded (/etc/systemd/system/mount-onedrive.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Wed 2020-04-22 16:49:36 EDT; 51s ago
    Process: 741 ExecStart=/usr/local/sbin/mount-onedrive.sh (code=exited, status=203/EXEC)
   Main PID: 741 (code=exited, status=203/EXEC)

Apr 22 16:49:36 mycomputer systemd[1]: Started OneDrive Mount on Startup.
Apr 22 16:49:36 mycomputer systemd[741]: mount-onedrive.service: Failed to execute command: Exec format error
Apr 22 16:49:36 mycomputer systemd[741]: mount-onedrive.service: Failed at step EXEC spawning /usr/local/sbin/mount-onedrive.sh: Exec format error
Apr 22 16:49:36 mycomputer systemd[1]: mount-onedrive.service: Main process exited, code=exited, status=203/EXEC
Apr 22 16:49:36 mycomputer systemd[1]: mount-onedrive.service: Failed with result 'exit-code'.

Last edited by MikeTeavee (2020-04-22 20:53:33)

Offline

#2 2020-04-22 20:53:19

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Error loading a systemd service (Rclone to mount OneDrive)

MikeTeavee wrote:
# mount-onedrive.sh
rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive

As it stands your service file runs this script as the root user, do you have a /root/OneDrive directory?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2020-04-22 21:01:28

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Re: Error loading a systemd service (Rclone to mount OneDrive)

(BTW Let me know if I did this right...)

I typed

sudo ls -a /root

I see:
.  ..  .bash_history  .cache  .config  .gnupg  .local  .viminfo

Looks like it's not there.

Last edited by MikeTeavee (2020-04-22 21:01:58)

Offline

#4 2020-04-22 21:08:14

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

What are the permissions on /usr/local/sbin/mount-onedrive.sh

You also need to run the service as the same user,  as the one that executed:

rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive

Edit:
If you execute as that same user

/usr/local/sbin/mount-onedrive.sh

Does that work without error?
Edit2:
Would also suggest changing your approach to not use a script file run by a shell.  Have systemd directly execute the command after substituting the full path.
See systemd.unit section SPECIFIERS particularly %h.

Last edited by loqs (2020-04-22 21:43:36)

Offline

#5 2020-04-22 22:56:09

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Re: Error loading a systemd service (Rclone to mount OneDrive)

loqs wrote:

What are the permissions on /usr/local/sbin/mount-onedrive.sh

Owner is root. Root has read and write.
Groups/Users/Others have read-only permission.

loqs wrote:

Edit:
If you execute as that same user

/usr/local/sbin/mount-onedrive.sh

Does that work without error?

I switched to root and tried to execute mount-onedrive.sh and it looks like root's rclone.conf file doesn't include the created "profile" for "onedrive". In other words, I setup rclone under my user login.

Maybe there's a quick way to fix this?

Otherwise I can take a shot at having systemd directly execute the command. (But perhaps creating my own systemd service is a good learning experience? big_smile )

Last edited by MikeTeavee (2020-04-22 23:04:23)

Offline

#6 2020-04-22 23:14:55

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

What is the output of the following executed as the same user (not root)

stat /usr/local/sbin/mount-onedrive.sh
/usr/local/sbin/mount-onedrive.sh

Edit:
See the tip box from pastebin if you need to post the output from the console.
Systemd/User#Writing_user_units covers writing user units including an example referencing a file in a users home directory.
Edit2:

# nano /etc/systemd/system/mount-onedrive.service
# cat /etc/systemd/system/mount-onedrive.service
[Unit]
Description=OneDrive Mount on Startup
#Requires=network.target
#After=network.target

[Service]
ExecStart=/usr/local/sbin/mount-onedrive.sh

[Install]
WantedBy=multi-user.target
# nano /usr/local/sbin/mount-onedrive.sh
# cat /usr/local/sbin/mount-onedrive.sh
rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive
# chmod 644 /usr/local/sbin/mount-onedrive.sh
# systemctl start mount-onedrive.service
# systemctl -o cat status mount-onedrive.service
....
Started OneDrive Mount on Startup.
mount-onedrive.service: Failed to execute command: Permission denied
mount-onedrive.service: Failed at step EXEC spawning /usr/local/sbin/mount-onedrive.sh: Permission denied
mount-onedrive.service: Main process exited, code=exited, status=203/EXEC
mount-onedrive.service: Failed with result 'exit-code'.

Error does not match with read write user read only group plus other

# chmod 744 /usr/local/sbin/mount-onedrive.sh
# systemctl -o cat status mount-onedrive.service
....
Started OneDrive Mount on Startup.
mount-onedrive.service: Exec format error
mount-onedrive.service: Failed at step EXEC spawning /usr/local/sbin/mount-onedrive.sh: Exec format error
mount-onedrive.service: Main process exited, code=exited, status=203/EXEC
mount-onedrive.service: Failed with result 'exit-code'.

Error now matches.  Add #! to specify it is a shell script.

# nano /usr/local/sbin/mount-onedrive.sh
# cat /usr/local/sbin/mount-onedrive.sh
#!sh
rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive
# systemctl -o cat status mount-onedrive.service
....
Started OneDrive Mount on Startup.
mount-onedrive.service: Failed to execute command: No such file or directory
mount-onedrive.service: Failed at step EXEC spawning /usr/local/sbin/mount-onedrive.sh: No such file or directory
mount-onedrive.service: Main process exited, code=exited, status=203/EXEC
mount-onedrive.service: Failed with result 'exit-code'.

Fails now as rclone is not installed on this system.

Last edited by loqs (2020-04-22 23:51:21)

Offline

#7 2020-04-23 00:12:16

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Re: Error loading a systemd service (Rclone to mount OneDrive)

loqs wrote:

What is the output of the following executed as the same user (not root)

stat /usr/local/sbin/mount-onedrive.sh
/usr/local/sbin/mount-onedrive.sh

Output of stat as user:

stat /usr/local/sbin/mount-onedrive.sh
  File: /usr/local/sbin/mount-onedrive.sh
  Size: 82              Blocks: 8          IO Block: 4096   regular file
Device: 10303h/66307d   Inode: 3678997     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-04-22 15:25:53.605224196 -0400
Modify: 2020-04-22 15:24:05.688555452 -0400
Change: 2020-04-22 15:24:05.705222118 -0400
Birth: 2020-04-22 15:24:05.688555452 -0400

Executing mount-onedrive.sh from terminal (as non-root user) makes the system hang and files are not appearing in the local directory. Weird, I feel like that should have worked.

EDIT:

Something went screwy. I could tell since my ~/OneDrive folder disappeared!

I rebooted Arch, and the OneDrive folder as present again in my home directory.  ...Tried, once again, manually executing mount-onedrive.sh, and it does indeed work. Files popped right up in the folder.

EDIT:

Added the mount-onedrive.sh to KDE Autostart, but nothing happened.

As for directly calling the rclone command from systemd, I had no idea what to do. But wouldn't that be pointless since rclone can't be called by root anyway?

This has been a pain in the butt, I'll honestly take any solution at this point. sad

Last edited by MikeTeavee (2020-04-23 03:49:21)

Offline

#8 2020-04-23 09:00:41

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

See Systemd/User#Writing_user_units so the command executes as your user.
You need to replace use of ~ with %h in the command string.

Offline

#9 2020-04-23 12:21:36

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Re: Error loading a systemd service (Rclone to mount OneDrive)

Yeah, read that part of the archwiki, and also the sub-section on systemd.unit.

Here's the latest version of my service file.

[Unit]
Description=Rclone OneDrive Mount

[Service]
Type=simple
User=mike
Group=wheel
ExecStart=%h/usr/local/sbin/mount-onedrive.sh --config %h/home/mike/.config/rclone/rclone.conf 
#TimeoutStartSec=0
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

On manual systemctl enable, I still get the lines in output:

mount-onedrive.service: Failed to execute command: Exec format error
mount-onedrive.service: Failed at step EXEC spawning /usr/local/sbin/mount-onedrive.sh: Exec format error

Offline

#10 2020-04-23 13:27:00

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

User=mike
Group=wheel
ExecStart=%h/usr/local/sbin/mount-onedrive.sh --config %h/home/mike/.config/rclone/rclone.conf 
man 5 systemd.unit wrote:

"%h" User home directory This is the homedirectory of the user running the service manager instance. In case of the system manager this resolves to "/root". Note that this setting is not influenced by the User= setting configurable in the [Service] section of the service unit.

If the service is being run a system service the ExecStart line would expand to

/root/usr/local/sbin/mount-onedrive.sh --config /root/home/mike/.config/rclone/rclone.conf

If the service is being run a user service and user mike has home directory /home/mike the ExecStart line would expand to

/home/mike/usr/local/sbin/mount-onedrive.sh --config /home/mike/home/mike/.config/rclone/rclone.conf
MikeTeavee wrote:

On manual systemctl enable, I still get the lines in output:

mount-onedrive.service: Failed to execute command: Exec format error
mount-onedrive.service: Failed at step EXEC spawning /usr/local/sbin/mount-onedrive.sh: Exec format error

See my second edit to post #6.  Although you do not need the shell script.  As the error message indicates systemd was finding the shell script you may have forgotten `systemctl daemon-reload` after altering the service file.
Is the current service still a system service or have you changed it to a user service?

Last edited by loqs (2020-04-23 13:44:02)

Offline

#11 2020-04-23 14:18:09

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Re: Error loading a systemd service (Rclone to mount OneDrive)

loqs wrote:

See my second edit to post #6.  Although you do not need the shell script.  As the error message indicates systemd was finding the shell script you may have forgotten `systemctl daemon-reload` after altering the service file.

After I edit the serivce file, I perform:

sudo systemctl disable mount-onedrive
sudo systemctl enable mount-onedrive
loqs wrote:

Is the current service still a system service or have you changed it to a user service?

I'm not sure, the service exists as mount-onedrive.service in the /etc/systemd/system/ (navigating the filesystem as user). So my guess is that it's being run from root?
Just to get this straight, does the location define whether the serivce file is being run as root or user? Really confused, but I'm a n00b.

EDIT:

I went back and read the archwiki....

So should I move the .service file to /etc/systemd/user/ then?

Last edited by MikeTeavee (2020-04-23 14:22:21)

Offline

#12 2020-04-23 14:31:59

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

Or ~/.config/systemd/user/mount-onedrive.service
Try

[Unit]
Description=OneDrive Mount on Startup

[Service]
ExecStart=rclone --vfs-cache-mode writes mount onedrive: %h/OneDrive

[Install]
WantedBy=default.target

Offline

#13 2020-04-23 15:06:17

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Re: Error loading a systemd service (Rclone to mount OneDrive)

Not sure if this is worth mentioning, but I don't have systemd folder inside my .config directory.

Offline

#14 2020-04-23 15:11:35

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

You can create it.

Offline

#15 2020-04-23 15:20:47

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Re: Error loading a systemd service (Rclone to mount OneDrive)

Update:

I moved mount-onedrive.service to /etc/systemd/user/

Manually enabled by typing

systemctl --user enable mount-onedrive

Terminal says:

 Created symlink /home/mike/.config/systemd/user/default.target.wants/mount-onedrive.service -> /etc/xdg/systemd/user/mount-onedrive.service.

Tried checking status of the service. I get...

● mount-onedrive.service - Rclone OneDrive Mount
     Loaded: loaded (/etc/xdg/systemd/user/mount-onedrive.service; enabled; vendor preset: enabled)
     Active: inactive (dead)

... still not working, also tried a reboot, and still not working.

EDIT:

(BTW, service file is identical to the loq's post #12, see above.)

Last edited by MikeTeavee (2020-04-23 15:23:46)

Offline

#16 2020-04-23 15:24:10

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

enabling will not activate a service, you'll need to start it. and the status should at least be different after the reboot if it has actually executed.

Offline

#17 2020-04-23 15:32:08

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

What is the output of

journalctl -b --user

See the tip box from pastebin if the output will not fit in code tags.

Offline

#18 2020-04-23 16:10:47

MikeTeavee
Member
Registered: 2020-03-29
Posts: 17

Re: Error loading a systemd service (Rclone to mount OneDrive)

V1del wrote:

enabling will not activate a service, you'll need to start it. and the status should at least be different after the reboot if it has actually executed.

Interesting... So how come when I installed Arch, and I had to install dhcpcd (for example), I only needed to use systemctl 'enable' and not 'start' to get the service running?

Anyway, I'm getting closer to getting this working. Typing the following:

systemctl --user start mount-onedrive
systemctl --user enable mount-onedrive

Manual start&enable works now! smile As files are present in the OneDrive folder.

HOWEVER on reboot, rclone is not automatically mounting.

Checking status of the service after reboot gives me:

Failed to create file system for "onedrive:": failed to get root: Get "https://grapth/microsoft.com/v1.0/drives/<some number here>/root": dial tcp: lookup graph.microsoft.com: Temporary failure in name resolution.

So I took a guess that network wasn't working yet perhaps...? ...and added the following two lines to the service file under [Unit]:

Wants=network-online.target
After=network-online.target

...But still not working after reboot. Any idea on a next step?

Last edited by MikeTeavee (2020-04-23 16:22:07)

Offline

#19 2020-04-23 17:34:11

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

Re: Error loading a systemd service (Rclone to mount OneDrive)

user units can not depend on system units which is an issue as network-online.target is a system unit.
The system unit that starts all user sessions is systemd-user-sessions.service.  You can try adding the dependencies to that unit with:

# systemctl edit systemd-user-sessions.service

Offline

#20 2020-09-03 13:19:32

jal
Member
Registered: 2015-04-23
Posts: 37

Re: Error loading a systemd service (Rclone to mount OneDrive)

Hopefully this post is tepid enough not to be necro, I'm in a similar boat to Señor TV.

cat ~/.config/systemd/user/mount-onedrive.service

[Unit]
Description=OneDrive Mount on Startup

[Service]
User=me
Group=me
ExecStart=rclone --vfs-cache-mode writes mount onedrive: %h/OneDrive

[Install]
WantedBy=default.target

(as me, not root)
systemctl --user start mount-onedrive
systemctl --user status mount-onedrive

● mount-onedrive.service - OneDrive Mount on Startup
     Loaded: loaded (/home/me/.config/systemd/user/mount-onedrive.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2020-09-03 14:07:39 BST; 7min ago
    Process: 13426 ExecStart=/usr/bin/rclone --vfs-cache-mode writes mount onedrive: /home/me/OneDrive (code=exited, status=216/GROUP)
   Main PID: 13426 (code=exited, status=216/GROUP)

Sep 03 14:07:39 laptop systemd[2535]: Started OneDrive Mount on Startup.
Sep 03 14:07:39 laptop systemd[13426]: mount-onedrive.service: Failed to determine supplementary groups: Operation not permitted
Sep 03 14:07:39 laptop systemd[13426]: mount-onedrive.service: Failed at step GROUP spawning /usr/bin/rclone: Operation not permitted
Sep 03 14:07:39 laptop systemd[2535]: mount-onedrive.service: Main process exited, code=exited, status=216/GROUP
Sep 03 14:07:39 laptop systemd[2535]: mount-onedrive.service: Failed with result 'exit-code'.

Any assistance appreciated.

Offline

#21 2020-09-03 13:28:23

jal
Member
Registered: 2015-04-23
Posts: 37

Re: Error loading a systemd service (Rclone to mount OneDrive)

Ok, fixed it. I just removed the User and Group lines from the service file.
https://stackoverflow.com/questions/480 … p-spawning

Offline

Board footer

Powered by FluxBB