Howto

Howto: Zend Framework Cron

This was verified to work under Zend Framework 1.9.5 and 1.9.6.

First we want to make a new file for the cron somewhere outside the public folder, I chose a folder called scripts.
My project thus looks like this:

  • domain.com Fresh Sweet CRON
    • application
    • library
    • logs
    • public
      • index.php
    • scripts
      • cronjob.php
    • tests

The trick with cronjobs is that you do not want to load the whole View part of ZF, we don’t need any kind of HTML output! To get this to work, I defined a new constant in the cronjob.php which I will check for in the index.php.

cronjob.php

define(“_CRONJOB_”,true);
require(‘/var/www/vhosts/domain.com/public/index.php’);
….. rest of your code goes here, you can use all Zend components now!

index.php

date_default_timezone_set(‘Europe/Amsterdam’);

// Define path to application directory
defined(‘APPLICATION_PATH’)
|| define(‘APPLICATION_PATH’, realpath(dirname(__FILE__) . ‘/../application’));

// Define application environment
defined(‘APPLICATION_ENV’)
|| define(‘APPLICATION_ENV’, (getenv(‘APPLICATION_ENV’) ? getenv(‘APPLICATION_ENV’) : ‘production’));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . ‘/../library’),
get_include_path(),
)));

/** Zend_Application */
require_once ‘Zend/Application.php’;

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . ‘/configs/application.ini’
);
$application->bootstrap();

/** Cronjobs don’t need all the extra’s **/
if(!defined(‘_CRONJOB_’) || _CRONJOB_ == false)
{
$application->bootstrap()->run();
}

It’s as easy as that!
You’d be surprised how long it took me to find the answer to this simple problem, like many other opensource projects documentation for ZF has to sometimes be found in the community and a lot of that is outdated. This was just one of a few solutions but it works just fine for me and is pretty simple to implement so I decided to stick with this.

I hope this can help someone out

Howto: Fan control in Ubuntu Jaunty

This tutorial will explain how to get fan control working on Ubuntu Jaunty.

Start with installing lm-sensors and detecting your sensors & fans:

sudo aptitude install lm-sensors
sudo sensors-detect

Pay attention to end part of running sensors-detect, it is the only option that defaults to NO but you want to select YES!
If you do happen to select NO then you will have to sudo nano /etc/modules yourself and add the lines sensors-detect shows at the end.
My run produced some output as seen below:

#—-cut here—-
# Chip drivers
w83627hf
k8temp
#—-cut here—-

If you want to be sure it put the code in the right place you can sudo cat /etc/modules to have a look.

Next we have to enable the sensors the script found.
This will happen automatically if you reboot, but we don’t want to reboot so will do it now.
This sometimes doesn’t seem to work though, so if you want to be sure it works reboot.

sudo modprobe w83627hf
sudo modprobe k8temp

Now we can configure the fanspeeds:

sudo pwmconfig

I ended up using the default settings, they were quite good for my situation.

Then we can start the daemon! Note that I added a & at the end. This starts fancontrol but gives us back control of the command-line. If you don’t understand run it without and you’ll get what I mean.. Ctrl+C is your friend ;)

sudo fancontrol &

To get fancontrol to run at boot I decided for the following (really easy) solution: put it in crontab at boot!
Since the program needs root this is not a problem, I think.

sudo crontab -e

And add the following line:

@reboot fancontrol

That’s it! Fancontrol now starts on reboot, keeps a check on temps and dynamically spins up/down the fan.
Actually works better for me than various apps I’ve tried in Windows, especially because it starts up way before the GUI is loaded (if you use one at all..)

Howto: VNC to home over SSH with Ubuntu

Something small I just figured out which might be useful for others again.
The various tutorials I found online missed something crucial in the explanation, so it took me a while to figure it out.

Server Side
Go to System->Preferences->Remote Desktop
Copy the following settings:

Client Side:

# Install SSH server on your client
sudo aptitude install ssh
# Make an SSH tunnel to your home for port 5900
# (the default VNC port)
ssh -NC -L 5900:localhost:5900 USER@DOMAIN.COM -p 22

Now you can start up your VNC client and set it to connect to localhost.
Because of the SSH tunnel we setup it will connect to the server as if it’s the localhost over an ecrypted SSH connection :D

More detailed information can be found on these two pages:
https://help.ubuntu.com/community/VNC?action=show&redirect=VNCOverSSH
https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding

Howto: Install HLDS / SRCDS (TF2) in Ubuntu 64bit

This took me a little while to figure out, but it was actually really easy.
So, once again, a post to store it on the interwebz and help others :)

# Make a new dir and move into it
mkdir srcds && cd srcds
# Download hldsupdatetool
wget http://www.steampowered.com/download/hldsupdatetool.bin
# Make it executable
sudo chmod +x hldsupdatetool.bin
# Install lib32gcc1 which you need to run hldsupdatetool.bin
# using a 64bit vesion of Debian or Ubuntu
sudo aptitude install lib32gcc1
# Run the updatetool
./hldsupdatetool.bin
# Let it update itself
./steam -command update
# Install TF2 (or any other game)
./steam -command update -game “tf” -dir .

A list of games available for install

Howto: Install Webmin on Ubuntu

Another very short howto on how to install Webmin on Ubuntu/Debian! :)

wget http://downloads.sourceforge.net/sourceforge/webadmin/webmin_1.480_all.deb?use_mirror=kent
sudo dpkg -i webmin_1.480_all.deb
sudo apt-get -f install

That’s all there is to it, you can now login to webmin at https://localhost:10000/ if you are connecting to it locally.

Mind you Webmin is not secure!! I only recommend this if you know how to secure your machine yourself.
I currently only use it on machines which are in a closed off LAN, never allowing connections to port 10000 from outside (the default Webmin port).
You could think about changing the port, or using SSH tunnels with a browser to connect to it.

Howto: Move Software RAID1 to Other Machine or New Installation (Ubuntu/Debian)

Short howto on recovering a software RAID1 array using Debian / Ubuntu (after moving it to another server/reinstalling OS)

sudo mdadm –scan –assemble /dev/md2 /dev/sdc1 /dev/sdd1
sudo mkdir mount
sudo mount /dev/md2 mount/
  • /dev/md2 is the new name of the raid array
  • /dev/sdc1 is the name of the first drive which was part of the array
  • /dev/sdd1 is the name of the 2nd drive
  • you can discover the various drives connected to your system using “sudo blkid”

It couldn’t be easier

Howto: Wordpress on SliceHost or VPS with SFTP and SSH

Introduction

Let me start off by explaining why I wrote this tutorial. I have been hosting with SliceHost for quite some time now, and decided to mess around with Wordpress a bit instead of building something from scratch. After downloading and installing Wordpress I noticed it wanted FTP login details to install plugins etc from the Admin interface. That was a problem as I only have SSH / SFTP acces. (I never setup an FTP server because it would just take up more memory, I have a 256MB slice/vps.) Anyways, I was in a bit of a pickle, I didn’t want to have to upload each plugin by hand and then manually install through the admin section. Then I found some tutorials on how to set up SSH support in Wordpress, but they were a bit unclear. Hence my reason for writing this.

More >