MinimServer Forum
Feature Request: Re-Scan/inotify - Printable Version

+- MinimServer Forum (https://forum.minimserver.com)
+-- Forum: MinimServer (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: Feature Request: Re-Scan/inotify (/showthread.php?tid=41)

Pages: 1 2


RE: Feature Request: Re-Scan/inotify - KoS - 26-04-2012 17:44

(26-04-2012 17:00)simoncn Wrote:  
(26-04-2012 16:29)KoS Wrote:  hmm.. haven't realized the problem with the SIGHUP when exiting from a shell. you could use instead another signal for the restart of the daemon, e.g. SIGUSR1 or SIGUSR2 ?
That's a good idea, though I'd need to be careful not to confict with the use of these signals for other purposes, such as controlling LinuxThreads. I think the best approach would be to make the choice of 'reload' signal configurable, so that people could choose a signal that doesn't conflict with other usage in their environment.
as far as i know the SIGUSR1 and SIGUSR2 kill signals are explicitly for custom use of an application and no-one should expect anything specific happening when using this signals. so its up to the application to define the usage.


RE: Feature Request: Re-Scan/inotify - KoS - 30-04-2012 14:55

i have created the following bash script to automatically restart my minim instance when files are added/deleted/modified:
Code:
#!/bin/sh
LOCK_FILE=/opt/minim/inotify.lck

restartminim() {
        while true; do
                if [ -e "$LOCK_FILE" ] ; then
                        if test `find "$LOCK_FILE" -mmin +1`
                        then
                                /opt/minim/restartminim.exp
                                rm $LOCK_FILE
                        fi
                fi
                sleep 60
        done
}

myinotifywait() {
        while inotifywait -q -r -e close_write,move,delete /media/upnp/Musik/; do
                touch $LOCK_FILE
        done
}

myinotifywait&
pid1=$!
echo "Myinotifywait spawned: $pid1"

restartminim&
pid2=$!
echo "Restartminim spawned: $pid2"

# Kill all sub-processes
trap "kill 0" SIGINT SIGTERM EXIT
wait

echo "finish."



RE: Feature Request: Re-Scan/inotify - simoncn - 30-04-2012 18:48

Thanks for sharing this!


RE: Feature Request: Re-Scan/inotify - KoS - 16-07-2012 11:26

new version of the script:
Code:
#!/bin/sh
pdir=${0%`basename $0`}
lck_file=$pdir/`basename $0`.lck
log_file=$pdir/`basename $0`.log
ino_lck_file=$pdir/`basename $0`.inotify.lck
conf_file=$pdir/`basename $0`.conf

if [ -f $conf_file ]; then
        source $conf_file
else
        echo "ERROR: Can't locate $conf_file"
        exit 1
fi

# ------------------------------------------------------------
# Am I Running
# ------------------------------------------------------------
if [ -f "${lck_file}" ]; then

  # The file exists so read the PID
  # to see if it is still running  
  MYPID=`head -n 1 "${lck_file}"`  

  TEST_RUNNING=`ps -p ${MYPID} | grep ${MYPID}`

  if [ -z "${TEST_RUNNING}" ]; then
    # The process is not running  
    # Echo current PID into lock file
    echo "Not running"   >>${log_file}
    echo $$ > "${lck_file}"
  else
    echo "`basename $0` is already running [${MYPID}]"  >>${log_file}
    echo "`basename $0` is already running [${MYPID}]"
    exit 0
  fi

else
#  echo "Not running"
  echo $$ > "${lck_file}"
fi

echo "*********************************" > ${log_file}
echo "`date`" >> ${log_file}
echo "Main process started : $PID" >>${log_file}

restartminim() {
        while true; do
                if [ -e "$ino_lck_file" ] ; then
                        if test `find "$ino_lck_file" -mmin +1`
                        then
                                echo "Restarting minim at `date`" >>${log_file}
                                $pdir/restartminim.exp 2>&1 >>${log_file}
                                rm $ino_lck_file
                        fi
                fi
                sleep 30
        done
}

myinotifywait() {
        while eval inotifywait -q -r -e close_write,move,delete $watch_dir >>${log_file}; do
                touch $ino_lck_file
        done
}

myinotifywait&
pid1=$!
echo "Myinotifywait spawned: $pid1" >>${log_file}

restartminim&
pid2=$!
echo "Restartminim spawned : $pid2" >>${log_file}

# Kill all sub-processes
trap "kill 0" SIGINT SIGTERM EXIT
wait

echo "finish." >>${log_file}

the config file has just one line/variable:
Code:
watch_dir="/media/upnp"



RE: Feature Request: Re-Scan/inotify - alegend - 23-12-2012 18:49

Im runnin a synology nas ...
where do i have to put this script so it is working?


RE: Feature Request: Re-Scan/inotify - winxi - 24-12-2012 10:34

(23-12-2012 18:49)alegend Wrote:  Im runnin a synology nas ...
where do i have to put this script so it is working?
Hi, unfortunately, this is not an easy task. A challenge might be to compile and install inotify-tools.
I will look into it and maybe make a separate package to automate the necessary steps for Synology DS's.


RE: Feature Request: Re-Scan/inotify - alegend - 24-12-2012 13:18

This would be really great!
Because otherwise I always have to use my comp to update the database.