I have got a script from xMule.org and modified it for my own aMule.
[code:1]
#!/bin/sh
#
# ****************************
# *** aMule restart script ***
# ****************************
#
# This script check if aMule is not running and restart it
#
#
# Copyright 2003 Neo_CH
# e-mail:
neo@networld.com# Distributed under the terms of the GNU General Public License v2
#
# Functions 'ebegin' and 'eend' copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# Modified by Neo_CH
#
# Last modification: 30th August 2003
# Last modification: changes for aMule useage, Sebastian Nov '03 (
human.waste@web.de)
#
########################################
#
# CONFIGURATION
#
########################################
#
# Program name and full binary path
#
PROGRAM=amule
BIN=/usr/local/bin/amule
#
# TCP Ports
#
# Ok, when aMule crash and you restart it too quickly you have
# a LOWID (and this is not good!!!) because the port is not well closed.
# A good solution is to change the TCP port.
# Here you can specify 2 TCP Ports and the script will switch between them
# (remember to configure your firewall to open and forward both ports)
#
TCPPORT1=4001
TCPPORT2=4010
#
# aMule configuration files
#
CONF=/home/myself/.eMule
BACKUP=/home/myself/.eMule.BAK
#
# VNC configuration
#
# VNCDISPLAY: server display number
#
# If you set VNCDISPLAY then aMule will try to connect on the selected server
# display. When not set it connect to :0 (default X display). This var is
# only useful when you use VNC or X on another display.
# If you don't know what VNC is, you probably don't need it, so you can
# safely comment the following line!
#
#VNCDISPLAY=1.0
#
# E-mail
#
# If you want to receive a mail notification after
# the script restarted aMule, please insert a valid
# email address
#
#MAILTO=>youremail@here.com>
#
#
# END CONFIGURATION
#
########################################
#
# Set default variables
#
set_vars() {
# Colors
GOOD=$'\e[32;01m'
BAD=$'\e[31;01m'
NORMAL=$'\e[0m'
BRACKET=$'\e[34;01m'
# Returns tty cols
getcols() {
echo >$2>
}
# Set number of cols et end cols
COLS=>`stty size 2> /dev/null`>
COLS=>`getcols ${COLS}`>
COLS=$((${COLS} - 7))
ENDCOL=$'\e[A\e['${COLS}'G'
# Error
ERROR=1
# Temp config file
TEMP=/home/myself/.eMule.TEMP
}
#
# show a message indicating the start of a process
#
ebegin() {
echo -e > ${GOOD}*${NORMAL} ${*}...>
return 0
}
#
# void eend(int error, char* errstr)
#
# indicate the completion of process if error, show errstr
#
eend() {
local retval=
if [ >$#> -eq 0 ] || ([ -n >$1> ] && [ >$1> -eq 0 ])
then
echo -e >${ENDCOL} ${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}>
else
retval=>$1>
if [ >$#> -ge 2 ]
then
shift
echo -e > ${BAD}*${NORMAL} ${*}>
fi
echo -e >${ENDCOL} ${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}>
# extra spacing makes it easier to read
echo
return ${retval}
fi
return 0
}
#
# Check presence of configuration file .eMule
#
check_config () {
ebegin >Searching for aMule configuration file in user directory>
if [ -e ${CONF} ]; then
eend
else
eend ${ERROR} >aMule configuration file (${CONF}) not Found.\n You must first start and configure aMule manually with this user.\n Unable to continue.>
exit 1
fi
}
#
# Set DISPLAY for VNC
#
#set_vnc () {
# if [ ${VNCDISPLAY} ]; then
# ebegin >Setting up DISPLAY (required for VNC)>
# export DISPLAY=:${VNCDISPLAY}
# eend
# fi
#}
#
# Get aMule's PID
#
function getpid() {
pid=`ps aux | grep amule | grep >${USER}> | grep -v >grep> | grep -v ${0#./} | awk '{print $2}'`
}
#
# Return the CPU time the instance has consumed so far
#
function gettime() {
ps aux | grep >${pid}> | grep -v >grep> | awk '{print $10}'
}
#
# Check if program is running or has gone stale
#
check_program () {
ebegin >Checking if ${PROGRAM} is running>
PS=`ps x`
#if echo ${PS} | grep ${BIN} > /dev/null; then
if echo ${PS} | grep ${PROGRAM} > /dev/null; then
# Program is running
eend ${ERROR} >${PROGRAM} is running. You don't need to restart it>
ebegin >Checking if ${PROGRAM} is alive (this may take some time)>
getpid
TIME1=`gettime`
sleep 45
TIME2=`gettime`
## Kill stale instance; checkrunning() will take care of the relaunch.
if [[ >${TIME1}> != >${TIME2}> ]]; then
# aMule ALIVE
eend
exit 0
else
# aMule has gone STALE
killall ${PROGRAM}
STALE=> (aMule has gone stale)>
eend ${ERROR} >${PROGRAM} has gone stale. Killing...>
fi
else
echo -e > ${PROGRAM} is not running.>
eend
fi
}
#
# Get current TCP Port & set new TCP Port
#
get_ports () {
ebegin >Loading current TCP Port>
ISTCPPORT1=`grep Port=${TCPPORT1} ${CONF} | awk -F'=' '{print $2}' | head -1`
ISTCPPORT2=`grep Port=${TCPPORT2} ${CONF} | awk -F'=' '{print $2}' | head -1`
if ! [ -z ${ISTCPPORT1} ]; then
# TCPPORT1 is the current TCP PORT configuration
CURPORT=${TCPPORT1}
NEWPORT=${TCPPORT2}
eend
elif ! [ -z ${ISTCPPORT2} ]; then
# TCPPORT2 is the current TCP PORT configuration
CURPORT=${TCPPORT2}
NEWPORT=${TCPPORT1}
eend
else
eend ${ERROR} >Neither TCP Port ${TCPPORT1} nor TCP Port ${TCPPORT2} found in configuration file.\n Please configure this script or set TCP Port to ${TCPPORT1} or ${TCPPORT2} in your amule.>
exit 1
fi
}
#
# Write new configuration file
#
write_conf () {
ebegin >Writing new configuration file>
sed -e >s/Port=${CURPORT}/Port=${NEWPORT}/> ${CONF} > ${TEMP}
eend
}
#
# Check if new configuration file have the right TCP Port and
# write new configuration file
#
check_conf () {
ebegin >Checking new configuration>
ISNEWTCPPORT=`grep Port=${NEWTCPPORT} ${TEMP} | awk -F'=' '{print $2}' | head -1`
if ! [ -z ${ISNEWTCPPORT} ]; then
# Configuration is ok
eend
ebegin >Creating backup>
cp -f ${CONF} ${BACKUP}
eend
ebegin >Writing new configuration>
mv -f ${TEMP} ${CONF}
eend
else
eend ${ERROR} >Error in new configuration. Unable to continue.>
exit 1
fi
}
#
# Restart the program
#
restart_program () {
cd /home/myself
./amule.sh
#ebegin >Restarting ${PROGRAM}>
#${BIN} & >/dev/null
# we remove the set of DISPLAY
#export DISPLAY=>>
#eend
}
#
# Send a mail notification
#
#send_mail () {
#if [ ${MAILTO} ]; then
# ebegin >Sending a mail to ${MAILTO}>
# echo >aMule restarted automatically by Neo_CH script on `date`${STALE}.> | mail -s >aMule restarted on `date`> ${MAILTO}
# eend
#fi
#}
#
# aMule-check script
#
echo >aMule-check script by Neo_CH.aMule modified by Sebastian>
echo >Please report bugs at neo@networld.com>
echo >Distributed under the terms of the GNU General Public License v2.>
echo
set_vars
#set_vnc
check_config
check_program
get_ports
write_conf
check_conf
# This new check is needed to prevent 2 sessions of amule
check_program
restart_program
#send_mail
exit 0
[/code:1]
I run this every hour with a cronjob (crontab --help for info)
and it do fine . . . (take a look at the path for amule in the script)
and if your system language isn't english you have to change "Restart the Programm" commands !!!!
Hope this can help
Sebastian , Germany