Archive for the ‘Linux’ Category

SmudgeVMM – Svmm – Smudgeit Virtual Machine Manager

Posted on February 15th, 2010 in Cakephp, Linux, PHP | No Comments »

I’m currently involved in a a new php project that will allow users to manager Xen virtual containers, through a simple web interface or robust API.

SmudgeVMM is being written in CakePHP and will run as a stand alone webservice, on any Centos Xen server.

Features include: Multiple interfaces (WAN and LAN), SAS storage (iscsi and NAS), package templates, support for most flavors of linux, integration with most hosting shopping carts, reseller and multi user level permissions along with complete Xen VPS container management.

Share/Save/Bookmark

Reducing an ext3 Logical Volume’s Size

Posted on January 14th, 2010 in Linux | No Comments »

Here are the commands to reduce an ext3 file system and also the Logical Volume that holds it.

Warning please make sure you leave enough space for the files inside, or data may be lost.

First make sure the files system isn’t mounted then.

e2fsck -f /dev/VolGroup00/disk1_rootimg
resize2fs -p /dev/VolGroup00/disk1_rootimg 15G
lvreduce –size 15G /dev/VolGroup00/disk1_rootimg
resize2fs /dev/VolGroup00/disk1_rootimg

This should reduce the file system to 15G

Share/Save/Bookmark

Generating a file list, for a Joomla Component XML info file

Posted on December 8th, 2009 in Apple OSX, Linux, PHP | No Comments »

I’ve had to do some work for a company recently.

It involved me creating Joomla components and those annoying XML files, listing all the files and folders to install.

If you want a quick command to generate the xml, you can cd to the directory then run

find * -type f -exec  echo ‘<filename>’{}’</filename>’ \;

find * -type d -exec  echo ‘<folder>’{}’</folder>’ \;

Then you can copy the output from the terminal and paste between the files tags.

<files folder=”components/com_test”>
<filename>controller.php</filename>
<filename>css/test.css</filename>
<filename>views/test/tmpl/index.html</filename>
<filename>test.php</filename>
<folder>css</folder>
<folder>images</folder>
<folder>install_sql</folder>
<folder>models</folder>
<folder>player</folder>
<folder>views</folder>
<folder>views/user</folder>
<folder>views/user/tmpl</folder>
<folder>views/test</folder>
<folder>views/test/tmpl</folder>
</files>

I repeated this for the administrator/components/com_test and components/com_test folders

Share/Save/Bookmark

New VPS Server

Posted on July 6th, 2009 in Apache, Linux | No Comments »

I’m now running the site on a new Xen VPS server with Smudgeit. The site is running smoothly and no issues to report.
I chose to go with a UK Centos Xen VPS Server.

Share/Save/Bookmark

HyperVM Manual Alternative for creating Xen Domu using LVM

Posted on June 26th, 2009 in Linux | 2 Comments »

After the sad death of K T Ligesh I decided, like many people, to move away from HyperVM.

I searched and tried many control panels.

Openqrm – I found this over kill
karesansui – This is very nice looking and polished but seemed quite slow.
VDS Manager – Still in beta for Xen

I’ve now decided to create the VM’s by hand. I then hope to make a PHP control panel of my own. Here are my steps for creating Xen VPS’s using the command line and Centos 5.

I’m going to create a vm called testvm

First I needed to find out what Volume groups exist on my system and what the VG Name was

lvdisplay

VG Name                VolGroup00

Create the disks for the VM and format

lvcreate -L8.5G -n testvm_rootimg VolGroup00
lvcreate -L 384M -n testvm_vmswap VolGroup00
mke2fs /dev/VolGroup00/testvm_rootimg
tune2fs -j /dev/VolGroup00/testvm_rootimg
mkswap /dev/VolGroup00/testvm_vmswap

mkdir /mnt/img
mkdir /mnt/vm

Now mount your disk image. I’ve created a custom hardened Centos distro, but you could use Jailtime Images

mount -o loop centos.5-3.64-smudge.img  /mnt/img
mount /dev/VolGroup00/looop_rootimg /mnt/vm

Copy the image onto your new partition

cp -a /mnt/img/* /mnt/vm/

Now all you need to do is configure the hostname, ip etc on the VM.

vi /mnt/vm/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=static
IPADDR=87.xxx.xxx.xxx
NETMASK=255.255.255.xxx
ONBOOT=yes

Change the hostname

vi /mnt/vm/etc/sysconfig/network

If your using Jailtime images people have advised to change this line to the following:

vi /mnt/vm/etc/inittab
1:2345:respawn:/sbin/mingetty console

vi /mnt/vm/etc/ssh/sshd_config
PermitRootLogin yes

vi /mnt/vm/etc/fstab

Add the line:

/dev/sda2     swap   swap     defaults     0     0

umount /mnt/img /mnt/vm

You will need a ram disk to boot from. This can be created by running:

mkinitrd /boot/xen-guest-initrd `uname -r` –with xenblk –with xennet –preload xenblk –preload xennet.

Now all you need to do is create the config file and give it an IP/ Mac address.Please check which kernel you are using first and change – kernel = “/boot/vmlinuz-2.6.18-128.1.14.el5xen”…

kernel = “/boot/vmlinuz-2.6.18-128.1.14.el5xen”
ramdisk    = ‘/boot/xen-guest-initrd’
maxmem = 192
memory = 192
vcpus = 1
name = “testvm”
vif = [ 'ip=87.xxx.xxx.xxx,bridge=xenbr0, rate = 1000KB/s, mac=aa:00:23:b0:de:34' ]
serial     = ‘pty’
disk       = ['phy:/dev/VolGroup00/testvm_rootimg,sda1,w', 'phy:/dev/VolGroup00/testvm_vmswap,sda2,w']
root = ‘/dev/sda1 ro’
on_poweroff = ‘destroy’
on_reboot   = ‘restart’
on_crash    = ‘restart’

All is ready to go.

Just run:

xm create testvm

And you VPS should be now running:

check with
xm console testvm

Hope this helps.

Smudge IT will be lauching  a new site and Xen Vps systems soon. Watch this space..

Share/Save/Bookmark

Usefull Ffmpeg commands for creating FLV files

Posted on March 18th, 2009 in Linux | No Comments »

Converting to flv

ffmpeg -i Head Office Version.ts -ar 22050 -ab 128 -f flv -s 448×252 – | flvtool2 -U stdin video.flv

or with better bitrate

ffmpeg -i happy_feet_h.i480.mov -ar 22050 -ab 128 -b 800 -f flv -s  480×204 – | flvtool2 -U stdin happyfeet.flv

Generate thumbnail

This creates a thumb of 12 seconds into the video

ffmpeg -y -i head_office.flv -f image2 -ss 12 -vframes 1 -an head_office.jpg

Share/Save/Bookmark

Generating a thumbnail preview, of a video using PHP

Posted on March 16th, 2009 in Linux, PHP | No Comments »

This is just a one liner as my class uses lots of method etc that you probably don’t need.

The money shot is this:


if (! file_exists ( $thumb_dir . $thumbname )) {
$draw_thumb = shell_exec ( $this->ffmpeg . ' -y -i ' . $video_file . ' -f image2 -ss 10 -vframes 1 -an ' . $thumb_dir . $thumbname );
}

($this->ffmpeg = the location of the ffmpeg binary)

This will generate a thumbnail of the video at 10 seconds.

Share/Save/Bookmark

Detecting a videos dimensions using PHP and FFMPEG

Posted on March 16th, 2009 in Linux, PHP | 2 Comments »

Here is a method, that I pulled out of one of my video conversion classes.

All you need to do is set the location of ffmpeg ($this->ffmpeg)

It will then parse and return the video dimensions. More video methods to follow :)


/**
* Get the dimensions of a video file
*
* @param unknown_type $video
* @return array(width,height)
* @author Jamie Scott
*/
function __get_video_dimensions($video = false) {

if (file_exists ( $video )) {
$command = $this->ffmpeg . ' -i ' . $video . ' -vstats 2>&1';
$output = shell_exec ( $command );

$result = ereg ( '[0-9]?[0-9][0-9][0-9]x[0-9][0-9][0-9][0-9]?', $output, $regs );

if (isset ( $regs [0] )) {
$vals = (explode ( 'x', $regs [0] ));
$width = $vals [0] ? $vals [0] : null;
$height = $vals [1] ? $vals [1] : null;
return array ('width' => $width, 'height' => $height );
} else {
return false;
}
} else {

return false;
}

}

Share/Save/Bookmark

Converting a PDF file to text. Indexing a PDF file using poppler

Posted on March 10th, 2009 in Linux | 1 Comment »

This is another problem that I came across, as unoconv doesn’t let you convert a PDF to anything.

I found some more cool tools for handling PDF files.

The package is called poppler and can be installed on linux or if you are using OSX there is a macport.

Poppler is a PDF rendering library based xpdf

To install on linux run the command

yum install poppler-utils

On the mac install macports then run

sudo port install poppler

Now you have the following binaries at your disposal.

pdftotext, pdftohtml

You can generate a text version of a pdf by running

pdftotext -enc UTF-8 -eol unix input.pdf output.txt

I’m writing a PHP script that will talk to these binaries. I will upload soon.

Here is the man page for the binary:

NAME
pdftotext – Portable Document Format (PDF) to text converter (version 3.00)

SYNOPSIS
pdftotext [options] [PDF-file [text-file]]

DESCRIPTION
Pdftotext converts Portable Document Format (PDF) files to plain text.

Pdftotext reads the PDF file, PDF-file, and writes a text file, text-file. If text-file is not specified, pdftotext con-
verts file.pdf to file.txt. If text-file is ´-’, the text is sent to stdout.

CONFIGURATION FILE
Pdftotext reads a configuration file at startup. It first tries to find the user’s private config file, ~/.xpdfrc. If
that doesn’t exist, it looks for a system-wide config file, /etc/xpdf/xpdfrc. See the xpdfrc(5) man page for details.

OPTIONS
Many of the following options can be set with configuration file commands. These are listed in square brackets with the
description of the corresponding command line option.

-f number
Specifies the first page to convert.

-l number
Specifies the last page to convert.

-layout
Maintain (as best as possible) the original physical layout of the text. The default is to ´undo’ physical layout
(columns, hyphenation, etc.) and output the text in reading order.

-raw Keep the text in content stream order. This is a hack which often “undoes” column formatting, etc. Use of raw
mode is no longer recommended.

-htmlmeta
Generate a simple HTML file, including the meta information. This simply wraps the text in

 and

and
prepends the meta headers.

-enc encoding-name
Sets the encoding to use for text output. The encoding-name must be defined with the unicodeMap command (see
xpdfrc(5)). The encoding name is case-sensitive. This defaults to “Latin1″ (which is a built-in encoding).
[config file: textEncoding]

-eol unix | dos | mac
Sets the end-of-line convention to use for text output. [config file: textEOL]

-nopgbrk
Don’t insert page breaks (form feed characters) between pages. [config file: textPageBreaks]

-opw password
Specify the owner password for the PDF file. Providing this will bypass all security restrictions.

-upw password
Specify the user password for the PDF file.

-q Don’t print any messages or errors. [config file: errQuiet]

-cfg config-file
Read config-file in place of ~/.xpdfrc or the system-wide config file.

-v Print copyright and version information.

-h Print usage information. (-help and –help are equivalent.)

BUGS
Some PDF files contain fonts whose encodings have been mangled beyond recognition. There is no way (short of OCR) to
extract text from these files.

EXIT CODES
The Xpdf tools use the following exit codes:

0 No error.

1 Error opening a PDF file.

2 Error opening an output file.

3 Error related to PDF permissions.

99 Other error.

AUTHOR
The pdftotext software and documentation are copyright 1996-2004 Glyph & Cog, LLC.

SEE ALSO
xpdf(1), pdftops(1), pdfinfo(1), pdffonts(1), pdftoppm(1), pdfimages(1), xpdfrc(5)
http://www.foolabs.com/xpdf/

Share/Save/Bookmark

I’ve been asked to rewrite hostingspeeds.com v3

Posted on March 6th, 2009 in Linux | No Comments »

Taken from hostingspeeds.com

‘February 1, 2009 – “Thanks for your email. That’s great news.” winning coder Jamie Scott and owner of smudge-it.co.uk replied today when he found out he won. Jamie will code hostingspeeds.com into a full featured web 2.0 hosting speed measuring service for webmasters and web hosts with plugins for Wordpress, Joomla and other great blog and portal scripts ppl use these days.

Jamie Scott has won because of his programming skills, his experience with web hosting business and his understanding of what web 2.0 is all about. I thank all of you that offered to code v3.’ :)

I have already started rewriting the graphing code, so that the data is stored in RRD databases and there will be pretty graphs using RRDtool.

Example speed graph

The system will be fully scalable, by using a worker node system to poll the information and will encorporate a complex advertising and server monitoring system.

Share/Save/Bookmark