[rclone] Init.d script - why does this fail?

Why does this script fail when I hit start from LuCi, but runs fine using /etc/init.d/mount-onedrive start?

root@OpenWrt:~# cat /etc/init.d/mount-onedrive
#!/bin/sh /etc/rc.common
# Copyright (C) 2007 OpenWrt.org

START=97
STOP=5

start() {
        /usr/bin/rclone --config /etc/rclone/rclone.conf mkdir /tmp/OneDrive --daemon > /dev/null 2>&1
        /usr/bin/rclone --config /etc/rclone/rclone.conf mount "OneDrive:/Scanned Documents/" /tmp/OneDrive/ --vfs-cache-mode full --umask 000 --allow-other > /dev/null 2>&1
}

stop() {
        fusermount -zu /tmp/OneDrive > /dev/null 2>&1
}
1 Like

Shot in the dark: fusermount is missing a full path.

Thanks for the suggestion but it's the start portion that is failing. When I tried writing output to file I saw nothing.

so what happens if you execute it manually, in foreground ?

It works perfectly.

Also I don't understand why:

/etc/init.d/mount-onedrive start

works, but router executing script on reboot or from LuCi (clicking start) fails.

Is it something to do with environment variables? The OpenWrt wiki on init.d scripts reveals nothing that I can see on this.

I assume this is executed during start up ?

try putting in the local start up script, with a preceding sleep 20, there might be a race condition making it fail.

Surely race wouldn't affect me manually clicking start on this particular service? I am keen to control when this executes though, and specifically before samba. Could this be to do with environment variable? How would I set that up properly?

Redirect the output to a log file and analyze the log when it fails.

1 Like

Probably not, hence the question whether it was started during boot or not,
but I now see you've stated you're executing it from LuCI.

if you need it to start before samba, do a /etc/init.d/samba restart within your own script.
/etc/init.d/samba start, if you disable samba's autostart.

have you verified there's no softlink to /etc/init.d/mount-onedrive in /etc/rc.d ?

for the fun of it, add an echo "start onedrive" > /tmp/onedrive to your start(), to verify the subroutine's actually executed, check if it exists after you've attempted to start it.

1 Like

Hi,

You actually can control order via the START/STOP variables you set at the beginning of your script. Once you do service <servicename> enable it will create a symlink under /etc/rc.d/S<your START value><servicename> and similar K<your STOP value><servicename> linking to your /etc/ini.d/<servicename>. So make sure your START value is lower than samba's to start your script before samba. And the otherway around if needed using STOP variable.

And instead of /dev/null 2>&1 may worth to replace to direct everything to a log file and or enable logging via rclone as suggested before. Usually apps running as daemon have logging capabilities.

Good luck!

Thanks. Yes I knew about the start and stop and have set start to 97 since that is just before samba and stop to same as samba.

But unfortunately the script start just fails when started from reboot or from LuCi and nothing is output to a file when I direct output to file (although file gets created). The script stop from LuCi runs fine.

I don't know why the execution from LuCi or from router reboot is different from me manually executing script on command line using the init.d file or the rc file?

I assume it has to do with environment variable and rclone being in usr bin? Maybe something to do with overlay? It's not as if when script completes it kills background process?

I will try adding the echo to verify start is running. I'm pretty sure it is because the output file to which output is directed gets created but is just empty and the command doesn't seem to run.

sed -i -r -e "
s|\s+>\s+/dev/null\s+2>&1||
1a exec &> /tmp/mount-onedrive.log
1a set -x -v
1a env
" /etc/init.d/mount-onedrive
1 Like

OK thanks @vgaetera so this code:

#!/bin/sh /etc/rc.common
# Copyright (C) 2007 OpenWrt.org
exec &> /tmp/mount-onedrive.log
set -x -v
env

START=97
STOP=5

start() {
        rclone mkdir /tmp/OneDrive
        rclone mount "OneDrive:/Scanned Documents/" /tmp/OneDrive/ --vfs-cache-mode full --umask 000 --allow-other --daemon
}

stop() {
        fusermount -zu /tmp/OneDrive
}

results in the following output to the log file:

root@OpenWrt:~# cat /tmp/mount-onedrive.log
env
+ env
SHLVL=1
PWD=/

START=97
+ START=97
STOP=5
+ STOP=5

start() {
        rclone mkdir /tmp/OneDrive
        rclone mount "OneDrive:/Scanned Documents/" /tmp/OneDrive/ --vfs-cache-mode full --umask 000 --allow-other --daemon
}

stop() {
        fusermount -zu /tmp/OneDrive
}

[ -n "$USE_PROCD" ] && {
        extra_command "running" "Check if service is running"
        extra_command "status" "Service status"
        extra_command "trace" "Start with syscall trace"

        . $IPKG_INSTROOT/lib/functions/procd.sh
        basescript=$(readlink "$initscript")
        rc_procd() {
                local method="set"
                [ -n "$2" ] && method="add"
                procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
                "$@"
                procd_close_service "$method"
        }

        start() {
                rc_procd start_service "$@"
                if eval "type service_started" 2>/dev/null >/dev/null; then
                        service_started
                fi
        }

        trace() {
                TRACE_SYSCALLS=1
                start "$@"
        }

        stop() {
                procd_lock
                stop_service "$@"
                procd_kill "$(basename ${basescript:-$initscript})" "$1"
                if eval "type service_stopped" 2>/dev/null >/dev/null; then
                        service_stopped
                fi
        }

        reload() {
                if eval "type reload_service" 2>/dev/null >/dev/null; then
                        procd_lock
                        reload_service "$@"
                else
                        start
                fi
        }

        running() {
                service_running "$@"
        }

        status() {
                if eval "type status_service" 2>/dev/null >/dev/null; then
                        status_service "$@"
                else
                        _procd_status "$(basename ${basescript:-$initscript})" "$1"
                fi
        }
}
+ '[' -n  ]

ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
+ ALL_COMMANDS='boot shutdown depends start stop restart reload enable disable enabled '
ALL_HELP="${ALL_HELP}${EXTRA_HELP}"
+ ALL_HELP='\tstart           Start the service\n\tstop            Stop the service\n\trestart         Restart the service\n\treload          Reload configuration files (or restart if service does not implement reload)\n\tenable          Enable service autostart\n\tdisable         Disable service autostart\n\tenabled         Check if service is started on boot\n'
list_contains ALL_COMMANDS "$action" || action=help
+ list_contains ALL_COMMANDS start
+ local 'var=ALL_COMMANDS'
+ local 'str=start'
+ local val
+ eval 'val=" ${ALL_COMMANDS} "'
+ val=' boot shutdown depends start stop restart reload enable disable enabled  '
+ '[' ' boot shutdown depends' '!=' ' boot shutdown depends start stop restart reload enable disable enabled  ' ]
$action "$@"
+ start
+ rclone mkdir /tmp/OneDrive
+ rclone mount 'OneDrive:/Scanned Documents/' /tmp/OneDrive/ --vfs-cache-mode full --umask 000 --allow-other --daemon

Does this reveal the problem and what the solution ought to be?

1 Like
1 Like

That is not the issue here as I have already tried running with config explicitly referenced. No change. My config is in /etc/rclone/rclone.conf.

I expect the UCI setting only affects the LuCI app:
https://github.com/ElonH/Rclone-OpenWrt/blob/master/luci-app-rclone/root/etc/config/rclone#L6-L6
So, what method are you using to provide the path to the config?

@vgaetera - when I set the config path I get same issue. It just seems to fail without any explanation. Here is the log output when I explicitly set the config path:

root@OpenWrt:/etc/init.d# cat /tmp/mount-onedrive.log
env
+ env
SHLVL=1
PWD=/

START=97
+ START=97
STOP=5
+ STOP=5

start() {
        rclone --config /etc/rclone/rclone.conf mkdir /tmp/OneDrive
        rclone --config /etc/rclone/rclone.conf mount "OneDrive:/Scanned Documents/" /tmp/OneDrive/ --vfs-cache-mode full --umask 000 --allow-other --daemon
}

stop() {
        fusermount -zu /tmp/OneDrive
}

[ -n "$USE_PROCD" ] && {
        extra_command "running" "Check if service is running"
        extra_command "status" "Service status"
        extra_command "trace" "Start with syscall trace"

        . $IPKG_INSTROOT/lib/functions/procd.sh
        basescript=$(readlink "$initscript")
        rc_procd() {
                local method="set"
                [ -n "$2" ] && method="add"
                procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
                "$@"
                procd_close_service "$method"
        }

        start() {
                rc_procd start_service "$@"
                if eval "type service_started" 2>/dev/null >/dev/null; then
                        service_started
                fi
        }

        trace() {
                TRACE_SYSCALLS=1
                start "$@"
        }

        stop() {
                procd_lock
                stop_service "$@"
                procd_kill "$(basename ${basescript:-$initscript})" "$1"
                if eval "type service_stopped" 2>/dev/null >/dev/null; then
                        service_stopped
                fi
        }

        reload() {
                if eval "type reload_service" 2>/dev/null >/dev/null; then
                        procd_lock
                        reload_service "$@"
                else
                        start
                fi
        }

        running() {
                service_running "$@"
        }

        status() {
                if eval "type status_service" 2>/dev/null >/dev/null; then
                        status_service "$@"
                else
                        _procd_status "$(basename ${basescript:-$initscript})" "$1"
                fi
        }
}
+ '[' -n  ]

ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
+ ALL_COMMANDS='boot shutdown depends start stop restart reload enable disable enabled '
ALL_HELP="${ALL_HELP}${EXTRA_HELP}"
+ ALL_HELP='\tstart           Start the service\n\tstop            Stop the service\n\trestart         Restart the service\n\treload          Reload configuration files (or restart if service does not implement reload)\n\tenable          Enable service autostart\n\tdisable         Disable service autostart\n\tenabled         Check if service is started on boot\n'
list_contains ALL_COMMANDS "$action" || action=help
+ list_contains ALL_COMMANDS start
+ local 'var=ALL_COMMANDS'
+ local 'str=start'
+ local val
+ eval 'val=" ${ALL_COMMANDS} "'
+ val=' boot shutdown depends start stop restart reload enable disable enabled  '
+ '[' ' boot shutdown depends' '!=' ' boot shutdown depends start stop restart reload enable disable enabled  ' ]
$action "$@"
+ start
+ rclone --config /etc/rclone/rclone.conf mkdir /tmp/OneDrive
+ rclone --config /etc/rclone/rclone.conf mount 'OneDrive:/Scanned Documents/' /tmp/OneDrive/ --vfs-cache-mode full --umask 000 --allow-other --daemon

I don't understand why manually running the init.d script with '/etc/init.d/mount-onedrive start' works fine, but when executed from LuCi by clicking 'start' it fails like above.

Your post does not appear to be related to an officially released OpenWrt version, package or supported operation.

It is unlikely that you will receive useful input here.

Please seek advise from the relevant maintainer.

https://rclone.org/commands/rclone_mount/

That's not helpful or productive. I am dubious that this has anything to do with rclone itself. But I have created this issue now:

denial is a river in egypt