Powernap – The Server Power Management


I recently moved into a new home and one of the first things that I HAD to do was setup the home media server with a XBMC front end. So I set it up and I have been watching movies and television happily for a month now. All was going well until I got my first electricity bill. Wow was it painful. Of course it include the usage of a fridge and other appliances, but the media server had not been turned off for the whole month even though I only used it maybe 2 hours a day.

To this end I set out to find a way to reduce power consumption. The first thing that I thought of was a simple shutdown script for the XBMC front end that would turn off the server before it turned off. This worked well but there where problems, that sometimes the front end wasn’t turned off for long periods with idle time, or sometimes after I turned off the front end I still wanted to access the server and I still had to manually turn the server on. Clearly this was not a long term solution.

The next concept was to get the computer to be turned on via Wake On Lan. Wake On Lan (WoL) is a method of sending a special command to a computers motherboard via an Ethernet connection. This is easy to setup but hard actually do. Searching around online I found a program Powerwake written by Dustin Kirkland which using a very simple interface can perform as required. On Ubuntu this can be installed and used to wake a computer like so:

sudo apt-get install powerwake

sudo powerwake 10.0.0.12

*Replace 10.0.0.12 with the the address of the computer you want to wake.

This can be used to wake a sleeping computer. I use a simple script built into the front end which when runs wakes the server, waits about 30 seconds and then tries to remount the fstab file. If it the remount fails it waits another 30 seconds and then tries again. When the remount succeeds the computer reloads XBMC – easy.

This leaves only the problem of getting the server to turn off after inactivity. For this I installed the powernap program. This is a great application, again from Dustin Kirkland, which acts much like a screen saver for a server or non-GUI system. It is was quite complex to setup, but once you understand how it works it becomes much simpler.

Unfortunately time has run out and this post must end now. Stay tuned for updates of how I installed Powernap and a better look at how the program works.

As power is becoming a more and more costly and a limited resource (until we switch to renewable energy sources) tools such as powernap and powerwake will become more and more necessary for both hobbyists and professionals alike.

Advertisements

Start using Fuel PHP today


The last few days I have been busy looking at the Fuel PHP framework. And it’s AWESOME. That’s not a great description, its not even very objective, but none the less it is true (you will have to take my word for it now). The framework can be found at fuelphp.com.

Today I am going to give a quick guide for installing and running Fuel PHP on a linux machine and some extra cool tricks to make the setup easier. First what things do you need, assuming that you have a fresh linux install.

  • apache webserver
  • php 5.3 (needs to be at least 5.3)
  • php cli (command line interface)
  • mysql database server
  • command line editor vi or vim (not totally necessary but i will assume that you have one as I believe command line file editing to be the easiest option)
  • wget or curl (fuel documentation uses curl but either could be used)

I will also assume that you have root access and that you are on a home computer using localhost for your domain. Production environments require more careful setup and I will address those issues in a completely different post.

Lets Go

1. install all the necessary components

sudo apt-get update
sudo apt-get install php5 php5-cli apache2 mysql-server phpmyadmin curl vim git-core

2. install the fuel PHP oil installer. (that sounds strange)

curl get.fuelphp.com/oil | sh

3. change into the directory that you want to build you fuel application in and run the fuel PHP oil create script. replace {user} with your username and {app name} with the name you want to give your application. it doesn’t matter what the name is as it wont get used in the website URI

cd /home/{user}/Public/
oil create {app name}

4. Now it that’s as far as the basic section of the documentation on the fuelphp.com documentation website. However you cannot access the app in the browser yet. Before you can do that there are a few steps that you must take. We have to set up the apache virtual host. This greatly varies on you operating system, but for simplicity I will cover just Ubuntu, and will cover different OS’s later. We need to alter the virtual host so that it follows symbolic links and knows what the root directory of the website is. Because the fuel index.php file is in the public folder in the actual top directory we will include the public directory in the website root directory.

sudo vim /etc/apache2/sites-enabled/000-default

Now make the file look like this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /home/{user}/Public/{app name}/public
        <Directory />
                Options FollowSymLinks
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        <Directory /home/{user}/Public/{app name}/public>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

Restart apache to apply the configuration changes

sudo /etc/init.d/apache2 restart

5. If everything worked you should now be able to go to http://localhost/ and the fuel app page should be visible. It looks a little bit like the codeigniter welcome page. (most of the developers of fuel have or still do contribute to codeigniter).

Conclusion

Hopefully this is guide is a relatively straight forward explanation of how to set up fuel on a new development environment. Any questions or comments are appreciated. I’m sure I made a mistake somewhere in there or perhaps it just didn’t work on your computer. I would also love to get some suggestions on what you would like to see next.

Installing Ruby RVM on Ubuntu and Fedora


Installing ruby on Linux is easy, just run sudo apt-get install ruby or yum install ruby. However, version control can be difficult to manage. That is, scripts that run on a version on your computer may not run as well on another. So wouldn’t it be great if you could have 2 or more versions or the ruby interpreter on your computer.

To do this we will use the RVM – Ruby Version Manager. This is a great program, Allowing you to have complete environments for running ruby. This includes the interpreter and gems. And besides the few intricacies of setting it up, It is relatively easy to do.

My instructions are fairly similar to the official RVM instructions. You can find them at rvm.beginrescueend.com and more about RVM at there index page.

OK. Lets go..

Firstly make sure that you have a version ruby installed and curl for downloading the script (most distributions come standard with this, although minimal setups will not.

UBUNTU
sudo apt-get install ruby curl

FEDORA
yum install ruby curl

Now make sure that you are logged in as the user that you want to install ruby for. This may be a no brainier however, if you have more than one user you may wish to install ruby for everyone or for a specific person. I would very much suggest NOT install RVM for everybody, because different users may choose to run different ruby interpreters which may cause problems latter on down the track.

Time to get dirty with the command line.

Open up a terminal session and cd to your home directory. The first thing is to download the install script and run it in bash

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

Once the script has run issue the following command to load RVM every time you login.

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

Now you need to close all your open terminal windows and then launch another. When the new one is open execute the following.

source .bash_profile

Now, to test that we have done all the previous correctly you need to use the following command and compare the results.

type rvm | head -l

The should output 'rvm is a function'

Thats it. Ruby Version Manager has been installed. Unfortunately, just having it installed is not much good, we need to look at gemsets and ruby versions, but that is for another post.

Quick Tip – Man Pages


Linux Man pages are one of the most useful resources a Linux user has in his arsenal when it comes to learning about a command line functionality or just about anything you could need to know about Linux. For example, today I want to transfer some log files from my server to my main computer analysis but a small script I had written, I decided do this via ftp (just cause I could). So the first thing that I did was check the man page to ensure I used the correct commands, by using man ftp.

man ftp

This shows an interactive document. You can scroll down to read more, press q to exit.

There are many different sections to the man program, each containing a different subset of commands and programs. This allows for different documentation of similar or the same named programs. For example, the apt program has to expansions – annotation processing tool and advanced packaging tool. Usually typing in a command into man produces the output you want, sometimes though you have to go searching.

man apt

This gives the man page for annotation processing tool.

man 8 apt

This gives the man page for advanced packaging tool.

If you come across the someone else referencing a man page, or you yourself want to reference a man page you would write it man program(section) eg for advanced packaging tool you would use man apt(8)

Selecting Hardware for a Server – Ubuntu Server


Hardware is KEY.

You must have the BEST.

I am here to tell you that ITS ALL LIES. Fed to us through not just the media but big businesses and other corporate goons, bent on taking us for as much money as we can. The truth of the matter is that unless your running windows 7 ultimate packed full of processor heavy programs, you only need the most minimal of hardware setups by todays standards to run a server and even then it will most like be underused. (more…)

Getting Ready to Install – Ubuntu Server


The Following article is suitable for any Linux Distribution, however make sure that there are no alternate instructions on the distribution you are using.

Now that we know which version of Ubuntu we are going to install we can prepare the installation disk. The first thing that we need to do is download the iso. The iso is an archive type formate that is burnable to a disk. It can be anything really, a dvd, a cd, a USB Thumb drive. The iso itself can be found many places. Primarily it can be downloaded from the main Ubuntu website. It can also be downloaded from a mirror. Google Ubuntu mirror and your country name will bring up many different mirrors, select a relevant one and navigate to and download the iso. I live in Australia and on a university campus so i use mirror.aarnet.edu.au from which i can download the whole iso (700MB) in 15-20 seconds.

Now we will need to load the iso onto the disk (for this article i will be putting it on a cd. I will go through all the different methods and OS later). Below is a list of descriptions for each primary operating system

  • Ubuntu
    1. Insert a blank disc. Cancel any pop up windows that may open
    2. Right click on the downloaded iso and choose the option “Write to Disc”
    3. Select the Write speed and location of write – either of theses options may not be available.
    4. Click Burn. The setup of the install disc is finished.
  • Mac
    1. Launch Disk Utility (Applications → Utilities → Disk Utility)
    2. Insert your blank CD/DVD
    3. Drag and drop your .iso file to the left pane in Disk Utility. Now both the blank disc and the .iso should be listed
    4. Select the .iso file, and click on the ‘Burn’ button in the toolbar
    5. Ensure that the ‘Verify burned data’ checkbox is ticked (you may need to click on the disclosure triangle to see the checkbox)
    6. Click ‘Burn’. The data will be burned and verified
  • Windows 7
    1. Right-click on an ISO image and choose ‘Burn disc image’
    2. Select a disk burner (drive) and choose ‘Burn’. If you check ‘Verify disc after burning’, it will confirm that the ISO image has been burned correctly

For a more comprehensive list of how to burn an iso visit BurningIsoHowto which details every way to burn disk image onto a any form of disk. Thank you Ubuntu.

Why Choose Ubuntu Server


Why Not.

Today, servers come in many many flavors, If your reading from a web browser you got your IP address from a DHCP server, sent information to a DNS server, more information to a web server, which accessed a database server. It is inescapable. And although it is undeniable that servers are everywhere (and will one day take over the world and rule with an iron fist) Why would you need one?

I use a server in my home for a number of reasons. I have 2 desktop computers, a laptop and a home built router. My server is the place where everything is put together and all the behind the scenes work happens. I never have data loss (theoretically that is) and all of my data and internal information is stored. I also can play games with my friends on it and it also allows my printer to be accessible from just about anywhere. This all happens because I have a server running Ubuntu 10.04 (more…)

Creating and Using Symlinks


Often we want some files to be in two places at once. Perhaps you are working a website that has its files in you home folder and then you want them to be displayed in /var/www/. Or maybe the software that your working with requests specific files in one folder but another program wants the in their current one. Despite the difficulty that I have in describing why you would need such an ability, There is know denying that eventually you are going to need to know how to use symlinks.

At the most basic level a symlink (AKA the Symbolic Link or sometimes referred to as a soft link) is a pointer that points to the actually location of the files without the program knowing that the files are not actually there. It also allows for a there to be differences in group and ownership if the content of a file, but more of that another time. (more…)

%d bloggers like this: