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?
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.
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.
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.
@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.