Thursday, February 26, 2009

Creating a server for torrents, usenet, PS3 Media server, vmware server and software raid

I have a PS3 and it's awesome at playing media files over UPnP. Divx, xvid, mpeg etc.

  • I had a server running Ubuntu 7 with a headless version of Azureus for downloading torrents and general network storage of movies, music etc. I also installed the WebUI for it so I could upload torrents remotely.
  • I then decided I wanted software raid, so I added a couple of 500G drives and implemented software raid. It was real easy using mdadm.
  • Then I wanted to start streaming to the PS3 from this server. I then installed Mediatomb and it worked fairly well. It had the ability to transcode incompatible files to a format the PS3 liked. But it never worked the greatest transcoding so I only used videos the PS3 could play natively.
  • Then I finally signed up for a usenet account, so I wanted the ability to download usenet files. But since the server is in the basement, it needed a webUI. So I installed hellanzb with the Zussaweb interface.
Then came PS3 Media Server. PMS for short. :-) I thought i'd give it a try to see if it was any better than mediatomb. The guy who started this really had it right. Small Java application that was built with the PS3 in mind. And transcoding was using mencoder, and it just works! No tweaking or anything. So now it's what I use for UPnP.

I then thought I'd try some HD content in 1080P. But this server just couldn't handle the load and stuttered. I thought it was time to rebuild the OS since it's an older version of Ubuntu, and I have other software on it that's no longer in use (mediatomb). But this also meant a hardware upgrade. So I bought:
So I built it and installed Ubuntu 8.10 desktop. There were no issues installing Ubuntu. It recognized everything (video, audio, network etc).

Hellanzb with Zussaweb


Next I installed hellanzb and what it needs:
sudo apt-get install rar unrar par2 python-dev python-twisted python-pyopenssl wget tar screen hellanzb


Create the hellanzb.conf file.
sudo cp /usr/etc/hellanzb.conf.sample /usr/etc/hellanzb.conf
sudo vim /usr/etc/hellanzb.conf
  1. Make sure you configure the server information in the .conf file. It’s pretty self explanatory and gives examples.
  2. If you’re planning to use SSL; make sure you enable the SSL option and change the port from 119 to 443. I use SSL since astraweb supports it.
  3. Set the PREFIX dir to something like /home/username/ or /mnt/storage/hellanzb/
Now you need to have hellanzb start in /etc/init.d
sudo vi /etc/init.d/hellanzb
Add this:
#
### BEGIN INIT INFO
# Provides: hellanzb
# Required-Start: $network $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Usenet Binary Downloader
### END INIT INFO
#
# hellanzb Start the hellanzb
#
# hellanzb init-script v0.6 dedicated
#
# the following vars are used:
# NAME= leave it to hellanzb, its just a display name and it is used to connect to it with screen
# USERNAME= your username, this is used to run hellanzb in
# *_PIDFILE= the pid file which the script checks
#

NAME=hellanzb
USERNAME=change_me_to_the_user_to_run_this_as
HELLANZB_PIDFILE=/var/run/hellanzb.pid
HELLANZB_BIN=/usr/bin/hellanzb
DESC="Binary Usenet Download Services:"

trap "" 1
export LANG=C

. /lib/lsb/init-functions

case "$1" in
start)
log_acti else
log_end_msg 1
fi
;;

stop)
log_action_msg "Stopping $DESC"
log_daemon_msg " Stopping $NAME.."
if start-stop-daemon -K --pidfile $HELLANZB_PIDFILE; then
log_end_msg 0
else
log_end_msg 1
fi
;;

restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/$NAME start|stop|restart}"
exit 1
;;
esac

exit 0
on_msg "Starting $DESC"

log_daemon_msg " Starting $NAME.."
if start-stop-daemon -S -c $USERNAME -m -b --pidfile $HELLANZB_PIDFILE --exec /usr/bin/screen -- -S $NAME -D -m $HELLANZB_BIN; then
log_end_msg 0
Change change_me_to_the_user_to_run_this_as to the correct user to run this as. To get this script to start when the box starts:
sudo chmod +x /etc/init.d/hellanzb
sudo update-rc.d hellanzb defaults

Start it up:
sudo /etc/init.d/hellanzb start

Make sure it's running:
ps-ef |grep hella
You should see it running.

I wanted to have a web interface for hella, so I decided to use zussaweb. But it needs apache. So I installed it and the php mod:
sudo apt-get install apache2 libapache2-mod-php5
So I then downloaded zussaweb and extracted it to /var/www. I also wanted to have it password protected, so I needed to create an .htaccess file in the /var/www/zussaweb page.

The first step is to add zussaweb to the httpd.conf file:
sudo vi /etc/apache2/httpd.conf
add this to httpd.conf:



Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all


Now we need to create a password file:
sudo mkdir -p /home/secure/
sudo htpasswd -c /home/secure/apasswords ogden
Change 'ogden' to whatever user you wish to log into the web interface with.

Now allow apache user www-data to read our password file:
sudo chown www-data:www-data /home/secure/apasswords
sudo chmod 0660 /home/secure/apasswords

Create the .htaccess file:
sudo vi /var/www/zussaweb/.htaccess
Add the following:
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/secure/apasswords
Require user ogden
Change the user ogden to the user you used to create the password file.

Restart apache:
sudo /etc/init.d/apache2 restart
You should be able to navigate to the web server and get prompted for a username/password:
Example: http://192.168.1.100/zussaweb
I then forwarded all port 21 access on my internet router to this server. That way I can download any usenet file I want whenever I'm not home. My Asus router has the ability to configure an account on dyndns.org, so I can just connect to my dyndns address.

Deluge

Now I want to install deluge. Get deluge. The one I used was here. To install the deb package, run the command:
sudo dpkg -i deluge-torrent_1.1.2-1_amd64.intrepid.deb
sudo vi /etc/default/deluge-daemon

Change the DELUGED_USER to a user on the server.
Make the init.d script executable and have it startup at boot:
sudo chmod +x /etc/init.d/deluge-daemon
sudo update-rc.d deluge-daemon defaults
sudo /etc/init.d/deluge-daemon start
You should now be able to navigate to the deluge webui at the server ip with port number 8112. The default password is deluge and you can configure the directories where it stores the files.

Next is PS3 Media Server
I installed the latest code from SVN, so you're going to need a few packages. Plus I want the multithreaded version of mplayer.
sudo apt-get install subversion build-essential git-core checkinstall yasm libgpac-dev ant sun-java6-jdk

I can't recall all the libs that are needed, so you may need to add more as needed. But here's a list to ensure you have everything:
sudo apt-get install em8300-headers gawk gettext html2text \
intltool-debian ladspa-sdk libaa1-dev libartsc0 libartsc0-dev \ libasound2-dev libatk1.0-dev libaudio-dev libaudio2 \
libaudiofile-dev libavahi-client-dev libavahi-common-dev \
libcaca-dev libcairo2-dev libcdparanoia0-dev libcucul-dev \
libdbus-1-dev libdbus-glib-1-dev libdirectfb-dev \
libdirectfb-extra libdts-dev libdv4-dev libenca-dev libenca0 \
libesd0-dev libexpat1-dev libfaac-dev libfaac0 \
libfontconfig1-dev libfreebob0 libfreetype6-dev libfribidi-dev \ libggi-target-x libggi2 libggi2-dev libggimisc2 \
libggimisc2-dev libgif-dev libgii1 libgii1-dev \
libgii1-target-x libgl1-mesa-dev libglib2.0-dev libglide3 \
libglu1-mesa-dev libglu1-xorg-dev libgtk2.0-dev libice-dev \
libjack-dev libjack0 libjpeg62-dev liblzo-dev liblzo1 \
liblzo2-2 liblzo2-dev libmad0 libmad0-dev \
libmail-sendmail-perl libmp3lame-dev libmp3lame0 libmpcdec-dev \
libmpcdec3 libncurses5-dev libogg-dev libopenal-dev libopenal1 \ libpango1.0-dev libpixman-1-dev libpng12-dev libpopt-dev \
libpthread-stubs0 libpthread-stubs0-dev libpulse-dev \ libpulse-mainloop-glib0 libsdl1.2-dev libslang2-dev libsm-dev \ libsmbclient-dev libspeex-dev libsvga1 libsvga1-dev \ libsys-hostname-long-perl libsysfs-dev libtheora-dev \
libtwolame-dev libtwolame0 libvorbis-dev libx11-dev libxau-dev \ libxcb-render-util0-dev libxcb-render0-dev libxcb-xlib0-dev \
libxcb1-dev libxcomposite-dev libxcursor-dev libxdamage-dev \
libxdmcp-dev libxext-dev libxfixes-dev libxft-dev libxi-dev \ libxinerama-dev libxrandr-dev libxrender-dev libxt-dev \
libxv-dev libxvidcore4 libxvidcore4-dev libxvmc-dev libxvmc1 \ libxxf86dga-dev libxxf86vm-dev mesa-common-dev po-debconf \
sharutils x11proto-composite-dev x11proto-core-dev \
x11proto-damage-dev x11proto-fixes-dev x11proto-input-dev \
x11proto-kb-dev x11proto-randr-dev x11proto-render-dev \
x11proto-video-dev x11proto-xext-dev x11proto-xf86dga-dev \ x11proto-xf86vidmode-dev x11proto-xinerama-dev xtrans-dev \
zlib1g-dev libschroedinger-dev libstdc++5 libfaad-dev \
libgsm1-dev libdc1394-22-dev libfaad-dev libsdl1.2-dev
Get the latest mplayer:
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
Get the multithreaded version of ffmpeg:
git clone git://gitorious.org/ffmpeg/ffmpeg-mt.git
Get the latest of x264:
git clone git://git.videolan.org/x264.git
Compile and install x264:
cd x264
./configure --enable-shared
make
sudo checkinstall --fstrans=no --install=yes --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`-ubuntu"
sudo ldconfig
Compile and install ffmpeg:
cd ffmpeg-mt
git clone git://git.ffmpeg.org/libswscale
./configure
make
sudo make install
Compile and install mplayer:
cd ../mplayer
cp -rf ../ffmpeg-mt/libavcodec libavcodec
cp -rf ../ffmpeg-mt/libavutil libavutil
cp -rf ../ffmpeg-mt/libavformat libavformat
./configure
make
sudo make install
Get the latest PMS:
cd ..
svn checkout http://ps3mediaserver.googlecode.com/svn/trunk/ ps3mediaserver-read-only
cd ps3mediaserver-read-only/ps3mediaserver
ant
Now we want to have PMS start up on boot. Since I'm starting it headless we don't want the actual java GUI to start. We need to modify the PMS.sh script.

vi PMS.sh

Use this for the contents of the script. Ensure you change the DIRNAME to where you've just put PMS. Notice I added the 'console' parm at the end to ensure no java GUI is started.

#!/bin/sh

DIRNAME="/home/gmo/ps3mediaserver/current_version"
cd $DIRNAME

# Setup PMS_HOME
if [ "x$PMS_HOME" = "x" ]; then
PMS_HOME=`cd $DIRNAME/; pwd`
fi
export PMS_HOME

# Setup the JVM
if [ "x$JAVA" = "x" ]; then
if [ "x$JAVA_HOME" != "x" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA="java"
fi
fi

# Setup the classpath
PMS_JAR="$PMS_HOME/pms.jar"

# Execute the JVM
exec "$JAVA" $JAVA_OPTS -Xmx768M -Djava.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -jar "$PMS_JAR" "$@" console
Now we need to create an /etc/init.d script:
sudo vi /etc/init.d/ps3mediaserver
Put this in the script and make sure you update the directories in red:

#!/bin/sh

DIRNAME="/home/gmo/ps3mediaserver/current_version"
cd $DIRNAME

PMS_PIDFILE=/var/run/pms.pid
DESC="PS3 media server"
DAEMON=/home/gmo/ps3mediaserver/current_version/PMS.sh
NAME="ps3mediaserver"

case "$1" in
start)
start-stop-daemon --start -b -m --pidfile $PMS_PIDFILE --exec $DAEMON
;;
stop)
start-stop-daemon -K --pidfile $PMS_PIDFILE
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/$NAME start|stop|restart}"
exit 1
;;

esac
Now we need to create the proper rc.d files:

sudo update-rc.d ps3mediaserver defaults

Next is to create directories. I have videos on various drive and different mount points through SAMBA. I didn't want to modify the PMS.conf file for all of these, so I decided to create one directory and it has symbolic links to all the other folders. Here's what mine looks like:

gmo@gmo-server:~/videos$ ls -l
total 4
drwxr-xr-x 51 gmo gmo 4096 2009-02-24 22:38 action
lrwxrwxrwx 1 gmo gmo 24 2009-02-15 15:40 comedy -> /mnt/asus-videos2/comedy
lrwxrwxrwx 1 gmo gmo 24 2009-02-15 16:29 crime -> /media/sdb1/videos/crime
lrwxrwxrwx 1 gmo gmo 28 2009-02-15 15:39 documentary -> /mnt/asus-videos/documentary
lrwxrwxrwx 1 gmo gmo 24 2009-02-15 16:29 drama -> /media/sdb1/videos/drama
lrwxrwxrwx 1 gmo gmo 25 2009-02-15 15:39 exercise -> /mnt/asus-videos/exercise
lrwxrwxrwx 1 gmo gmo 23 2009-02-15 15:39 horror -> /mnt/asus-videos/horror
lrwxrwxrwx 1 gmo gmo 22 2009-02-15 15:40 kids -> /mnt/asus-videos2/kids
lrwxrwxrwx 1 gmo gmo 22 2009-02-15 15:40 music -> /mnt/asus-videos/music
lrwxrwxrwx 1 gmo gmo 24 2009-02-15 15:40 romance -> /mnt/asus-videos/romance
lrwxrwxrwx 1 gmo gmo 23 2009-02-15 15:40 scifi -> /mnt/asus-videos2/scifi
lrwxrwxrwx 1 gmo gmo 25 2009-02-15 16:30 sports -> /media/sdb1/videos/sports
lrwxrwxrwx 1 gmo gmo 27 2009-02-15 16:30 thriller -> /media/sdb1/videos/thriller
lrwxrwxrwx 1 gmo gmo 20 2009-02-15 16:29 tv_shows -> /media/sde1/tv_shows
To create the links above, you would do something like this:
cd /home/gmo/videos
ln -s
/media/sde1/tv_shows tv_shows
Now edit the PMS.conf:

cd /home/gmo/ps3mediaserver/current_version
vi PMS.conf
The lines I changed are folders, hostname, port, language, nbcores, mencoder_audiolangs, mencoder_sublangs, and mencoder_audiosublangs. I also added the sort type at the bottom. I checked the source and the functionality exists, but it wasn't added to the conf file.
folders = /home/gmo/videos,/raid-drive
hostname = 192.168.1.220
port = 16111
language = eng
thumbnails = true
thumbnail_seek_pos = 1
nbcores = 2
turbomode = false
minimized = false
hidevideosettings = false
usecache = false
charsetencoding = 850
engines = mencoder,avsmencoder,tsmuxer,mplayeraudio,ffmpegaudio,tsmuxeraudio,vlcvideo,mencoderwebvideo,mplayervideodump,mplayerwebaudio,vlcaudio,ffmpegdvrmsremux
autoloadsrt = true
avisynth_convertfps = true
avisynth_script =
transcode_block_multiple_connections = false
tsmuxer_forcefps = true
tsmuxer_preremux_pcm = false
tsmuxer_preremux_ac3 = false
audiochannels = 2
audiobitrate = 384
maximumbitrate = 0
skiploopfilter = false
enable_archive_browsing = false
mencoder_fontconfig = false
mencoder_font =
mencoder_forcefps = false
mencoder_usepcm = false
mencoder_intelligent_sync = true
mencoder_decode =
mencoder_encode = keyint=1:vqscale=1:vqmin=2
mencoder_nooutofsync = true
mencoder_audiolangs = eng
mencoder_sublangs = eng
mencoder_audiosublangs = eng
mencoder_subfribidi = false
mencoder_ass_scale = 1.0
mencoder_ass_margin = 10
mencoder_ass_outline = 1
mencoder_ass_shadow = 1
mencoder_noass_scale = 3
mencoder_noass_subpos = 2
mencoder_noass_blur = 1
mencoder_noass_outline = 1
mencoder_subcp = cp1252
mencoder_ass = true
mencoder_disablesubs = false
mencoder_yadif = false
mencoder_scaler = false
mencoder_scalex = 0
mencoder_scaley = 0
ffmpeg = -g 1 -qscale 1 -qmin 2
#this is the sort method for the file listing - by date or alphabetical
# 0 = alpha 1=date
key_sort_method = 0

You should now be able to start up PMS.
sudo /etc/init.d/ps3mediaserver start
Go to your PS3 and you should be good to go for viewing the videos.


Software RAID
I already had RAID 1 configured on the older box and was worried that I'd have to redo it all over again on the new machine. I backed up all the files to a USB drive just in case.
But once I got Ubuntu 8.10 installed and hooked the 2 500G SATA drives up I was able to add them to a raid device.

It's been a while, but here's what I think I did to 'rebuild' that raid array. I know that at a basic level you create the raid device (/dev/md0) and then add the discs to the raid device. It warned me that the discs already had a filesystem on them but I did it anyways.
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdc1
I'd need to mount it to access it, so I created a directory for it:
sudo mkdir /raid-drive
sudo chmod -R 777 /raid-drive
Then I added it to the /etc/fstab to mount at boot:
sudo vi /etc/fstab
Add this to the fstab file:
/dev/md0 /raid-drive ext3 defaults,errors=remount-ro 0 2
You should then be able to mount the drive and use it like any other mounted drive:
sudo mount /raid-drive

No comments: