aMule Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're back! (IN POG FORM)

Author Topic: aMule crash watcher: automatic restart  (Read 11621 times)

thepolish

  • Hero Member
  • *****
  • Karma: 2
  • Offline Offline
  • Posts: 896
aMule crash watcher: automatic restart
« on: January 02, 2004, 11:59:22 AM »

Hello,

If u are not always in front of screen, u can use the ps-watcher program to restart automaticaly aMule when it crashes:

http://ps-watcher.sourceforge.net/

make a config file like ~/.pswatcher like this:

[code:1]# Restart aMule if it has crashed
[amule]
occurs = none
action = /opt/amule/bin/amule >/dev/tty10 2>/dev/tty11 &

# If aMule is running, do some backup
[/opt/amule/bin/amule]
occurs = first
action =<mkdir -p ~/.aMule/backup/met
cp -f ~/.aMule/Temp/*.met ~/.aMule/backup/met/
cp -f client.met known.met server.met  ~/.aMule/backup/
cp -f adresses.dat shareddir.dat ipfilter.dat amfriends.dat ~/.aMule/backup/
EOT[/code:1]

Run

ps-watcher --config ~/.pswatcher --daemon

after starting aMule

Or, u can also create a user crontab like this:

[code:1]00 * * * * /opt/pswatcher/bin/ps-watcher --config ~/.pswatcher --nodaemon --sleep -1
15 * * * * /opt/pswatcher/bin/ps-watcher --config ~/.pswatcher --nodaemon --sleep -1
30 * * * * /opt/pswatcher/bin/ps-watcher --config ~/.pswatcher --nodaemon --sleep -1
45 * * * * /opt/pswatcher/bin/ps-watcher --config ~/.pswatcher --nodaemon --sleep -1[/code:1]
You can also complicate the thing with counting number of craches ...

And you will have a nice crash watcher like in windows mods like eChanblard

the polish
Logged
Only after the last tree has been cut down
Only after the last river has been poisoned
Only after the last fish has been caught
Only then you will find out that money cannot be eaten
(Cree Prophecy)

thepolish

  • Hero Member
  • *****
  • Karma: 2
  • Offline Offline
  • Posts: 896
Re: aMule crash watcher: automatic restart
« Reply #1 on: January 02, 2004, 06:42:15 PM »

Add-on:

Depending on your distrib, you would have to set the display for X jobs starting from cron (debian for instance) if u dont want to have CANNOT OPEN DISPLAY:

[code:1]00 * * * * env DISLPAY=:0 /opt/pswatcher/bin/ps-watcher --config ~/.pswatcher --nodaemon --sleep -1
15 * * * * env  DISPLAY=:0 /opt/pswatcher/bin/ps-watcher --config ~/.pswatcher --nodaemon --sleep -1
37 * * * * env DISPLAY=:0 /opt/pswatcher/bin/ps-watcher --config ~/.pswatcher --nodaemon --sleep -1
45 * * * * env DISPLAY=:0 /opt/pswatcher/bin/ps-watcher --config ~/.pswatcher --nodaemon --sleep -1
[/code:1]

the polish
Logged
Only after the last tree has been cut down
Only after the last river has been poisoned
Only after the last fish has been caught
Only then you will find out that money cannot be eaten
(Cree Prophecy)

Rocco83

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 7
Re: aMule crash watcher: automatic restart
« Reply #2 on: January 04, 2004, 04:54:10 PM »

i prefer a simplest way.

$ while [ 1==1 ] ; do amule ; done

it's an endless loop... when amule crash, it restart.
usually i ran it over screen (man), but you can also use it in background
$ `while [ 1==1 ] ; do amule ; done` &

and with a DISPLAY=ip:screennumber (ex: DISPLAY=unix:0 `while [ 1==1 ] ; do amule ; done` &) is a lot funny :)

bye
Logged
to bodly go where no man has gone before.

thepolish

  • Hero Member
  • *****
  • Karma: 2
  • Offline Offline
  • Posts: 896
Re: aMule crash watcher: automatic restart
« Reply #3 on: January 04, 2004, 11:19:49 PM »

Yes, it is really the simpliest way ...

But as i ve experimented the lost of part.met (and so the associated dl)  when crashes are not du to amule, but power failures, i use principaly this script to backup amule files and part.met.

the polish

# If aMule is running, do some backup
[amule$]
occurs = first
action =<echo > /dev/tty10
echo "***** THIS A PSWATCHER JOB *****" > /dev/tty10
echo `date` > /dev/tty10
echo "aMule is running, doing backup tasks" >/dev/tty10
sync
cd ~/.aMule
mkdir -p backup/met
echo "Saving Temp/*.met -> backup/" >/dev/tty10
cp -f Temp/*.met backup/met/
cp -vf clients.met known.met server.met emfriends.met backup/ >/dev/tty10
cp -vf adresses.dat shareddir.dat ipfilter.dat backup/ >/dev/tty10
sync
echo "********************************" > /dev/tty10
echo > /dev/tty10
EOT
Logged
Only after the last tree has been cut down
Only after the last river has been poisoned
Only after the last fish has been caught
Only then you will find out that money cannot be eaten
(Cree Prophecy)

keevitaja

  • Newbie
  • Karma: 0
  • Offline Offline
  • Posts: 3
Re: aMule crash watcher: automatic restart
« Reply #4 on: February 15, 2004, 09:28:58 PM »

this is working with vnc. if you want to use crontab you must link some vnc commands (vncpasswd etc) to the /usr/bin  or modify crontabs PATH for crontab to find them.
Quote
#!/bin/bash

export DISPLAY=:1
export LD_LIBRARY_PATH=/usr/lib/wxPython/lib
export USER=my_user

CONF=${HOME}/.eMule
CONF_TMP=${HOME}/.eMule.tmp
XMULE_PATH=${HOME}/.xMule
XMULE_BIN=/usr/local/bin/amule
VNC_PATH=${HOME}/.vnc
VNCSERVER_BIN=/usr/X11R6/bin/vncserver
PIDOF_BIN=/sbin/pidof
FUSER_BIN=/sbin/fuser
TCP_PORT1=4662
TCP_PORT2=4762
UDP_PORT=4672
OUTPUT=/dev/null

#kontrollime, kas vncserver on yleval
if ${PIDOF_BIN} Xvnc > ${OUTPUT}
    then :
#juhul kui mitte, siis k2ivitame
else
   #kustutame vanad failid
   rm -rf ${VNC_PATH}/${HOSTNAME}:1.pid
   rm -rf /tmp/.X1-lock
   rm -rf /tmp/.X11-unix/X1

    ${VNCSERVER_BIN} :1 -geometry 980x670 -localhost -depth 16 2> ${OUTPUT}
   #lisame ka logi sissekande
    d=`date`
    echo "${d}: vnc server started" >> ${XMULE_PATH}/scripti_logi.log
fi
#kontrollime, kas xmule on yleval
if ${PIDOF_BIN} amule > ${OUTPUT}
    then exit
#juhul kui mitte, siis k2ivitame
else
   #kontrollime millist porti xmule viimati kasutas
    CUR_PORT1=`grep Port=${TCP_PORT1} ${CONF} | awk -F'=' '{print $2}' | head -1`
    CUR_PORT2=`grep Port=${TCP_PORT2} ${CONF} | awk -F'=' '{print $2}' | head -1`

   #muudame pordi
   if ! [ -z ${CUR_PORT1} ]; then
      OLD_PORT=${TCP_PORT1}
      NEW_PORT=${TCP_PORT2}
   elif ! [ -z ${CUR_PORT2} ]; then
      OLD_PORT=${TCP_PORT2}
      NEW_PORT=${TCP_PORT1}
   else
      exit
   fi  

   #muudame confofaili
   sed -e "s/Port=${OLD_PORT}/Port=${NEW_PORT}/" ${CONF} > ${CONF_TMP}
   
   #kontrollime kas 6nnestus
   if grep ${NEW_PORT} ${CONF_TMP} > ${OUTPUT}; then
      mv -f ${CONF_TMP} ${CONF}
   fi

   #yritame tappa protsessid, mis kasutavad porte
   ${FUSER_BIN} -vk ${NEW_PORT}/tcp
   ${FUSER_BIN} -vk ${UDP_PORT}/udp

   #kui k6ik on ok, siis l6puks k2ivitame xmule
    ${XMULE_BIN} 2> ${OUTPUT} > ${OUTPUT} &
    d=`date`
    echo "${d}: lmule started" >> ${XMULE_PATH}/scripti_logi.log
fi
exit
Logged