More > JRiver Media Center 22 for Linux
Request for tutorial on setting up cron job for MediaCenter on QNAP
Afrosheen:
I'm thankful for Bob to have found the key command to request this, but as a command line newbie, I'm wondering if those of you who know better can give a hand to provide a tutorial to set up a cron job to keep MC running on my QNAP. Bob mentioned a few things that are required to be done first in order for this to run successfully. I've listed them out below, but I'm wondering how one would go about doing this. I'm sure this would be beneficial for others who have MC installed on their QNAP NAS.
Prerequisites:
1. How to obtain process ID of mediacenter22 via pidof command?
2. How to find out if the X server is running on the QNAP, i.e. the user is logged in?
Setting up the script:
1. Command to see if the process ID of mediacenter22 exists;
2. If not running, then run the following command:
--- Code: ---chroot /share/CACHEDEV1_DATA/.qpkg/HD_Station su - -c "export DISPLAY=:0 ; nohup mediacenter22&"
--- End code ---
3. Configure script via cron or launchd command to run every 5 minutes, or user defined.
I only know about cron and launchd through apps like LingonX and Cronnix on the MacOS which are just GUI frontends for the command. I admit I should learn more about using the command line personally, but I'm having a hard time investing the necessary time right now.
Thanks again for the consideration!
-A
imugli:
You'll want to try something like this (providing you have access to a terminal)...
Create a bash script (we'll call it MC.sh) with the following...
#!/bin/bash
pidof mediacenter22 >/dev/null
if [[ $? -ne 0 ]] ; then
echo "Restarting MC: $(date)" >> /var/log/MC.txt
chroot /share/CACHEDEV1_DATA/.qpkg/HD_Station su - -c "export DISPLAY=:0 ; nohup mediacenter22&"
fi
This checks for a pid, and if 0 (or doesn't exist) starts MC. Make it executable by running
chmod u+x your/location/to/MC.sh
Then, run
crontab -e
and add the following line to it
*/5 * * * * /your/path/to/MC.sh
I haven't tested this, but adapted it from http://stackoverflow.com/questions/20162678/linux-script-to-check-if-process-is-running-act-on-the-result.
aoqw76:
I have a cron job that has the same goal, but works by looking for the existence of crash logs and relaunching mc if one is found, or indeed launching if its not running at all.
--- Code: ---zzip="/home/robert/Documents/mc22crash.zip"
touch /var/crash/dummy_file
## this counts how many crash logs exist for mediacenter
checkmc=`ls -ltr /var/crash/* | grep mediacenter22 | wc -l`
## this counts if mediacenter is one of the running applications
checkmcv2=`ps -aux | grep -v grep | grep mediacenter | wc -l`
## you dont need to do it, but i move the crash file and zip it, so you can skip/remove that code if not needed. it does help tidy up the crash logs though.
now=$(date +%y%m%d%H%M)
## if it has crashed i.e. crash log found
if [ $checkmc -gt 0 ]
then
## apport is the app that pops up in ubuntu to notify you that something has gone wrong, but i just get rid
pkill apport
pkill mediacenter
## this block is moving and zipping the log file
cd /var/crash
for file in *mediacenter22*
do
chown robert:robert "$file"
mv "$file" "$file.$now"
done
mv *mediacenter22* /home/robert/Documents
rm $zzip
zip /home/robert/Documents/mc22crash /home/robert/Documents/$file.$now
fi
## now if either a crash log was found, or mediacenter was not found as a running application, restart it
if [ $checkmc -eq 0 ] | [ $checkmcv2 -eq 0 ]
then
/usr/bin/mediacenter22
fi
--- End code ---
astromo:
Based on this:
https://www.techandme.se/qnap-and-cron/
Looks like cron on a qnap is far from straight forward.
One to investigate. Thanks for highlighting the possibilities.
Afrosheen:
--- Quote from: astromo on May 07, 2017, 01:03:43 am ---Based on this:
https://www.techandme.se/qnap-and-cron/
Looks like cron on a qnap is far from straight forward.
One to investigate. Thanks for highlighting the possibilities.
--- End quote ---
Yes, I was having much trouble figuring out how to use QNAP's crontab so I went with a different route with tonight being the first test run that went successfully. I hope that with this it will be the end of having to manually start up MediaCenter on my QNAP.
First, I went with a different crontab for QNAP: WebCrontab, which I installed via QNAP's AppCenter. The qpkg is only located on QNAP EU, not on the default repository. To add QNAP EU repository, you'll need to open AppCenter's settings that's located on the top right by clicking on the gear icon. Then add the following link with your preferred title: http://store.qnapclub.eu/store.php
Once that's done, search for WebCrontab from the newly added repository and install it. Add port 4000 to your router's forwarding list. Then add the script that @imugli wrote as a task. Here's a screenshot of my setup on WebCrontab.
So far each time I manually quit MC, it pops right back up. I feel like I conquered an indomitable foe.
Navigation
[0] Message Index
[#] Next page
Go to full version