Jump to content

Mailer script and code :)


TvL

Recommended Posts

Hi community,

I really like utserver! Used azureus in the past...

I did like the Status Notification Emailer from azureus and tried to recreate it using the finish_cmd and state_cmd feature.

So I created my own mailer script in Ruby and thought some of you might like it as well.

Here is my utserver config: utserver_config.png

Yes, the first argument really are 2 single quotes.

I am using version utorrent-server-3.0-25053.tar.gz and according to my logfile the first argument is not being sent to my script.

I am using the webui version from 2011-05-28 (found in this post: http://forum.utorrent.com/viewtopic.php?id=58156)

The mailer script is written in Ruby and therefore you need ruby:

apt-get install ruby1.9.1 rubygems1.9.1
gem1.9.1 install mail --no-ri --no-rdoc

So far the dependencies, now the script (sendmail.rb):

#!/usr/bin/ruby1.9.1

require 'mail'
require 'logger'

$log = Logger.new('sendmail.log', 4, 1024*1024) # rotate after 1MB and keep 4 copies
$log.datetime_format = '%Y-%m-%d %H:%M:%S'
$log.level = Logger::DEBUG

if ARGV.length < 3
$log.fatal "Not enough arguments: #{ARGV.inspect}"
exit 1
end


pstate = ARGV.shift.to_i
cstate = ARGV.shift.to_i
title = ARGV.join(' ')

exit(0) if pstate == cstate

pindex = pstate - 1
cindex = cstate - 1

states = Array.new
states << 'error'
states << 'checked'
states << 'paused'
states << 'super seeding'
states << 'seeding'
states << 'downloading'
states << 'super seeding (forced)'
states << 'seeding (forced)'
states << 'downloading (forced)'
states << 'queued seed'
states << 'finished'
states << 'queued'
states << 'stopped'

$log.info "title: #{title} went from: #{states[pindex]} to #{states[cindex]}"

Mail.defaults do
delivery_method :smtp, {
:address => '127.0.0.1',
:port => 25,
:enable_starttls_auto => false
}
end

mail = Mail.new do
to "tvl@mailinator.net"
from "utorrent@mailinator.net"
subject "Status change for '#{title}'"
html_part do
content_type 'text/html; charset=UTF-8'
body %Q|
<HTML>
<HEAD>
<TITLE>
Utorrent download status notification
</TITLE>
</HEAD>
<BODY>
<H1>Utorrent download status notification</H1>
Download '#{title}' has changed state from #{states[pindex]} to #{states[cindex]}
</BODY>
</HTML>|
end
end

mail.deliver!

Don't forget to

chmod 755 sendmail.rb

Adjustments according to your need:

- mailto: currently set to tvl@mailinator.net

- mailfrom: currently set to utorrent@mailinator.net

- smtphost: 127.0.0.1 port 25 (change that to the mailserver of your ISP or to your own mailserver)

- logfile: sendmail.log

- ruby interpreter: /usr/bin/ruby1.9.1

I hope you like this :)

EDIT: It seems to me that utserver does not correctly reap it's children. That's why the sendmail script remains as zombie after it has been run. In order to get rid of zombies, the utserver needs to be restarted. It's not a showstopper for me and there's a post about it:

http://forum.utorrent.com/viewtopic.php?id=89600

Link to comment
Share on other sites

It seems to me that utserver does not correctly reap it's children. That's why the sendmail script remains as zombie after it has been run. In order to get rid of zombies, the utserver needs to be restarted. It's not a showstopper for me and there's a post about it:

http://forum.utorrent.com/viewtopic.php?id=89600

Thanks for the second report on this issue. I have not been able to reproduce it. My tests never show zombies being created. Each child process created for state change events is put in a new session via setsid(), so there should be no need for the utserver process to wait on those child processes. Can you tell me more about the environment in which you run uTorrent Server (32-bit or 64-bit, etc.)?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...