aMule Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're back! (IN POG FORM)

Author Topic: restart my amule in command line  (Read 7621 times)

Guest

  • Guest
restart my amule in command line
« on: November 13, 2003, 10:47:39 AM »

how can i restart my amule after crash in command line ?
i would like to do a script who check my amule process.

thanks!!
Logged

Guest

  • Guest
Re: restart my amule in command line
« Reply #1 on: November 13, 2003, 11:35:04 AM »

when i do this command
[code:1]/usr/bin/amule&[/code:1]

a received this error message :
[code:1]
Gtk-WARNING **: cannot open display:
[/code:1]
Logged

deltaHF

  • Evil Admin
  • Former Developer
  • Hero Member
  • *****
  • Karma: 6
  • Offline Offline
  • Posts: 3920
  • .. Legends may sleep, but they never die ..
    • http://www.amule.org
Re: restart my amule in command line
« Reply #2 on: November 13, 2003, 11:57:42 AM »

Quote
Original von Fox



[code:1]#!/bin/bash

f=`basename $0`
pidf=>/tmp/$f.PID>

if [ -e $pidf ] ; then
    echo >allready running>
    exit
else
    pidof -x $0 >$pidf
fi

while netstat -ta | grep 3668 > /dev/null; do
    sleep 10s
done

export DISPLAY=:0.0 && nice -n 6 /usr/local/bin/amule &>/dev/null &

rm $pidf

#EOF
[/code:1]

Guest

  • Guest
Re: restart my amule in command line
« Reply #3 on: November 13, 2003, 12:07:51 PM »

thanks guy for your quickly response !!

 :D  :D  :D  :D
Logged

Guest

  • Guest
Re: restart my amule in command line
« Reply #4 on: November 21, 2003, 11:23:43 AM »

Quote
Original von Fox



[code:1]#!/bin/bash

f=`basename $0`
pidf=>/tmp/$f.PID>

if [ -e $pidf ] ; then
    echo >allready running>
    exit
else
    pidof -x $0 >$pidf
fi

while netstat -ta | grep 3668 > /dev/null; do
    sleep 10s
done

export LANG=C && export LC_ALL=en_EN && export LANG=en_EN && export LC_MESSAGES=C && export DISPLAY=:0.0 && nice -n 6 /usr/local/bin/amule &>/dev/null &

rm $pidf

#EOF
[/code:1]


shouldn't it re-start itself before exiting? :?

grep 3668? why 3668?

anyway.... will using netstat work? i think some connections may be still up for a lot when amule crashes... so... maybe it won't restart.

we could use ps, but sometimes amule freezes...

so i've wrote (still not tested) this:

[code:1]#!/bin/bash

f=`basename $0`
pidf=>/tmp/$f.PID>
exe=>amule>
pre_par=>env LANG=C LC_ALL=en_EN LANG=en_EN LC_MESSAGES=C nice -n 18>

if [ -e $pidf ] ; then
    echo >already running>
    exit
else
    pidof -x $0 >$pidf
fi

while ps aux|grep $exe|grep -v $0|grep -v grep|grep -v >0.0> >/dev/null ; do
    sleep 10s
done

rm $pidf
$pre_par $exe >/dev/null 2>&1 &
$0 &

#EOF[/code:1]
Logged

Lo'oRiS

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 22
    • http://lano.webhop.net
Re: restart my amule in command line
« Reply #5 on: November 21, 2003, 11:24:58 AM »

*ehm* i wasn't logged in. this forum has problem with cookies, doesn't it?
Logged

deltaHF

  • Evil Admin
  • Former Developer
  • Hero Member
  • *****
  • Karma: 6
  • Offline Offline
  • Posts: 3920
  • .. Legends may sleep, but they never die ..
    • http://www.amule.org
Re: restart my amule in command line
« Reply #6 on: November 21, 2003, 11:32:34 AM »

Quote
Original von Lo'oRiS

*ehm* i wasn't logged in. this forum has problem with cookies, doesn't it?


nope Lo'oRiS.. either your browser ..
theres an checkbox, log me on automatically each visit .. maybe u didn't checked it

greets
delta

Lo'oRiS

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 22
    • http://lano.webhop.net
Re: restart my amule in command line
« Reply #7 on: November 23, 2003, 05:25:40 AM »

well... the script i tried to do contains some mistakes... i'll try to correct it ;)
Logged

knecht666

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 24
    • http://knecht.homelinux.net
because of script to check amule
« Reply #8 on: November 26, 2003, 08:32:13 AM »

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
Logged
---------------------------------------
fiat veritas pereat mundus