aMule Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're back! (IN POG FORM)

Pages: [1] 2

Author Topic: cron, how to start/stop amule?  (Read 9545 times)

xushi

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • http://xushi.co.uk
cron, how to start/stop amule?
« on: July 21, 2006, 10:40:40 PM »

Hi all, long time no see :)

I'm with a new ISP now with this g*y *ss 'fair policy' where i can't use any p2p or download any big file between 6pm to 11pm. So I'm asking for advice on how to sort out a cron job;

I ask, how can i, or is it possible to, create a cron job that will safely stop or kill amule (not amuled or amuleweb, but the normal amule) at 5.50pm, and start it at 11.05pm ? If yes, can you advise me on how the cron job will look like? or how to set it up?

Thanks.
Logged
--
Avtomat KaXushnikova
\/ushi - xushi.co.uk
/\          - socialprotest.com

I am nerdier than 94% of all people. Are you nerdier? Click here to find out!

wardevil

  • Sr. Member
  • ****
  • Karma: -1
  • Offline Offline
  • Posts: 402
Re: cron, how to start/stop amule?
« Reply #1 on: July 22, 2006, 02:17:29 AM »

This next file is what i use for that /etc/rc.d/init.d/amule:
Code: [Select]
#!/bin/sh
#
# Startup script for aMule
#
# chkconfig: 345 80 30
#
# description: Starts aMule with webserver,the service is available \
#              via [URL]http://localhost:4711.[/URL] The GUI runs under \
#              the user account
#
# processname: amule
USER=wardevil
RETVAL=0

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Avoid using root's TMPDIR
unset TMPDIR

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0


[ -f /usr/bin/amule -o -f /usr/local/bin/amule  ] || exit 0

export DISPLAY="localhost:1"

start() {
         printf "Starting aMule : "
         daemon  --user $USER amule  &
         #RETVAL is never returned by aMule?
         RETVAL=0
         echo
         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/amule || \
         RETVAL=1
         return $RETVAL
 }
  stop() {
         printf "Shutting down the aMule daemon: "
         killproc amule
         RETVAL=$?
         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/amule
         echo "Killing webserver!!" && killall amuleweb
         return $RETVAL

 }
restart() {
         $0 stop
         $0 start
 }


case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -f /var/lock/subsys/amule ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart}"
        exit 1
esac

exit $?

Just put this code into /etc/rc.d/init.d and change it to fits your needs in particular the user who is going to run amule.
The crontab entry for your needs:
become root
type crontab -e to edit the root crontab and put this code:
05 11 * * * /etc/rc.d/init.d/amule start
50 5 * * * /etc/rc.d/init.d/amule stop
save it and voilá.
Hope it works for you as it does for me  ;)

Cheers...
Logged
Linux user nº289016 at Linux counter

xushi

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • http://xushi.co.uk
Re: cron, how to start/stop amule?
« Reply #2 on: July 22, 2006, 11:58:28 AM »

Thanks alot! that's a very nice script. Just what i needed.

Will try it now.
Logged
--
Avtomat KaXushnikova
\/ushi - xushi.co.uk
/\          - socialprotest.com

I am nerdier than 94% of all people. Are you nerdier? Click here to find out!

xushi

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • http://xushi.co.uk
Re: cron, how to start/stop amule?
« Reply #3 on: July 22, 2006, 12:08:40 PM »

Hmm, i'm running the script early so i can check if it works or not. I'm not getting any results whatsoever. No output, no errors, nothing starting, and ps -ef shows no processes running. Any chance i can get more output? or find what the problem is ?

All i changed from the above is the USER, and i checked that /usr/bin/amule is correct too.
Logged
--
Avtomat KaXushnikova
\/ushi - xushi.co.uk
/\          - socialprotest.com

I am nerdier than 94% of all people. Are you nerdier? Click here to find out!

JusTiCe8

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 30
    • http://perso.wanadoo.fr/justice8
Re: cron, how to start/stop amule?
« Reply #4 on: July 22, 2006, 02:06:56 PM »

1 run the script by hand
then 2: run it with -x (sh -x script)

Remarks:
cron is not for running gui app, running amuled will be better
cron script in /etc/init.d is not FHS friendly
Logged

wardevil

  • Sr. Member
  • ****
  • Karma: -1
  • Offline Offline
  • Posts: 402
Re: cron, how to start/stop amule?
« Reply #5 on: July 22, 2006, 02:36:40 PM »

You probably need to chmod +x the file to become executable....

Cheers...
Logged
Linux user nº289016 at Linux counter

xushi

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • http://xushi.co.uk
Re: cron, how to start/stop amule?
« Reply #6 on: July 22, 2006, 03:03:41 PM »

Sorry i should have been more clear.

I did run it by hand, but not through sh -x. And yes it is executable. I just tried running it with sh -x amule, and this is the result i got (the user is only for testing at the moment).

Code: [Select]
localhost init.d # sh -x amule
+ USER=root
+ RETVAL=0
+ '[' -f /etc/init.d/functions ']'
+ '[' -f /etc/rc.d/init.d/functions ']'
+ exit 0
localhost init.d #

I don't know what the above is or does, but i just checked /etc/init.d, and it only has famd, fancontrol, and functions.sh

And i'm on gentoo if that helps.

Edit: Also,
./amule: line 28: /etc/sysconfig/network: No such file or directory
./amule: line 31: [: =: unary operator expected

From what i can see, i assume you're on redhat/mandrake? If so, what's /etc/sysconfig/network supposed to represent?
« Last Edit: July 22, 2006, 03:07:55 PM by xushi »
Logged
--
Avtomat KaXushnikova
\/ushi - xushi.co.uk
/\          - socialprotest.com

I am nerdier than 94% of all people. Are you nerdier? Click here to find out!

Gerd78

  • Hero Member
  • *****
  • Karma: 9
  • Offline Offline
  • Posts: 681
Re: cron, how to start/stop amule?
« Reply #7 on: July 22, 2006, 03:32:27 PM »

You have to port the script to your distro. It's distro specific.

From what I understand, it reads the variable NETWORKING from /etc/sysconfig/network in order to determine whether the system has a network interface or not. So you will have to replace this code (lines 28 and 31) by something that fits your distro.

As a quick hack, you could just delete this lines, assuming that your system always has a network interface.
Logged

xushi

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • http://xushi.co.uk
Re: cron, how to start/stop amule?
« Reply #8 on: July 22, 2006, 06:13:53 PM »

Yep, i got it now, and i'll comment it out for now since it's on a machine that's always on and connected.

I think what's left for me is the actual creation of the proccess.. Either 'daemon' (line 40) is redhat/mandrake specific, or i'm missing a package here.

I just looked into a few other init.d processes (like amuled) to see if i can hack something up, but they all look totally different.. Heh, i wondered how hard this will eventually be.

Edit: if i replace that daemon --user ....... line with the following,

 start-stop-daemon --start --exec /usr/bin/amule

I get the following output,

localhost ~ # /etc/init.d/amule start
Starting aMule : Error: Unable to initialize gtk, is DISPLAY set properly?
« Last Edit: July 22, 2006, 06:17:28 PM by xushi »
Logged
--
Avtomat KaXushnikova
\/ushi - xushi.co.uk
/\          - socialprotest.com

I am nerdier than 94% of all people. Are you nerdier? Click here to find out!

Gerd78

  • Hero Member
  • *****
  • Karma: 9
  • Offline Offline
  • Posts: 681
Re: cron, how to start/stop amule?
« Reply #9 on: July 22, 2006, 06:23:26 PM »

amule needs a running X server, you have to use amuled if it must work without X. Replace "amule" by "amuled" in line 40, line 50 any maybe also line 34.

If you want to use amule (the GUI application), an init script is not the right thing for you - instead, add amule to your X session startup script in that case.

Maybe I'll try to hack up a strictly LSB compliant init script later today.
« Last Edit: July 22, 2006, 06:24:42 PM by Gerd78 »
Logged

xushi

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • http://xushi.co.uk
Re: cron, how to start/stop amule?
« Reply #10 on: July 22, 2006, 06:26:39 PM »

Gerd78, Thanks for the reply. No i don't want amuled (unless there's a solution i dont know about). I want amule. Regarding the X session startup, would that still control its startup and shutdown like i originally want ?

Would it be easier/safe if i just run two cron scripts, one having
amule
and the other one
pkill amule

?
Logged
--
Avtomat KaXushnikova
\/ushi - xushi.co.uk
/\          - socialprotest.com

I am nerdier than 94% of all people. Are you nerdier? Click here to find out!

Gerd78

  • Hero Member
  • *****
  • Karma: 9
  • Offline Offline
  • Posts: 681
Re: cron, how to start/stop amule?
« Reply #11 on: July 22, 2006, 06:31:00 PM »

Ah, sorry, I misread everything ;)

The script sets the DISPLAY variable in line 36. Adjust that to something that fits your system.
Logged

xushi

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • http://xushi.co.uk
Re: cron, how to start/stop amule?
« Reply #12 on: July 22, 2006, 06:34:33 PM »

Tried that :) messed it all up...

well i just tried replacing the 1 with 0 or 2
Logged
--
Avtomat KaXushnikova
\/ushi - xushi.co.uk
/\          - socialprotest.com

I am nerdier than 94% of all people. Are you nerdier? Click here to find out!

wardevil

  • Sr. Member
  • ****
  • Karma: -1
  • Offline Offline
  • Posts: 402
Re: cron, how to start/stop amule?
« Reply #13 on: July 22, 2006, 09:36:37 PM »

The DISPLAY variable is set in my script to localhost:1 because i use a vnc xsession wich is the display 1 if you set it to 0(zero) then amule should pop up in the user Xsession normally is the 0.

Can you tell us what kind(distro) of linux are you using?

Cheers....
Logged
Linux user nº289016 at Linux counter

xushi

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • http://xushi.co.uk
Re: cron, how to start/stop amule?
« Reply #14 on: July 22, 2006, 11:43:59 PM »

Yep, I'm on a gentoo system, with 2.6.17, gcc 4.1, and amule 2.1.3.

I've started again with the script from scratch because the old one i killed from editing too much. The things i've changed from the original script above is
USER=root (for now till i fix it)
DISPLAY="localhost:0"

what i need to change now is line 31, because that to me looks more redhat/mandrake than gentoo. I'm trying to replace that line with the following,
Code: [Select]
start-stop-daemon --start --make-pidfile --pidfile /var/run/amule.pid -c root -x /usr/bin/amuleThat's the closest i managed to figure out after reading a few other scripts in there. Now, this allows for my script to run, up to that point, where it still insists that there's no display set properly.
Code: [Select]
localhost ~ # /etc/init.d/amule start
Starting aMule : Error: Unable to initialize gtk, is DISPLAY set properly?

Here's the whole file.

Code: [Select]
#!/bin/sh
#
# Startup script for aMule
#
# chkconfig: 345 80 30
#
# description: Starts aMule with webserver,the service is available \
#              via [URL]http://localhost:4711.[/URL] The GUI runs under \
#              the user account
#
# processname: amule
USER=root
RETVAL=0

# Source function library.
if [ -f /etc/init.d/functions.sh ] ; then
  . /etc/init.d/functions.sh
else
  exit 0
fi

# Avoid using root's TMPDIR
#unset TMPDIR

[ -f /usr/bin/amule -o -f /usr/local/bin/amule  ] || exit 0

export DISPLAY="localhost:0"

start() {
         printf "Starting aMule : "
         #daemon  --user $USER amule  &

         start-stop-daemon --start --make-pidfile --pidfile /var/run/amule.pid -c root -x /usr/bin/amule


         #RETVAL is never returned by aMule?
         RETVAL=0
         echo
         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/amule || \
         RETVAL=1
         return $RETVAL
 }
  stop() {
         printf "Shutting down the aMule daemon: "
         killproc amule
         RETVAL=$?
         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/amule
         echo "Killing webserver!!" && killall amuleweb
         return $RETVAL

 }
restart() {
         $0 stop
         $0 start
 }


case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -f /var/lock/subsys/amule ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart}"
        exit 1
esac

exit $?

Now, after reading the error again, i did an echo $DISPLAY, and i got the result: 0.0. So i tried changing the script's display to localhost:0.0 but still the same error. I did another echo $DISPLAY afterwards to see if anything changed, but it was still the same. So i manually changed it with export $DISPLAY="localhost:0" (putting it like that in the script again too), but still the same error. So i'm confused and i think something's wrong with this display setting as a whole..

Thanks for the help so far.

edit1: if it helps, here's the output of ps -ef for X
Code: [Select]
root      9267  9264  0 Jul21 tty7     00:13:26 /usr/bin/X :0 -audit 0 -auth /var/gdm/:0.Xauth -nolisten tcp vt7
« Last Edit: July 22, 2006, 11:49:05 PM by xushi »
Logged
--
Avtomat KaXushnikova
\/ushi - xushi.co.uk
/\          - socialprotest.com

I am nerdier than 94% of all people. Are you nerdier? Click here to find out!
Pages: [1] 2