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

The generated init script doesn't start synoindexwatcher at boot #49

Open
vordho opened this issue May 20, 2021 · 8 comments
Open

The generated init script doesn't start synoindexwatcher at boot #49

vordho opened this issue May 20, 2021 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@vordho
Copy link

vordho commented May 20, 2021

Hello.

My generated script doesn't start up at NAS boot, i have to launch it manually at every reboot.
I'm sorry, i can't find alone where can the issue come from.
Here are the informations.

$ python3 -m synoindexwatcher --generate-init --config=/volume1/homes/jo/synoindexwatcher.conf --logfile=/volume1/homes/jo/synoindexwatcher.log | sudo tee /usr/local/etc/rc.d/S99synoindexwatcher.sh
$ sudo chmod a+x /usr/local/etc/rc.d/S99synoindexwatcher.sh

#!/bin/sh

# This file has been generated by Synoindex Watcher.

ARGS="--config=/volume1/homes/jo/synoindexwatcher.conf --logfile=/volume1/homes/jo/synoindexwatcher.log"
PIDFILE="/var/run/synoindexwatcher.pid"

start_synoindexwatcher() {
    if [ ! -f "$PIDFILE" ]; then
        echo "Starting synoindexwatcher..."
        # Set LC_ALL to ensure that the filesystem encoding is correctly
        # detected during boot.
        nohup env LC_ALL=en_US.utf8 /usr/local/bin/python3 -m synoindexwatcher $ARGS > /dev/null 2>&1 &
        echo $! > "$PIDFILE"
    else
        echo "Error: synoindexwatcher has already been started"
        exit 1
    fi
}

stop_synoindexwatcher() {
    if [ -f "$PIDFILE" ]; then
        echo "Stopping synoindexwatcher..."
        kill `cat "$PIDFILE"`
        rm "$PIDFILE"
    else
        echo "Error: synoindexwatcher has not been started yet"
        exit 1
    fi
}

case "$1" in
    start|"")
        start_synoindexwatcher
        ;;
    restart|reload|force-reload)
        stop_synoindexwatcher
        start_synoindexwatcher
        ;;
    stop)
        stop_synoindexwatcher
        ;;
    *)
        echo "Usage: `basename $0` [start|stop]" >&2
        exit 3
        ;;
esac

@letorbi letorbi self-assigned this May 20, 2021
@letorbi letorbi added the question Further information is requested label May 20, 2021
@letorbi
Copy link
Owner

letorbi commented May 20, 2021

Hej, are you able to start Synoindex Watcher manualy by using the init-script (/usr/local/etc/rc.d/S99synoindexwatcher.sh start) or are you starting it directly (python3 -m synoindexwatcher --config=/volume1/homes/jo/synoindexwatcher.conf --logfile=/volume1/homes/jo/synoindexwatcher.log)?

@vordho
Copy link
Author

vordho commented May 20, 2021

Hello.

Starting it directly works fine :

$ python3 -m synoindexwatcher --config=synoindexwatcher.conf --logfile=synoindexwatcher.log &
[1] 8480
$ ps aux | grep synoindexwat
        8480  5.8  0.6  81156 12620 pts/24   S    18:57   0:00 python3 -m synoindexwatcher --config=synoindexwatcher.conf --logfile=synoindexwatcher.log

while killing the process with
$ kill -9 8480

Then, trying to start it with the script will give :

$ /usr/local/etc/rc.d/S99synoindexwatcher.sh start
Error: synoindexwatcher has already been started

While no process is running.
But, there is an existing /var/run/synoindexwatcher.pid file.

So, i've deleted the /var/run/synoindewwatcher.pid and tried the start script again.
It does work and start with out issue.

Then i've killed the process, remove the .pid and reboot.

After reboot, synoindexwatcher is NOT running (no process from ps aux | grep synoindexwatcher), but a pid file exist at /var/run/synoindexwatcher.pid

@letorbi
Copy link
Owner

letorbi commented May 25, 2021

I assume that the config- and/or log-file cannot be found, because you are using relative paths. Could you use absolute paths (like --config=/usr/local/etc/synoindexwatcher.conf --logfile=/var/log/synoindexwatcher.log) and try again?

Please ensure that the files are existing and that the user, who runs Synoindex Watcher, can access them. You can create an empty logfile easily via touch /var/log/synoindexwatcher.log.

@vordho
Copy link
Author

vordho commented May 25, 2021

Thanks for you answer :)

Well, i'm not using relative paths in /usr/local/etc/rc.d/S99synoindexwatcher.sh :
ARGS="--config=/volume1/homes/jo/synoindexwatcher.conf --logfile=/volume1/homes/jo/synoindexwatcher.log"

Also, /usr/local/etc/rc.d/S99synoindexwatcher.sh is supposed to be run by root at boot isn't it ?
And both files (.conf and .log) have 777 right (and root is suppose to be able to acces it).

-rwxrwxrwx 1 jo users 145 May 20 08:20 synoindexwatcher.conf
-rwxrwxrwx+ 1 root root 2892485 May 20 19:22 synoindexwatcher.log

@letorbi
Copy link
Owner

letorbi commented May 26, 2021

Well, i'm not using relative paths in /usr/local/etc/rc.d/S99synoindexwatcher.sh

Oh, my bad. The paths and access rights seem to look right. Does the logfile contain any output? It would be nice, if you could post it here.

Otherwise the line to start Synoindex Watcher might have some kind of bug. Could you test the following commands and post their output, if an error occurs?

  • nohup env LC_ALL=en_US.utf8 /usr/local/bin/python3 -m synoindexwatcher --config=/volume1/homes/jo/synoindexwatcher.conf --logfile=/volume1/homes/jo/synoindexwatcher.log
  • env LC_ALL=en_US.utf8 /usr/local/bin/python3 -m synoindexwatcher --config=/volume1/homes/jo/synoindexwatcher.conf --logfile=/volume1/homes/jo/synoindexwatcher.log
  • env /usr/local/bin/python3 -m synoindexwatcher --config=/volume1/homes/jo/synoindexwatcher.conf --logfile=/volume1/homes/jo/synoindexwatcher.log
  • /usr/local/bin/python3 -m synoindexwatcher --config=/volume1/homes/jo/synoindexwatcher.conf --logfile=/volume1/homes/jo/synoindexwatcher.log

@vordho
Copy link
Author

vordho commented May 26, 2021

I've tried to move conf and log file to
/usr/local/etc/synoindexwatcher.conf
/var/log/synoindexwatcher.log

Made both owned by root:root and 755.
Modified /usr/local/etc/rc.d/S99synoindexwatcher.sh accordingly

But, it still doesn't start at boot...

Does the logfile contain any output? It would be nice, if you could post it here.

No, only :
2021-05-20 19:22:35,842 INFO Waiting for media file changes...

I guess because of loglevel=INFO
in /usr/local/etc/synoindexwatcher.conf
Also, it does log when the script execute well, but doesn't seems to log script start process's potentials errors

Your commands does works fine without errors...
And the first one does create a nohup.out file but empty.

@LapinFou
Copy link

LapinFou commented Jul 18, 2023

I know this message is two years old, but if it can help anyone, here's what I successfully did on my Syno.
Please note that it is running DSM7.

To set up a configuration that will survive any DSM update/reboot, here's what I did (adjust the commands according to your configuration). In my setup, all my Docker stuff, including this great Synoindex Watcher Python script, is located in this path: /volume1/docker/

First, as recommended, I installed Python virtual environment:
sudo -i → Be careful, by doing so you will be in god mode...
export PyVenv="/volume1/docker/synoindexwatcher"
python -m venv $PyVenv
$PyVenv/bin/python -m pip install --upgrade pip
$PyVenv/bin/python -m pip install --upgrade synoindexwatcher

Then, I generated the config and init file:
$PyVenv/bin/python -m synoindexwatcher --generate-config | tee $PyVenv/synoindexwatcher.conf
$PyVenv/bin/python -m synoindexwatcher --generate-init | tee $PyVenv/synoindexwatcher.sh

I have updated the configuration file with the correct log file path: logfile=/volume1/docker/synoindexwatcher/synoindexwatcher.log.

[GLOBAL]
blacklist=^\.|^\@|\.tmp$
whitelist=
logfile=/volume1/docker/synoindexwatcher/synoindexwatcher.log
loglevel=DEBUG
[...]

For the init file, I added the line sysctl -w fs.inotify.max_user_watches=204800 in the start_synoindexwatcher() function.

[...]
start_synoindexwatcher() {
    if [ ! -f "$PIDFILE" ]; then
        echo "Starting synoindexwatcher..."
        # Set LC_ALL to ensure that the filesystem encoding is correctly
        # detected during boot.
        sysctl -w fs.inotify.max_user_watches=204800
        nohup env LC_ALL=en_US.utf8 /volume1/docker/synoindexwatcher/bin/python -m synoindexwatcher $ARGS > /dev/null 2>&1 &
        echo $! > "$PIDFILE"
    else
        echo "Error: synoindexwatcher has already been started"
        exit 1
    fi
}
[...]

From here, you don't need an SSH connection anymore. The first benefit is that, with the correct permissions on your NAS, you can access all the config, init, and log files through SMB or whatever connection you are using (NFS, etc...).

The final step is to start and stop the Synoindex Watcher. To do so, you need to create two tasks in the DSM task scheduler. One task should run when the NAS boots up, and the other task should run when the NAS stops (or reboots, as it is the same process).
More information can be found on the official Synology website: Task Scheduler
The two triggered tasks I created are named SynoIndexStart and SynoIndexStop.
The tasks are, of course, executed as root, and the commands are respectively
bash /volume1/docker/synoindexwatcher/synoindexwatcher.sh start
and
bash /volume1/docker/synoindexwatcher/synoindexwatcher.sh stop

With this solution, you can even start and stop the script without the need to log on through an SSH connection. The setup allows you to manage the Synoindex Watcher easily through the DSM task scheduler, providing a more user-friendly approach.

I hope these tips will be helpful to others.

@LapinFou
Copy link

Here are some screenshots.
Sorry, they are displayed in French since I'm French, but I'm sure you get the idea.
Start
Start2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants