Bash script to restart mylar when it hangs.

Information and Tutorials on features in Mylar and how to use it
Post Reply
bmfrosty
Posts: 14
Joined: Wed May 07, 2014 2:12 am

Bash script to restart mylar when it hangs.

Post by bmfrosty »

Tired of restarting mylar when it hangs. Slowly cataloging ways it logs when it hangs. Should turn it into a function. May eventually turn it into something that uses "curl http://localhost:8090/home | grep something" to test for upness and then restart if it fails upness twice.

Run in cron.

YOU WILL HAVE TO EDIT WITH YOUR OWN FILE LOCATIONS AND DIRECTORIES

testmylar.sh

Code: Select all

#!/bin/bash

if (tail -n 2 /home/bmfrosty/mylar/logs/mylar.log | grep "end reached. ignoring remainder.") ; then
	if [ -f /home/bmfrosty/mylar/logs/mylar.bad1 ] ; then
		sudo service mylar restart
		rm -f /home/bmfrosty/mylar/logs/mylar.bad1
	else
		touch /home/bmfrosty/mylar/logs/mylar.bad1
	fi
else
	rm -f /home/bmfrosty/mylar/logs/mylar.bad1
fi

if (tail -n 2 /home/bmfrosty/mylar/logs/mylar.log | grep "database is locked") ; then
	if [ -f /home/bmfrosty/mylar/logs/mylar.bad2 ] ; then
		sudo service mylar restart
		rm -f /home/bmfrosty/mylar/logs/mylar.bad2
	else
		touch /home/bmfrosty/mylar/logs/mylar.bad2
	fi
else
	rm -f /home/bmfrosty/mylar/logs/mylar.bad2
fi
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: Bash script to restart mylar when it hangs.

Post by evilhero »

You're being a demon with the bash scripts eh ;)

Definitely useful, could also use this within Mylar son when an exception error occurs, it would auto-restart, saving the last log file in the process.

I have exceptions and traceback errors now getting logged in Mylar so it'd be fairly easy to build into.

PS. Database locking might be done too. I'm heavily testing this thing out and after a week of iterations I may have just done it. I'm not sure if it affects speed of processing though, but no locking is more important at this point.
bmfrosty
Posts: 14
Joined: Wed May 07, 2014 2:12 am

Re: Bash script to restart mylar when it hangs.

Post by bmfrosty »

evilhero wrote:You're being a demon with the bash scripts eh ;)

Definitely useful, could also use this within Mylar son when an exception error occurs, it would auto-restart, saving the last log file in the process.

I have exceptions and traceback errors now getting logged in Mylar so it'd be fairly easy to build into.

PS. Database locking might be done too. I'm heavily testing this thing out and after a week of iterations I may have just done it. I'm not sure if it affects speed of processing though, but no locking is more important at this point.
Most of my scripts aren't here. :)

I'm rather looking forward to the new release/dev version/whatever. I love a lot of what it does, and I look forward to using this more and more for collection management.

I'm also planning to spend some time once the release is in dev helping with the logging. I love that logs from filechecker.py state that they're from filechecker.py, and I want to expand that for all your sources, and perhaps even include classes and functions in the logging.
Post Reply