Setup your own deb repository

It is difficult to setup a Debian repository that is signed and can handle multiple versions of any single package. I went through many different packages and tutorials in how to setup my own Debian repository and it was a pain to find a method that works. My two requirements might be specific to my needs but they give the user the ability to do these two things.

The signed part allows automated scripts to upgrade a package as it allows the following.

sudo apt-get -y install <package>

The ability to handle multiple versions of the same package would allow the user to install which ever version of the package with the following command example

sudo apt-get -y install <package>=<version>

Generate a gpg key

We need a gpg key to sign our packages and repository. So let’s generate one before setting up freight.

gpg –gen-key

Select option 4 RSA (sign only)

Fill out all the information that it asks.

Note: Be sure to add an email. It will be needed to configure freight.

One thing that will happen most likely is that there is not enough entropy to generate the key and it waits for entropy. I found a good way to generate some entropy is to run stress. Open another terminal to install and run stress while leaving the gen key running.

sudo apt-get install stress

stress –hdd 8 –io 8

If you want to watch the available entropy get generated, open another terminal and watch with this command

watch cat /proc/sys/kernel/random/entropy_avail

Installing Freight

The package that I found to handle both my requirements was freight. The instructions are there, but I will document what I did just to be complete.

I installed via apt-get and so I needed to add the third party source list before installing

echo “deb http://packages.rcrowley.org $(lsb_release -sc) main” | sudo tee /etc/apt/sources.list.d/rcrowley.list

sudo wget -O /etc/apt/trusted.gpg.d/rcrowley.gpg http://packages.rcrowley.org/keyring.gpg

sudo apt-get update

sudo apt-get -y install freight

Configuring Freight

Copy the example conf

sudo cp /etc/freight.conf.example /etc/freight.conf

Edit the freight.conf and add

GPG=”emailfromgpgkey@mydomain.com”

Add deb packages

Take a deb file you already created and added to the repository. The apt/squeeze, etc arguments are the different distros where the deb should be published.

freight add foobar_1.2.3-1_all.deb apt/squeeze apt/lucid apt/natty

Build the cache

freight cache

Setting up Nginx

Now we need to serve out the repository over http. You can use any web server to do this. I chose Nginx and here is the setup procedure.

sudo apt-get install nginx

Setup hosting file

cd /etc/nginx/sites-available

sudo vi mydomain.com

Put something like this into the site configuration file

server {
listen 80;
server_name mydomain.com;
access_log /var/log/nginx/mydoamin.com.access.log;
error_log /var/log/nginx/mydomain.com.error.log;

location / {
alias /var/cache/freight/;
}
}

Enable the new site

cd /etc/nginx/sites-enabled

sudo ln -s /etc/nginx/sites-available/mydomain.com mydomain.com

Restart Nginx

sudo service nginx restart

Consume packages

Now to install the packages from your new repository on a Debian machine, add the source list and the key

echo “deb http://mydomain.com $(lsb_release -sc) main” | sudo tee /etc/apt/sources.list.d/mydomain.list

sudo wget -O /etc/apt/trusted.gpg.d/mydomain.gpg http://mydomain.com/keyring.gpg

Now you can do the normal apt-get procedure to install a package

sudo apt-get update
sudo apt-get -y install foobar

Getting Ionic framework running on Ubuntu

Very frustrating when it appears that Ionic setup is as simple as http://ionicframework.com/getting-started/ to get a helloworld running. But I received all kinds of errors when following those simple instructions. Primarily, there were Cordova dependencies that were missing and are not installed if you only follow Ionic instructions.

So here they are. After installing cordova and ionic

sudo npm install -g cordova

sudo npm install -g ionic

Install ADT

http://developer.android.com/sdk/index.html#download

Unzip to somewhere that makes sense for you on your home dir

Add paths

edit your .bashrc and add this to the bottom

export PATH=$PATH:/[path to adt]/adt-bundle/sdk/platform-tools:/[path to adt]/adt-bundle/sdk/tools

Save your .bashrc then run

source ~/.bashrc

Then install ant

sudo apt-get install ant

Then create a AVD

android create avd -n <name> -t <targetID>

you can list targets to see what you have available

android list targets

Now that everything else is installed and an AVD is created, you can continue with the Ionic instructions.

$ cd myApp
$ ionic platform android
$ ionic emulate android
$ ionic run android <-- still getting an error on this one

 


	

Laravel, another php framework to explore

Laravel is a framework in the same class as Codeigniter. However, at first glance it implements a couple of annoying missing features I’ve waited a longtime for CI to add but have yet to do it: full unit-testing and ORM. For ORM, there have been many third party addons/sparks that would add the functionality but not from base install. Unit testing is a much bigger problem in CI. There is no good way to integrate php-unit or simpletest to test your code. So we are left trying to unit test with the joke implementation of unit testing library from CI.

I’m hoping Laravel will prove to be as amazing as what people have been raving about in the blogsphere. Can’t wait to give it a shot.

Codeigniter header already sent error using json header

Getting this error when moving from development server to staging server and getting this error.

Severity: Warning –> Cannot modify header information – headers already sent

The error shows up if you are doing all of the following.

1. Change header using

$this->output->set_content_type(‘application/json’);

2. Outputting using echo (which is not recommended by Codeigniter).

3. In php.ini, have output_buffering set very small, like 0.

Solution

There are two solutions to this issue.

1. Increase the output_buffering enough so to buffer your echo. (this is a hack)

2. Recommended solution is to replace echo with CIs built in $this->output->set_output(‘content’) method.

Codeigniter running into some major growth issues

I have been using Codeigniter for a while on many projects and it had been very useful as it is non-intrusive. Its very small footprint also allows for the extremely good performance on page loads. However, these projects were simply using just the CI core and not implementing any plugins. Some base classes have been extended, but purely specifically for the individual project so not causing any conflict with other code.

Recently, I started building a startup project using CI and would like to employ more plugins do speed up development. Pleasantly surprised, I found that CI had implemented Sparks for searching and installing plugins to CI. Great right! So I implemented an ORM called DataMapper and it was brilliant.

Here comes the reality check. After upgrading from CI 2.0.2 to 2.0.3, everything broke. Why? Because CI changed a lot of methods within its core classes from public to protected. That of course is not actually a bad thing as it was in fact incorrectly implemented before allowing a developer to mess with core functionality too much. However, through researching into these issues, I came to a huge realization that I missed about CI before. CI only allows plugins and developers to modify core classes by extending them into MY_core_class.php. If multiple plugins need to extended the same class, even if they need to overload different methods, it requires some code merging by the developer. If the plugins need to overload the same method in the same core class, that becomes a huge undertaking for the developer to understand what each plugin is trying to do and write merged code that works for both in the same overloaded method.

After that realization, I have determined that CI is fine for applications that are going to use mainly the core classes. If you intend to implement plugins, be very careful understanding what core classes each one will extend. Choose wisely. If those requirements cannot be met, look for another framework.

Replacing OpenGeo Suites on Windows with GeoServer on Linux

After our initial installation of OpenGeo Suites for WMS service on Windows, we encountered some stability issues that could not be resolved. We could have hired some high priced consultants to debug the issue but we opted for a lighter weight infrastructure.

Our initial system specs:

  • Windows Server 2008
  • 4GB ram
  • Quad core
  • Open Geo Suites running as Windows application

Our slim and fast system specs:

  • Ubuntu 10.04
  • 512MB ram
  • Quad core
  • GeoServer running as java process

So far so good. All layers are loading super fast. We will see how the stability issue is resolved. At least we are using a lot few resources now which makes scaling out to a cluster of GeoServers much more affordable.

Running stored procedures on MSSQL via any language on Linux

If you need to run store procedures on Microsoft SQL Server on perl, php, ruby, etc., you need to configure /etc/freetds/freetds.conf with the server connection information. Specifically, specify the tds version to be 8.0. Something like the following.

/etc/freetds/freetds.conf

[Server80]
host = domain.com
port = 1433
tds version = 8.0

Connection to the server via php would look like this.

$link = mssql_connect("Server80", "user", "pass");

Scaling down from MS to open source

We just moved a service that was running on the Microsoft stack (Windows Server 2008, .NET, MSSql Server, IIS) to an open source stack (Ubuntu Server, php, Codeigniter framework, apache2, postgres).

We now run the service on a cloud server with dual cpu and 256MB ram (Yes, that’s megabytes).

The old server ran on dual core with 2GB of ram.

sendmail[2525]: My unqualified host name (servername) unknown

If you see these messages in your syslog, your sendmail is not configured correctly with the domain name. If you are sending from a fully qualified domain, add it to the local-host-names file. In Ubuntu, it would be /etc/mail/local-host-names. Make sure it reads something like this.

localhost
[domain.com]
[server name]

Now in the /etc/hosts, make sure it reads the following.

127.0.0.1 [domain.com] [server name] localhost

Then

sudo /etc/init.d/sendmail restart

and the error should not continue filling the syslog.