2013/02/19

How to setup a fail-proof aMule in the pandaboard (or RPi)

As a final post on my series of posts about how to get a low-cost and low-energy consumption HTPC via a combination of pandaboard and RPi, I'll talk about how to setup the ed2k download client aMule (the Linux port of the famous Emule) so you can leave it there forever, making sure it is fail-proof in the process, thanks to Monit.

aMule


The reason for me to choose aMule as my P2P client is mostly because I never liked torrents. This is just a personal opinion, but I've always have the impression that torrent users don't share as much as "good-old-donkey" ones. Besides, I like watching old stuff, something very hard to find in torrent format. Having said that, let's go down to installing and configuring aMule in your download server.

You'll end up in love with your mule like this girl, serious

In my case, that was a pandaboard set up as depicted in my previous post. I've alway been using eMule & aMule downloading the client and using it directly in the same machine. While this works sweet in normal Linux distributions, I've found it really hard in my panda, due basically to two reasons: First, I'm accesing my X session through VNC, and it is slow. Not bad for normal surfing and just do casual work, but it is uncomfortable after some time. And second, and this one is really frustrating, never managed to include e2dk links clicked in any Web browser automatically to aMule.

This may look like I enjoy whining about minor issues, but I just can't bare having to copy & paste e2dk links from one place to another. Maybe if I didn't know the feature existed, I wouldn't mind, but since I do, I just can't go on it without it. The reason for this is still unknown for me. I've searched for days and still can't find a definitve answer, but, for some reason, my Firefox version is not able to interpret e2dk links. Don't think is a Firefox issue really, I've also tried Midori, Chromium and even Konqueror, to no avail. All failed miserably.

Tried all sort of supposed solutions, like using ML Donkey Protocol Handler Firefox plugin, or the Chromium one, no luck. Also tried to set up some values in Firefox config, but did not work either. I was about to give up when I just realized (yeah, blame me I was too slow on this) that why not trying to use aMule daemon so I could use aMule without having to login and interact directly with the pandaboard? There are a lot of advantages using this approach, but the most interesting for me are:

  • You can manage your downloads from any other place with the aMuleWeb front-end, or the aMuleGUI if you prefer
  • No need to physically or remotely connect to the machine. This is a big plus for me, I just didn't realize how comfy it is to access my downloads from a web browser, no ssh-ing, no vnc-ing, just a plain URL.
  •  You don't even need to have a graphical interface at all in the machine running aMule daemon. There are some examples of people deploying aMule in Linux capable routers.
So there are basically two options:  get aMule daemon and aMule Web from official repositories or download sources and compile. First option is quicker and easier, second will give you more control but its obviously more work. Unless you need some specific functionality, the provided packages in repositories are more than enough. This is the approach I used too. Let's go to it:
  • Download and install amuled
  • 
    $ sudo apt-get install amule-daemon

  • This will install amuled and amuleweb. Now run amuled for the first time in orden to create the configuration file.
    
    $ amuled

  • You'll get an error about accepting External Connections. To fix it, edit the newly created configuration file which is located in your /home folder
  • 
    $ vi /home/your_user/.aMule/amule.conf
    

  • Modify the value of AcceptExternalConnections to 1
  • 
    AcceptExternalConnections=1

  • Now we need to generate a password for the ECPassword, field
  • 
    echo -n yourpasswordhere | md5sum | cut -d ' ' -f 1

  • Copy the generated password and paste it in the ECPassword field
  • 
    ECPassword=your_password_md5hash

  • Now you should be able to run amule daemon
  • 
    sudo service amule-daemon start

aMuleWeb 

In order to be able to access our amule-daemon  and send ed2k links, we're gonna use amuleWeb, a web-based front-end application to manage aMule that works pretty well. aMuleWeb is already installed if you followed the instructions above, but must be configured:

  • Create the configuration file for amuleWeb. Don't worry about the password fields, we'll fix that later. This will generate a remote.conf file in the same place as the amule.conf one. You can also specify other important things in this file, like listening port, server name, etc. I left the ones by default, but feel free to modify them to suit your needs.
  • 
    $ amuleweb --write-config --host=localhost --password=password --admin-pass=anotherpassword

  • The password you entered previously in the ECPassword field and the AdminPassword field in remote.con MUST be the same. So just copy and paste
  • 
    $ vi /home/your_user/.aMule/remote.conf

  • Remember, same password
  • 
    $ AdminPassword=your_password_md5hash
In order to run amuled + amuleWeb as a service on startup, you must follow these steps:
  • Try to add amuled to startup scripts.
  • 
    $ sudo /etc/init.d/amule-daemon

  • An ERROR will show up:
  • 
    $ * Not starting aMule daemon, AMULED_USER not set in /etc/default/amule-daemon.

  • To fix it, edit the file /etc/default/amule-daemon and type your user in the AMULED_USER field
  • 
    $ sudo vi /etc/default/amule-daemon
    $ AMULED_USER="your_user"
    

  • Go back to amule.conf and specify that amuleWeb must be started along amuled. Go to the WebServer section and change the Enabled field to 1 and type the password you generated earlier
  • 
    $ vi /home/your_user/.aMule/amule.conf
    $ Enabled=1
    Template=default
    Password=your_password_md5hash
    

  • Reboot and check that amuled and amuleWeb are started and reachable
  • 
    $ sudo reboot

aMuleWeb up&running
  • Lastly, if you haven't done already, open required ports in your router for amule-daemon and amuleWeb. Default ones are 4672 TPC, 4662 UDP and 4711 TCP.

monit

Last step involves installing monit to supervise (among many other things) that amule daemon is up and running. Monit is a great tool used to supervise all kind of things, but mostly, running services that could be critical in a server (like Apache, MySQL, PostgreSQL, FTP, whatever...) or CPU usage, RAM, etc. You can define alarms or thresholds and monit will check those rules and do whatever you specify when something happens, normally restarting the service.

One monit to rule them all
In our case, we'll use monit to watch if amule-daemon is down and if so, log a message and restart the amule-daemon service.

  • Install monit
  • 
    $ sudo apt-get install monit

  • Start configuring monit, the configuration file is /etc/monit/monitrc
  • 
    $ sudo vi /etc/monit/monitrc

  • Change the interval that monit uses to check for services. Default value is 2 minutes
  • 
    $   set daemon 120            # check services at 2-minute intervals
    

  • Specify log file
  • 
    $   set logfile /var/log/monit.log
    

  • If you want to use the embedded server that monit has to check for services, uncomment the following line
  • 
    $ set httpd port 2812
    use address localhost  # only accept connection from localhost
    allow localhost        # allow localhost to connect to the server and
    allow admin:your_pass_here      # require user 'admin' with password 'monit'

  • Add a new entry in the services section for our Amule daemon.
  • 
    $ #Included for amule-daemon
    check process aMule with pidfile /home/your_user/.aMule/muleLock
    start program = "/etc/init.d/amule-daemon start"
    stop program  = "/etc/init.d/amule-daemon stop"
    if failed host localhost port 4711 then restart

  • You will obviously need to change the port number if you are not using default one. We're only restarting amule daemon if monit notices that is down for whatever the reason. Restart monit.
  • 
    $ sudo service monit restart

That's it! You should have by now a working amule daemon with amuleWeb under supervision by monit and almost be as happy as me with this setup :).

No comments:

Post a Comment