Saturday, 22 August 2015

The Broken Toshiba as a server

My little EE Box is feeling the strain with all the work it does on top of just file sharing. I've come across a slightly broken Toshiba laptop which works until you try to do anything graphical on it. But just running a text based desktop works fine, so I've decided to offload some of the tasks from the other machine on it.

The first thing I'm going to do is install Ubuntu 14.04 server with just the basic packages and the ssh server so I can do the rest remotely. I'll configure the router to give it a static IP. I'm not going to go into any detail on that lot as you really shouldn't be doing the rest of this if you can't do that.

But first  I'm going to install Midnight Commander and a few other files as I'm going to be accessing an nfs share with this server, it's not essential and if this is going to be a standalone machine then you don't need the following:

sudo apt-get install mc nfs-common nfs-server

Then with the help of some instructions from NoobsLabs, I'm going to setup my own cloud server using OwnCloud, it's going to take some time so go with me on this.

Quite a few command to type so let's make a start:

This is all one line:

sudo sh -c "echo 'deb http://download.opensuse.org/repositories/isv:/ownCloud:/community/xUbuntu_14.10/ /' >> /etc/apt/sources.list.d/owncloud.list"


And so is this:

wget http://download.opensuse.org/repositories/isv:ownCloud:community/xUbuntu_14.10/Release.key
sudo apt-key add - < Release.key



sudo apt-get update

sudo apt-get install owncloud



During the installation it's going to ask you to create a password for the SQL server, please remember this password and if you are going to get access while away from home make sure it's a good password.

Then we have to set the permissions for the Owncloud folders:



sudo chown -R www-data:www-data /var/www/owncloud
and
sudo chmod 0777 -R -v /var/www/*



Then we setup SSL to enable an encrypted connection, we are going to use self certification for this so you will get security alerts from some browsers when connecting.

sudo apt-get install openssl
sudo a2enmod ssl
sudo a2enmod rewrite
sudo mkdir -p /etc/apache2/ssl
sudo openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/owncloud.pem -keyout /etc/apache2/ssl/owncloud.key

Now run ifconfig to find the IP address of the machine, mine is 192.168.0.251
And then past the following text in to the file you are about to create, replacing the IP address with the one for your server:


sudo nano /etc/apache2/sites-enabled/owncloud.conf



<VirtualHost 192.168.0.251:80>
#### Redirect to port 443 ###
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
#### End of Redirection configuration ###
DocumentRoot /var/www/owncloud/
<Directory /var/www/owncloud>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.0.251:443>
####Configuration for SSL #####
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/owncloud.pem
SSLCertificateKeyFile /etc/apache2/ssl/owncloud.key
#### End of SSL Configuration ####
DocumentRoot /var/www/owncloud/
<Directory /var/www/owncloud>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

And now we restart Apache with:

sudo service apache2 restart


You should now be able to connect to the server with a browser using:

https://machinename

Create a login and get on with the initial configuration, if you are asked to add the server as a trusted domain just do it.

Then you need to setup some port forwarding on your router so you can access the cloud from the outside world. And that's your cloud server all setup.





Next up I'm going to install Newznab to index some newsgroups.


Now we need to install some files:





Now we create the file structure with:
sudo mkdir /var/www
sudo mkdir /var/www/newznab
sudo chmod 0777 /var/www/newznab




Next we need to install php with the following:

sudo apt-get install php5 php5-dev php-pear


Then we install some php extensions with:

sudo apt-get install php5-gd php5-mysql php5-curl


Now we make some changes to the php configuration file:

sudo nano /etc/php5/cli/php.ini


Under the resource limits section we need to change the maximum execution time to 120:

max_execution_time = 120

Then under Module Settings we need to change the time zone settings, in my case I'm the UK so I'm going to change it to:

date,timezone = Europe/London

There are other options depending on where you live, you can find these here.



Now we make sure that all the required SQL stuff is installed

sudo apt-get install mysql-server-5.5

sudo apt-get install mysql-client-5.5

sudo apt-get install libmysqlclient-dev


We have to make some changes to the Apache config now with:

sudo nano /etc/php5/apache2/php.ini

We then need to change these settings


memory_limit =  -1
max_execution_time = 120 
date.timezone =  Europe/London


Now we need to create a configuration file for Newznab, so type the following to create an empty file:


sudo nano /etc/apache2/sites-available/newznab.conf

And then paste the following into the file:

<VirtualHost *:8080>
ServerAdmin webmaster@localhost
ServerName localhost

DocumentRoot /var/www/newznab/www
ErrorLog /var/log/apache2/error.log
LogLevel warn
</VirtualHost>


This will run Newznab on port 8080, change this if you want it to run on another port.

Save this file to continue.


We also need to enter another Apache file with:


nano /etc/apache2/ports.conf


Add Listen 8080 to the list or whatever port you have Newznab on.


# If you just change the port or add more ports here, you will likely also

# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

Listen 8080
<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>

        Listen 443
</IfModule>


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet





We now need to get hold of Newznab itself, you can get it from here. Newznab classic works but there are some limitations, if you are serious just pay the money for a better product and you get free upgrades too.

Get the file downloaded and then we need to extract it and copy it to the right place, if you have decided to use a graphical desktop you can follow these pictures.








As I have a paid for version I'm going to use a slightly different approach, for this you need to install subversion with the following command:

sudo apt-get install subversion

Then to get Newznab you enter the following command:

svn co svn://svn.newznab.com/nn/branches/nnplus /var/www/newznab

At this point you will be asked for the root password for your system and the SVM login details that have been emailed to you by the Newznab team.


You also need to edit /etc/apache2/apache2.conf and make this change:



sudo nano/etc/apache2/apache2.conf


<Directory /var/www/>

        Options Indexes FollowSymLinks
# Default Setting is AllowOverride None
        AllowOverride All 
        Require all granted

</Directory>


Save the file and now it's time to activate the changes with the following.

sudo a2ensite newznab
sudo a2enmod rewrite
sudo service apache2 restart

Now it's time to change some permissions with the following commands:

sudo chmod 777 /var/www/newznab/www/lib/smarty/templates_c
sudo chmod 777 /var/www/newznab/www/covers/movies
sudo chmod 777 /var/www/newznab/www/covers/music
sudo chmod 777 /var/www/newznab/www
sudo chmod 777 /var/www/newznab/www/install
sudo chmod 777 /var/www/newznab/nzbfiles/
sudo chmod 777 /var/www/newznab/www/covers/anime

We just need to make sure that some files are also installed:



sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
sudo apt-get update
sudo apt-get install unrar
sudo apt-get install mediainfo
sudo apt-get install ffmpeg
sudo apt-get install lame

When you run the Newznab config and go in to edit the site you will need to put the paths in for these files, they normally are:
/usr/bin/unrar
/usr/bin/mediainfo
/usr/bin/ffmpeg
/usr/bin/lame


And now point your browser to 

http://servername:8080/install 

And just follow the instructions and prompts to configure your very own Newznab server.

Once you have finished the comfiguration, run this following command to change permissions on one of the folders.

sudo chmod 777 /var/www/newznab/nzbfiles/tmpunrar

I would like to thank the howtogeek website for helping with most of these instructions.





Now it's time to install SabNZB

Then we install the app:

sudo apt-get install sabnzbdplus


Now we edit one of the config files with:

sudo nano /etc/default/sabnzbdplus


USER=root
# The Host one can be 0.0.0.0 if you only have one IP address
HOST=192.168.0.249 
# Change this to another port if 8080 is already in use.
PORT=8082


Then we make it executable:

sudo chmod +x /etc/init.d/sabnzbdplus


Then we restart the service

sudo service sabnzbdplus restart

Once this has finished point your browser to http://ipaddress:8082 and finish setting up the app.

I'm using XS Usenet to provide me usenet feed, you can get an account yourself by clicking on this link.







Now it's time to install a Torrent client in Debian and configure it without the help of a GUI.


We're going to use Deluge for this

Back to the command line with:

sudo apt-get update
sudo apt-get install deluge-console deluged deluge-web


Now we need to configure this to start on boot up:

sudo nano /etc/default/deluge-daemon

And then enter this text:

####################
# Configuration for /etc/init.d/deluge-daemon

# The init.d script will only run if this variable non-empty.
DELUGED_USER="" # !!!CHANGE THIS!!!!

# Should we run at startup?
RUN_AT_STARTUP="YES"
##################

And now another config file

sudo nano /etc/init.d/deluge-daemon

And then enter this text:


####################################################


#!/bin/sh

### BEGIN INIT INFO
# Provides:          deluge-daemon
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Should-Start:      $network
# Should-Stop:       $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Daemonized version of deluge and webui.
# Description:       Starts the deluge daemon with the user specified in
#                    /etc/default/deluge-daemon.
### END INIT INFO

# Author: Adolfo R. Brandes 

# Updated by: Jean-Philippe "Orax" Roemer

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="Deluge Daemon"
NAME1="deluged"
NAME2="deluge"
DAEMON1=/usr/bin/deluged
DAEMON1_ARGS="-d"             # Consult `man deluged` for more options
DAEMON2=/usr/bin/deluge-web
DAEMON2_ARGS=""               # Consult `man deluge-web` for more options
PIDFILE1=/var/run/$NAME1.pid
PIDFILE2=/var/run/$NAME2.pid
UMASK=022                     # Change this to 0 if running deluged as its own user
PKGNAME=deluge-daemon
SCRIPTNAME=/etc/init.d/$PKGNAME

# Exit if the package is not installed

[ -x "$DAEMON1" -a -x "$DAEMON2" ] || exit 0

# Read configuration variable file if it is present

[ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME

# Load the VERBOSE setting and other rcS variables

[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.

# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

if [ -z "$RUN_AT_STARTUP" -o "$RUN_AT_STARTUP" != "YES" ]

then
   log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it."
   exit 0
fi

if [ -z "$DELUGED_USER" ]

then
    log_warning_msg "Not starting $PKGNAME, DELUGED_USER not set in /etc/default/$PKGNAME."
    exit 0
fi

#

# Function to verify if a pid is alive
#
is_alive()
{
   pid=`cat $1` > /dev/null 2>&1
   kill -0 $pid > /dev/null 2>&1
   return $?
}

#

# Function that starts the daemon/service
#
do_start()
{
   # Return
   #   0 if daemon has been started
   #   1 if daemon was already running
   #   2 if daemon could not be started

   is_alive $PIDFILE1

   RETVAL1="$?"

   if [ $RETVAL1 != 0 ]; then

       rm -f $PIDFILE1
       start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --make-pidfile \
       --exec $DAEMON1 --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK -- $DAEMON1_ARGS
       RETVAL1="$?"
   else
       is_alive $PIDFILE2
       RETVAL2="$?"
       [ "$RETVAL2" = "0" -a "$RETVAL1" = "0" ] && return 1
   fi

   is_alive $PIDFILE2

   RETVAL2="$?"

   if [ $RETVAL2 != 0 ]; then

        sleep 2
        rm -f $PIDFILE2
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --make-pidfile \
        --exec $DAEMON2 --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK -- $DAEMON2_ARGS
        RETVAL2="$?"
   fi
   [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 2
}

#

# Function that stops the daemon/service
#
do_stop()
{
   # Return
   #   0 if daemon has been stopped
   #   1 if daemon was already stopped
   #   2 if daemon could not be stopped
   #   other if a failure occurred

   start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE2

   RETVAL2="$?"
   start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE1
   RETVAL1="$?"
   [ "$RETVAL1" = "2" -o "$RETVAL2" = "2" ] && return 2

   rm -f $PIDFILE1 $PIDFILE2


   [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] && return 0 || return 1

}

case "$1" in

  start)
   [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME1"
   do_start
   case "$?" in
      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
   esac
   ;;
  stop)
   [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME1"
   do_stop
   case "$?" in
      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
   esac
   ;;
  restart|force-reload)
   log_daemon_msg "Restarting $DESC" "$NAME1"
   do_stop
   case "$?" in
     0|1)
      do_start
      case "$?" in
         0) log_end_msg 0 ;;
         1) log_end_msg 1 ;; # Old process is still running
         *) log_end_msg 1 ;; # Failed to start
      esac
      ;;
     *)
        # Failed to stop
      log_end_msg 1
      ;;
   esac
   ;;
  *)
   echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
   exit 3
   ;;

esac


#########################################

Now we change the permissions of this file with:


sudo chmod 755 /etc/init.d/deluge-daemon

Now we get it running on startup

sudo update-rc.d deluge-daemon defaults


We can then start it with this command:

sudo invoke-rc.d deluge-daemon start


And stop it with this command:

sudo invoke-rc.d deluge-daemon stop


You should now be able to access it with http://machinename:8112






Next up is SickRage to track and download the TV series you want to watch


There are some things that we need to install first:


sudo apt-get install git-core python python-cheetah



Now this bit gets installed as a normal user and not root:


cd ~

git clone https://github.com/SiCKRAGETV/SickRage.git .sickrage



We now need to create a file to get this working properly


cd ~/.sickrage

cp -a autoProcessTV/autoProcessTV.cfg.sample autoProcessTV/autoProcessTV.cfg



And then we start it with:


python ~/.sickrage/SickBeard.py -q



Now connect to it with http://machinename:8081 and follow all the configuration steps, once that's done , shut it down from inside it's web interface and then it's time to get it running automatically.



cd ~/.sickrage/runscripts


And then:


sudo cp init.debian /etc/init.d/sickrage

sudo chmod +x /etc/init.d/sickrage

Now we need to edit a file with:



sudo nano /etc/default/sickrage

And add the following to it:
# COPY THIS FILE TO /etc/default/sickrage
#########################################################
# Change user below to the username you have installed SickRage into
#########################################################

SR_HOME=/home/user/.sickrage/
SR_DATA=/home/user/.sickrage/
SR_USER=user
SR_GROUP=user

Now we make this file executable
sudo chmod +x /etc/default/sickrage


And then update the boot sequence:

sudo update-rc.d sickrage defaults


We can now start and stop it with the following commands:

sudo service sickrage start
sudo service sickrage stop



And now we move onto Couchpotato for films, so it's back to root for this lot and first up we run the following command:



sudo git clone https://github.com/RuudBurger/CouchPotatoServer.git /opt/CouchPotato


We then need to change the file ownership with the following command:


sudo chown -R username:username /opt/CouchPotato


Replace username with the username you will be running this under.




Now we make it a script to start it automatically

sudo nano /etc/default/couchpotato


Paste this lot in, replacing username with your username


CP_HOME=/opt/CouchPotato

CP_USER=username
CP_PIDFILE=/home/username/.couchpotato.pid

CP_DATA=/opt/CouchPotato


Now we copy over the init file


sudo cp /opt/CouchPotato/init/ubuntu /etc/init.d/couchpotato



Then we make it executable


sudo chmod +x /etc/init.d/couchpotato


And finally make it run on startup


cd /etc/init.d/


sudo update-rc.d couchpotato defaults




Now reboot and try it all out.

Monday, 3 August 2015

Raw Camel

July the 23rd in Wolverhampton was the night, Wulfrun Hall was the venue, Camel were the band. The seating was uncomfortable, the hall could have done with some redecoration, the Seleco projector in the lighting rig looked like it had been there for some time and then Camel arrived on stage. There were problems with the sound equipment causing a bit of distortion but the band were fantastic, that is really what I think. The playing by all members was awesome, they were up on stage doing what they do best and they all seemed to be thoroughly enjoying themselves. Ton and Jason on keyboards were superb, Ton's style is different from the late Guy LeBlanc who he took over from on this tour but his piano on Long Goodbyes was brilliant. Jason seemed to be playing various instruments during the show and deserves to be recognised as a brilliant performer in hos own right.

Then there's Denis on drums, I swear he had 4 arms at one point, the man is amazing and he doesn't seem to break into a sweat.

Next we come to Mr Colin Bass of the bass guitar who just stands there effortlessly playing away and is looking good with his new growth of facial hair, he's also done some wonderful solo albums and produces some class bands including 9bach.

And last but not least there's Andy Latimer, the man behind the band. This man can put so many different emotions into a guitar, he is up there with the greatest in my humble opinion.

The band played a selection tracks old and new including some of my favourites, Ice, Mother Road, Drafted and Long Goodbyes. I'd love to say they were perfect, but they weren't. Perfect doesn't even come close to describing how good they were, this was Camel, live and raw, having a good time, playing some of their best tracks.

The last track, Long Goodbyes was dedicated to Chris Rainbow and Guy LeBlanc who had both been members of the band and had regretfully passed away, images of them were projected onto screens as it was played, I have to be honest I cried like a baby.




After the concert I got to meet up with Andy and Colin, I asked Colin if he could sign my ticket for my granny. His face lit up and he looked at me and said "you're Paul Holt". He is a really nice bloke and is fitting in with his local community in North Wales even learning Welsh.

Andy is also a really nice humble person. I mentioned that I met him last at a Liverpool concert, couldn't remember the place but it began with an R. A few minutes later the name came to me, it was the Lomax. This seemed to cause quite a but of humour and references to the Romax.


 I look forward to seeing them again hopefully and look forward to any new material they produce.

Till then, Never Let Go.