но не совсем понятен алгоритм их работы:
1.
This one will actually try to connect to amule to check that it's alive.
It's supposed to restart amule even when it did not crash, but frozen. Which happens
from time to time.
Код: Выделить всё
#!/bin/sh # aMule watchdog # Checks on aMule every 5 (configurable parameter) minutes # and restarts it if aMule does not respond. # Requires Netcat # # Created by Demiurg - demiurg@tau<.>ac<.>il (Alexander Sirotkin) # Have fun. MULENAME=amule MULE=`which ${MULENAME}` NC=`which nc` TCPPORT=4642 SLEEP=300 test -e ${MULE} || (echo "${MULE} not found. Dying"; exit 1) test -e ${NC} || (echo "Netcat not found. Dying"; exit 1) FIRSTLOOP=1 while true; do # echo "Waiting" test ${FIRSTLOOP} || sleep ${SLEEP} unset FIRSTLOOP # echo "Checking" nc localhost ${TCPPORT} < /dev/null && continue echo "Restarting" date killall -9 ${MULENAME} sleep 1 ${MULE} & # echo "Running" done
2.
ehm... I've been hacking on the script, cuz I needed one to auto-start on boot. I've put it in KDE's autostart map (but I guess gnome and other wm's have similar places or functions). It'll start ?mule with a set priority (so it wont stall the system if its very busy or hangs) after a certain time (so the system can boot first, start all services etc - and then amule).
although this was based upon another script posted above, and on a small script I wrote earlier, this is actually the biggest script I've ever hacked upon, so pls check me and don't bite if it doesnt work ;-)
this is the script:
Код: Выделить всё
#!/bin/bash # welcome # aMule/xMule startup script - for putting in ~/.kde/Autostart. # starts aMule/Xmule and continually checks if it's running (or stalled) - if things are wrong, it restarts aMule/xMule. # by Superstoned,- I actually just extended script the by Demiurg. # Requires Netcat. # first some checkups and settings # priority can be set with nice. higher nice is lower priority. you can't set nice lower than 0 unless you're root. dont set higher than 13. # tcpport must be same as in amule/xmule (see settings of the mule) # sleep sets interval in seconds for the watchdog part (which checks if the mule is running). dont set it too low because that's slow. MULENAME=amule MULE=`which ${MULENAME}` NC=`which nc` NICE=5 TCPPORT=4662 SLEEP=300 # test if amule/xmule does exist, and if nc does exist. test -e ${MULE} || (echo "${MULE} not found. Dying"; exit 1) test -e ${NC} || (echo "Netcat not found. Dying"; exit 1) #wait some time, until most other programs have started - this way it doesnt slow down startup. echo echo "Welcome to the aMule/xMule start & control script." echo "First we wait 30 seconds to ensure we are not slowing down other starting programs at boot." echo sleep 35 #start amule, with a higher nice (eg lower priority) so it doesnt slow down the system, even if it goes into loop (sucking much cpu). echo "Ok, now we will start ${MULE}" nice -n ${NICE} ${MULE} & # aMule/xmule original watchdog # Checks on aMule every 5 (configurable parameter) minutes # and restarts it if aMule does not respond. # Requires Netcat # # Created by Demiurg - demiurg@tau<.>ac<.>il (Alexander Sirotkin) # Have fun. # wait a min before attempting to check - amule must be ready starting and connecting to a server first. echo "while the mule is starting up, we wait another minute to give it some time to get ready for the first checkup;-)" sleep 60 echo "Ok, now we will start the watchdog and to the first check." FIRSTLOOP=1 while true; do echo "Waiting" test ${FIRSTLOOP} || sleep ${SLEEP} unset FIRSTLOOP echo "Checking if ${MULE} is running and not stalled" nc localhost ${TCPPORT} < /dev/null && continue echo "Restarting ${MULE}" date killall -9 ${MULENAME} sleep 2 nice -n ${NICE} ${MULE} & echo "${MULE} is running again." done
что непонятно:
Netcat - кто это такой и какие функции в скрипте выполняет
test - какие действия выполняет?
killall - скрипт (как и приложение) запускается от обычного пользователя. как сделать так, чтобы эта команда могла выполняться и не под рутом? (или скрипт пускать от рута а прогу запускать как su doka -c "amule" ??)
какое значение имеет использование изменения приоритета процесса (nice) во втором скрипте ?
--------------------------------------
взято отсюда