Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init.d script problem #21

Open
lynxthecat opened this issue Sep 11, 2021 · 2 comments
Open

init.d script problem #21

lynxthecat opened this issue Sep 11, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@lynxthecat
Copy link

lynxthecat commented Sep 11, 2021

I am struggling with a strange issue relating to setting up an init.d script on OpenWrt to launch an rclone mount, as follows:

root@OpenWrt:/etc/init.d# cat /etc/init.d/mount-onedrive
#!/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 --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
}

Namely, when I run '/etc/init.d/mount-onedrive start' manually, it works fine (as in rclone process shows up with 'ps' and rclone mount is present). But when it is run from LuCi or upon router reboot it fails (as in the rclone process does not show up with 'ps' and the rclone mount is not present), with this output log:

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
@lynxthecat
Copy link
Author

lynxthecat commented Sep 11, 2021

I found the solution - I just needed to include:

export PATH=/usr/sbin:/usr/bin:/sbin:/bin

Working script is now:

#!/bin/sh /etc/rc.common
# Copyright (C) 2007 OpenWrt.org

export PATH=/usr/sbin:/usr/bin:/sbin:/bin

exec &> /tmp/mount-onedrive.log

START=97
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 ful}

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

I hope this is safe enough to run as an init.d script in OpenWrt.

@ElonH
Copy link
Collaborator

ElonH commented Sep 12, 2021

It is a nice feature that mount cloud storage into file system. Maybe I can integrate it into luci, and manipulate mounted storage on web page

@ElonH ElonH added the enhancement New feature or request label Sep 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants