Projekt Watchdog 4 Emby

Silas Mariusz

rm -rf /
Help us, GOD!
5 Kwiecień 2008
10 318
33
2 634
153
40
Nowy Sącz
forum.qnap.net.pl
QNAP
TS-x77
Ethernet
1 GbE
Potrafi Wam się zawiesić Emby?

O to Watchdog Emby skrypt, który wystarczy umieścić w Cronie, aby automatycznie restartował i uruchamiał Emby w przypadku awarii.
Aby umieścić go w cronie wystarczy skorzystać z paczki WebCrontab:
Qnapclub Store: WebCrontab

Poponowane ustawienie do skryptu?
upload_2017-5-19_1-18-24.png
Field|Value
\Name|Qmono-Emby
\Description|Qmono restart if Emby is not working
\Schedule|*/30 * * * * *
\Command|/share/CACHEDEV1_DATA/.qpkg/watchdog-emby.sh
\|NOTKA: Powyższa ścieżka ma prowadzić do pliku, zawartego w poniższym źródłem z uprawnieniami do uruchomienia.

chmod +x /sciezka/tj./share/bla/bla/bla/watchdog-emby.sh
\Directory| (pusto)
\Enviriontment Variables| (pusto)

Źródło:
Bash:
#!/bin/sh

# Helper exit
function _exit()
{
	echo -e "$*"
	echo

	# interactive shell? then keep user attention on the err msg
	if [[ -t "$fd" ]] || [[ -p /dev/stdin ]]; then
		echo -n "" ; sleep 1
		echo -n "" ; sleep 1
		echo -n "" ; sleep 1
		echo -n "" ; sleep 1
		echo -n "" ; sleep 1
	fi

	exit 1
}

function _warn()
{
	echo -e "$*"
	echo

	# interactive shell? then keep user attention on the err msg
	if [[ -t "$fd" ]] || [[ -p /dev/stdin ]]; then
		echo -n "" ; sleep 1
		echo -n "" ; sleep 1
		echo -n "" ; sleep 1
		echo -n "" ; sleep 1
		echo -n "" ; sleep 1
	fi
}

# Check if there is Emby enabled
__emby_enable="$(getcfg Emby Enable -f /etc/config/qpkg.conf -u -d error)"
[ "$__emby_enable" = "TRUE" ] || _exit Emby found, but its not enabled. Please enable it first.
__emby_path="$(getcfg Emby Install_Path -f /etc/config/qpkg.conf -d error)"
[ -d "$__emby_path" ] || _exit Emby directory not found. Please reinstall emby.

# Check if there is Emby enabled
__Qmono_enable="$(getcfg Qmono Enable -f /etc/config/qpkg.conf -u -d error)"
[ "$__Qmono_enable" = "TRUE" ] || _exit Qmono found, but its not enabled. Please enable it first.
__Qmono_path="$(getcfg Qmono Install_Path -f /etc/config/qpkg.conf -d error)"
[ -d "$__Qmono_path" ] || _exit Qmono directory not found. Please reinstall emby.


# Strip alias
alias strip_esc='sed -r "s/\x1B[\[|\(]([0-9]{1,2}(;[0-9]{1,2})?)?[m|K|A|B|C|E|J|S|Z|H]//g"'


# Write error log message and exit
# ###########################################################################
_err(){
	local msg_type="err!"
	local write_err="/sbin/log_tool -t2 -u$NAME -p127.0.0.1 -mlocalhost -a"
	local message="$NAME: ${*:-"Unknown Error"}" && $write_err "($msg_type) $(echo $message | strip_esc)"

	_exit "(${alert}$msg_type${nc}) $message \n"
}

# Write error log message and exit
# ###########################################################################
_warn(){
	local msg_type="warn!"
	local write_err="/sbin/log_tool -t2 -u$NAME -p127.0.0.1 -mlocalhost -a"
	local message="$NAME: ${*:-"Unknown Error"}" && $write_err "($msg_type) $(echo $message | strip_esc)"
}

# Find Emby process
_p="MediaBrowser.Server.Mono.exe"
ps ax | grep -v grep | grep "${_p}"
RETVAL=$?
#echo $RETVAL

if [ "$RETVAL" -ne 0 ]; then
	_warn Emby or Qmono seems to be creashed. Trying to restart both services...
	/etc/init.d/Qmono.sh stop
	sync
	sleep 1
	/etc/init.d/Qmono.sh start
	sync
	sleep 1
	/etc/init.d/Emby.sh stop
	sync
	sleep 5
	sync
	/etc/init.d/Emby.sh start
	sync
elif [ "$RETVAL" -eq 0 ]; then
	echo Nothing to be done, works very well
fi

exit 0
 
  • Lubię to
Reakcje: nightcom