Hi guys
I'm running Serviio on a headless Ubuntu server. All my files are located on a NAS, which is NFS mounted on the server and then served onto my devices.
My main issue so far is with the library updates. Whenever there is a power issue in my area, both my server and NAS go down when the UPS is out of juice.
When power is back up, NAS and server boot, but usually the NAS is slower, and by the time the server tries to mount the disk via NFS, it fails, since the NAS is still booting.
Then Serviio starts, does not detect any file and clears the database. When I manually remount the NAS disk, Serviio starts reindexing everything, which usually takes a few hours.
I've done an upstart script for Serviio that checks if the mounted folder is available and if not, does not start Serviio.
I've also created a simple script that runs every minute and if the folder is unavailable, stops the Serviio service, so that the database does not update.
I realize this solution is tailored for my specific needs, and that in the event of an issue as described above, it requires human intervention, but that works for me. All i try to do is stop the database refresh when the files are not there. I could stop the automatic refresh from the serviio console, but the family add new files everyday and I don't want to manually refresh every time.
I've used the upstart script provided by soundcheck in this same post (
posting.php?mode=reply&f=17&t=71#pr58712), and modified it to my needs. I post it here in case it can be of use to someone.
create a file /etc/init/serviio.conf
- Code:
#!upstart
# script will run only after network is up and my /media/nas mounted
start on (started networking and mounted MOUNTPOINT=/media/nas)
#optional stuff
description "Serviio Server Upstart Script"
# configuration variables
#user that will run the Serviio service
env USER=ale
#the folder that contains all my movies
env FOLDER=/media/nas/videos
#a file in the folder above
env FPID=.serviio.pid
#path to the serviio start script
env BIN=/path/to/your_serviio/bin/serviio.sh
# pre-start stanza
pre-start script
# main process will not be run if /some/file does not exist
# if the file defined above does not exist (folder not mounted) it will exit
test -f $FOLDER/$FPID || { stop ; exit 0; }
end script
# normal script
script
# Set up correct LANG // you might not need this
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG LANGUAGE LC_MESSAGES LC_ALL LC_CTYPE
fi
#start the service
exec start-stop-daemon --start --make-pidfile --pidfile /var/run/serviio.pid -c $USER --exec $BIN
end script
In my case, i'm running serviio with my own user which i'm sure is the wrong thing to do. You can create a dedicated user following soundcheck's post (
posting.php?mode=reply&f=17&t=71#pr58712)
Now you run
- Code:
sudo initctl reload-configuration
If I reboot, my script will run after network is up and my folder is mounted.
Now i want to add another checkpoint in case my NAS goes down for any reason.
To do this I created a simple bash script and scheduled it with cron.
Create a file called test_serviio.sh
- Code:
#!/bin/bash
# this is the file to check
FPID=/media/nas/videos/.serviio.pid
if [ ! -f $FPID ]
then
echo "File not found: "$FPID
service serviio stop
echo "The system tried to stop Serviio service to keep the database unrefreshed at "$(date)" because "$FPID" was not available. You will need to restart the service manually, but first make sure that "$FPID" is available again." | mail -s "Serviio service stopped" you@yourmail.com
fi
I have scheduled it in the root crontab to run every minute. It's very rudimentary but gets the work done.
One small issue is that if the NAS goes down, it will send me a mail every minute for as long as the disk is not remounted. But well...
As you can see from the above, i'm a linux newbie, can't program at all, but hey, seems to work. Hoping that this could help some people.