Sunday 5 February 2012

rTorrent & Screen Upstart 1.3 (Updated)

Upstart script for rTorrent for Upstart 1.3 (and older?)
Upstart 1.4 supports setting uid and gid so we can use that instead of start-stop-daemon or sudo or su to correctly track the process id using expect daemon and tell it to send the proper kill signal (for rTorrent is SIGINT)

So what do we do for Upstart 1.3?
Well, we're forced to use either start-stop-daemon or sudo or su to start a process as another user. Even with expect daemon it always tracks the wrong process id and in my case causes shutdown to freeze as it tries to kill a process that doesn't exist.

My solution is to start a job that cleanly kills (by sending a SIGINT) rTorrent when you'd expect it to. In my case runlevels [016]

#rtorrent-start.conf

description     "rTorrent - ncurses BitTorrent client based on LibTorrent"

start on (local-filesystems and net-device-up IFACE=eth0 and runlevel [2345])
stop on runlevel [016]

console none

exec start-stop-daemon --start -c <user> --exec /usr/bin/screen -- -dmUS rtorrent /usr/bin/rtorrent
##

#rtorrent-stop.conf

description "Correctly ensure rTorrent shuts down gracefully"

start on runlevel [016]

console none
task

script
 if [ -f /home/ <user> /.rtorrent/rtorrent.lock ]; then
   kill -s 2 $(cat /home/ <user> /.rtorrent/rtorrent.lock | awk -F+ '{ print $2 }')
   rm -f /home/ <user> /.rtorrent/rpc.socket
 fi
end script
##

.lock file cleaning should be left for rTorrent as it usually removes it when correctly killed. If an old .lock file remains its a clear indicator that rTorrent did not correctly shutdown.
Won't hurt to remove the socket file though (if you use it). Saves adding it in .rtorrent.rc

UPDATE:
I've recently had some issues with UDP trackers and DHT causing some torrents to not start downloading at all even when the swarm is healthy. I've since given up on rTorrent and have started using Deluge, which is nice and compact with a sweet web gui.

Thursday 2 February 2012

Xorg modelines for LG 32LC46

Xorg modelines for LG 32LC46 as reported by its EDID because Intel can't parse the data completely (so it misses some refresh rates and resolutions). Had to plug this in to my old HTPC with an Nvidia ION to get this (with startx -- -logverbose 6)

HorizSync 28.0 - 67.0
VertRefesh 50.0 - 75.0

Modeline "1920x1080@60p" 148.50 1920 2008 2052 2200 1080 1084 1089 1125 +hsync +vsync
Modeline "1920x1080@50p" 148.50 1920 2448 2492 2640 1080 1084 1089 1125 +hsync +vsync
Modeline "1920x1080@30p" 89.01 1920 2448 2492 2640 1080 1084 1089 1125 +hsync +vsync
Modeline "1920x1080@25p" 74.25 1920 2448 2492 2640 1080 1084 1089 1125 +hsync +vsync
Modeline "1920x1080@24p" 74.16 1920 2558 2602 2750 1080 1084 1089 1125 +hsync +vsync
Modeline "1360x768@60p" 84.75 1360 1432 1568 1776 768 771 776 798 -hsync +vsync
Modeline "1280x768@60p" 80.14 1280 1344 1472 1664 768 771 778 798 -hsync -vsync
Modeline "1280x720@60p" 74.25 1280 1390 1430 1650 720 725 730 750 +hsync +vsync
Modeline "1280x720@50p" 74.25 1280 1720 1760 1980 720 725 730 750 +hsync +vsync
Modeline "1024x768@75p" 78.75 1024 1040 1136 1312 768 769 772 800 +hsync +vsync
Modeline "1024x768@70p" 75.00 1024 1048 1184 1328 768 771 777 806 -hsync -vsync
Modeline "1024x768@60p" 65.00 1024 1048 1184 1344 768 771 777 806 -hsync -vsync
Modeline "800x600@75p" 49.50 800 816 896 1056 600 601 604 625 +hsync +vsync
Modeline "800x600@60p" 40.00 800 840 968 1056 600 601 605 628 +hsync +vsync
Modeline "720x576@50p" 27.00 720 732 796 864 576 581 586 625 -hsync -vsync
Modeline "720x480@60p" 27.00 720 736 798 858 480 489 495 525 -hsync -vsync
Modeline "640x480@75p" 31.50 640 656 720 840 480 481 484 500 -hsync -vsync
Modeline "640x480@60p" 25.17 640 656 752 800 480 490 492 525 -hsync -vsync

These caused issues
Modeline "1920x1080@60i" 74.18 1920 2008 2052 2200 1080 1084 1094 1124 +hsync +vsync Interlace
Modeline "1920x1080@50i" 74.25 1920 2448 2492 2640 1080 1084 1094 1124 +hsync +vsync Interlace

EDID in hex

00ffffffffffff001e6db77576230400
0911010380462778ead9b0a357499c25
11494ba56e00314045406140d1c00101
010101010101023a801871382d40582c
4500c48e2100001e1b2150a051001e30
48883500bc862100001c000000fc0033
324c433436200a2020202020000000fd
00324b1c430f000a2020202020200166
020321f14e021101031213041405211f
202210230907078301000065030c0020
00011d00bc52d01e20b8285540c48e21
00001e011d007251d01e206e285500c4
8e2100001e011d80d0721c1620102c25
80c48e2100009e8c0ad090204031200c
405500c48e210000184e1f008051001e
3040803700bc882100001800000000bc