Trying to create script to refresh minidlna

I have this, but I don't think it works very well:
Code:
#!/bin/sh
# Stop the service
/usr/sbin/service minidlna stop

# Force a rescan of existing files (use -R instead of -r for a full rebuild)
/usr/local/sbin/minidlnad -r -f /usr/local/etc/minidlna.conf

# Start the service back up
/usr/sbin/service minidlna start

I get a message that is already running. Also, when I do a ps -aux | grep dlana, I get this:
Code:
/usr/local/sbin/minidlnad -r -f /usr/local/etc/minidlna.conf

What I would ordinarily get, if I did not run the script is just:
Code:
$ ps -aux | grep dlna
dlna       2922   0.0  0.3   146508  30824  -  INs  15:28     0:00.02 /usr/loca

dlna is the friendly name I gave it . Maybe, before I try to start the service back up, I should stop it again?
 
Last edited by a moderator:
I do not know it it is the right way to make this task. I have a script that do the job (refresh minidlna database), the run it in a cron job every day at 06:00AM. The script should be improved to check if the cathalog is changed (with a list of current cathalog/old cathalog and perhaps checksum or timestamp check for modifications), but... I have no time, so take it as it is and possibly improve it.

This is the sh script
Bash:
#! /usr/bin/env sh
#***************************************************************************************************
# Rebuild the multimedia cathalog
#---------------------------------------------------------------------------------------------------


#===================================================================================================
# Functions
#---------------------------------------------------------------------------------------------------

#---------------------------------------------------------------------------------------------------
# Print and log (to /var/log/messages) a message
# @param {String} $1 - The message to print and log
#---------------------------------------------------------------------------------------------------
printLog ()
{
    echo "$1"
    logger "$1"
}

#===================================================================================================
# Main
#---------------------------------------------------------------------------------------------------
printLog "minidlna-reload - Update minidlna multimedia cathalog"

# Check if 'minidlnad' is installed
which -s 'minidlnad'
iResult=$?
if [ $iResult -ne 0 ]; then
    printLog "ERROR: minidlna not installed"
    exit $iResult
fi
# Check if service is running
service -q minidlna status
iResult=$?
if [ $iResult -eq 0 ]; then
    # Service is running, stop it
    service -q minidlna stop
    iResult=$?
    if [ $iResult -ne 0 ]; then
        printLog "ERROR: Cannot stop minidlna service"
        exit $iResult
    fi
fi
# Start service with reload flag
minidlnad -r
iResult=$?
if [ $iResult -ne 0 ]; then
    printLog "ERROR: Error updating multimedia cathalog"
    exit $iResult
fi
# Wait 30 seconds and stop the service
sleep 30
service -q minidlna stop
iResult=$?
if [ $iResult -ne 0 ]; then
    printLog "ERROR: Error stopping minidlna service after updating multimedia cathalog"
    exit $iResult
fi
# Wait 2 seconds and start the service
sleep 2
service -q minidlna start
iResult=$?
if [ $iResult -ne 0 ]; then
    printLog "ERROR: Cannot start minidlna service"
    exit $iResult
fi
printLog "done"
exit 0

The cron job in /usr/local/etc/cron.d/minidlna
Code:
# Reload the minidlna multimedia cathalog
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# No mail
MAILTO=""

# See crontab(5) for field format.

0    6    *    *    *    root    /usr/local/system-env/bin/minidlna-reload

Hope it helps
 
The inotify monitoring service (in minidlna) doesn't work?

fwiw, there's also net/gerbera in ports tree which refreshes automatically

I am new to minidlna. I have read that, on freebsd, minidlna has to updated manually.
Supposedly, on other platforms there is no need to manually refresh the minidlna, but for some reason, under freebsd, the database does not always refresh on it's own.

I am not familiar with the inotify monitoring service.

Is gerbera another dlna application?
 
I do not know it it is the right way to make this task. I have a script that do the job (refresh minidlna database), the run it in a cron job every day at 06:00AM. The script should be improved to check if the cathalog is changed (with a list of current cathalog/old cathalog and perhaps checksum or timestamp check for modifications), but... I have no time, so take it as it is and possibly improve it.

This is the sh script
Bash:
#! /usr/bin/env sh
#***************************************************************************************************
# Rebuild the multimedia cathalog
#---------------------------------------------------------------------------------------------------


#===================================================================================================
# Functions
#---------------------------------------------------------------------------------------------------

#---------------------------------------------------------------------------------------------------
# Print and log (to /var/log/messages) a message
# @param {String} $1 - The message to print and log
#---------------------------------------------------------------------------------------------------
printLog ()
{
    echo "$1"
    logger "$1"
}

#===================================================================================================
# Main
#---------------------------------------------------------------------------------------------------
printLog "minidlna-reload - Update minidlna multimedia cathalog"

# Check if 'minidlnad' is installed
which -s 'minidlnad'
iResult=$?
if [ $iResult -ne 0 ]; then
    printLog "ERROR: minidlna not installed"
    exit $iResult
fi
# Check if service is running
service -q minidlna status
iResult=$?
if [ $iResult -eq 0 ]; then
    # Service is running, stop it
    service -q minidlna stop
    iResult=$?
    if [ $iResult -ne 0 ]; then
        printLog "ERROR: Cannot stop minidlna service"
        exit $iResult
    fi
fi
# Start service with reload flag
minidlnad -r
iResult=$?
if [ $iResult -ne 0 ]; then
    printLog "ERROR: Error updating multimedia cathalog"
    exit $iResult
fi
# Wait 30 seconds and stop the service
sleep 30
service -q minidlna stop
iResult=$?
if [ $iResult -ne 0 ]; then
    printLog "ERROR: Error stopping minidlna service after updating multimedia cathalog"
    exit $iResult
fi
# Wait 2 seconds and start the service
sleep 2
service -q minidlna start
iResult=$?
if [ $iResult -ne 0 ]; then
    printLog "ERROR: Cannot start minidlna service"
    exit $iResult
fi
printLog "done"
exit 0

The cron job in /usr/local/etc/cron.d/minidlna
Code:
# Reload the minidlna multimedia cathalog
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# No mail
MAILTO=""

# See crontab(5) for field format.

0    6    *    *    *    root    /usr/local/system-env/bin/minidlna-reload

Hope it helps

I cannot explain this, minidlna is running, but when I do a:
# which -s 'minidlnad'

I get nothing.

However when I do:
Code:
# ps -aux | grep dlna
dlna       2922   0.0  0.5   178252   56852  -  INs  08:25      0:00.15 /usr/lo

In the config file, I configured 'dlna' to be the friendly name. But it seems to me that minidlnad should be running.

I am using the bash shell. Maybe that has something to do with it?
 
I am new to minidlna. I have read that, on freebsd, minidlna has to updated manually.
Supposedly, on other platforms there is no need to manually refresh the minidlna, but for some reason, under freebsd, the database does not always refresh on it's own.

I am not familiar with the inotify monitoring service.

Is gerbera another dlna application?
It should be enabled by default, https://github.com/glebius/minidlna/blob/master/minidlna.conf#L41

Yes, gerbera is indeed another dlna server. https://gerbera.io/
Both can be installed side by side for evaluation but not run at the same time.
 
I remember minidlna automatically refresh the datatbase when I istalled few years ago (I do not remember when, 13.x-RELEASE/14.0-RELEASE?), then after an update (port and/or system) stop auto updating. I was new to minidlna, I thought I made a mistake somewehere or something changed in minidlna and wrote that script, but never investigated deep. In my config inotify=yes
 
I cannot explain this, minidlna is running, but when I do a:


I get nothing.

However when I do:


In the config file, I configured 'dlna' to be the friendly name. But it seems to me that minidlnad should be running.

I am using the bash shell. Maybe that has something to do with it?

The command which -s minidlnad print nothing, set exit code to 0 if minidlna exists and in PATH, otherwise 1. To print out the result remove the -s option
 
I have this, but I don't think it works very well:
Code:
#!/bin/sh
# Stop the service
/usr/sbin/service minidlna stop

# Force a rescan of existing files (use -R instead of -r for a full rebuild)
/usr/local/sbin/minidlnad -r -f /usr/local/etc/minidlna.conf

# Start the service back up
/usr/sbin/service minidlna start

I get a message that is already running. Also, when I do a ps -aux | grep dlana, I get this:
Code:
/usr/local/sbin/minidlnad -r -f /usr/local/etc/minidlna.conf

What I would ordinarily get, if I did not run the script is just:
Code:
$ ps -aux | grep dlna
dlna       2922   0.0  0.3   146508  30824  -  INs  15:28     0:00.02 /usr/loca

dlna is the friendly name I gave it . Maybe, before I try to start the service back up, I should stop it again?

I think it works better if I put in another service stop after the db refresh. Here is my new script:

#!/bin/sh
# Stop the service
/usr/sbin/service minidlna stop

# Force a rescan of existing files (use -R instead of -r for a full rebuild)
/usr/local/sbin/minidlnad -r -f /usr/local/etc/minidlna.conf

# Stop the service
/usr/sbin/service minidlna stop

# Start the service back up
/usr/sbin/service minidlna start
 
Back
Top