Monday, June 14, 2010

Rhodes + Android + Eclipse + Ubuntu 10.4

In an attempt to start using Rhodes to build an Android app, I'm building my local dev environment, hence the title "Rhodes + Android + Eclipse + Ubuntu 10.4".

Handy pages:
Installing ruby and some essentials

So.. let's start at the beginning, we'll need Ruby, rails and rubygems (which is now in the repros - change the X.X below for the latest version - use tab-complete to the the options).
sudo apt-get install ruby-full build-essential rubygemsX.X
Installing rhodes

Once we have done that, let's get rhodes (version 2.0 is currently in beta)
sudo gem install templater
sudo gem install rake
sudo gem install rails
sudo gem install rhodes --pre
Irritatingly, the apt-get install of rubygems doesn't add the path of the gems that we later installed to the PATH... doh! Have a look where rubgems has been installed to - should be something like "/usr/lib/gems/1.9.1/" although the last directory name will clearly depend on what version you installed above. Open up ~/.bashrc and add (thanks to adamtao):
PATH = "${PATH}":/var/lib/gems/1.9.1/bin
export PATH
You also need to install eclipse and the Android SDK and NDK. I'm not going to list the routine for getting it done since it's explained well elsewhere. Setup for android development including getting all the files from the android development site. Setup an Android AVD (Android virtual device) and test the emulator with a simple hello world script.

Setting up rhodes

Now we need to link our rhodes installation to the SDK and eclipse.
rhodes-setup
You'll be prompted with questions - my answers are below:
  • JDK path: /usr/lib/jvm/java-6-openjdk/
  • Android SDK path: /opt/androidSDK/
  • Android NDK path: /opt/androidNDK/
  • the remainder of the questions related to Windows and Blackberry: (left blank)
Helpful way to find paths is to either look in your path (echo $PATH) or use "locate" (locate java > java_list) and then look in the java_list file that has just been created.

Create a soft link to the rhodes directory:
sudo ln -s /var/lib/gems/1.9.1/gems/rhodes-2.0.0.beta9/ /var/lib/rhodes
First application

So, for now, I'm going to work via the command line and with gedit to edit files; using tutorial2 as a starting point:
  • rhogen app testapp
  • cd testapp
  • joe build.yml
    I wanted to remove the iphone refs and add in some android ones
sdk:"/var/lib/gems/1.9.1/gems/rhodes-2.0.0.beta9"
sdkversion: 2.0.0
name: testapp
version: 1.0
vendor: rhomobile
build: debug
bbver: 4.6
applog: rholog.txt
android:
version: 2.1
extensions: ["extension-name-here", "second-extension-name"]
  • rake run:android
You'll be asked if you want to setup hardware - type yes and answer the questions.

When you have finished, and want to uninstall the app:
  • rake uninstall:android


More to come as a work through the process

Smartphone app development

At radiopaedia.org, we have had iPhone apps for a while - and they are great. However, with a growing userbase that is using Android and other platforms, we'd really like to expand our apps and develop our teaching files for Android too.

Given the usual mantra of "okay, I'll give it a go", I'd launched myself head first into Android app development. My coding background is traditional webdesign - HTML, PHP, CSS and a little bit of javascript (which has been increasing lately with the use of Jquery).

So, the Java environment that is Android development is completely new to me. After a late night and a little bit of progress, I was pointed in the direction of Rhodes - a Ruby-based development stack that allows traditional HTML, CSS and javascript for designing your app and a Ruby backend for the MVC part of the app.

It sounds amazing - and what's better is that you can take your Rhodes app and build it as an iPhone app, Android app, windows mobile app... And it builds the Objective C++, Java etc. And, to give the apps a naitive feel, all you need to do is tweak the CSS - amazing.

For development, I could use RhoHub, an online SDK which looks pretty cool. But, if you want to create private apps with more than 3 contributors, you need to pay. So, I'm going to attempt to build a Rhodes development environment locally using the Android SDK and eclipse on Ubuntu 10.4 - with me luck!

Blogger templater

I'd heard about the new blogger templater, but hadn't had a chance to play with it. But, given that I'm just about to post another item to the blog about smartphone app development, I thought I'd have a play. And... I was duly impressed... and after a couple of clicks have a much improved look to the blog.

Monday, May 17, 2010

Local development with GIT and Plesk

I'm loving GIT. But, what I really wanted to do was to create a development environment locally that pushed changes to a server which was therefore always up to date.

So, I've got an Ubuntu (lucid) machine locally and an Ubuntu server running Plesk 9.x remotely.

Make sure that git is installed on both systems
sudo apt-get install git-core
Make sure that you setup Plesk to give the user shell access (bin/bash) in Web Hosting Settings.

Follow this helpful todo.

Easy! When you are working remotely to setup the git repro, you will need to be root - so remember to change the httpdocs and httpdocs.git directory permissions back to "username:psaserv" and do it recursively:
chown -R username:psaserv httpdocs
chown -R username:psaserv httpdocs.git
Passwordless login and git clone

It's worth while setting up passwordless login:
ssh-copy-id -i .ssh/id_rsa.pub username@domainname.tld
Then, the command to get the git repro locally becomes:
git clone ssh://username@domainname.tld/var/www/vhosts/domainname.tld/httpdocs.git
Setup apache

You'll need to make sure the apache2, php5 are installed:
sudo apt-get install apache2 php5
You need to setup apache by editing the conf file: /etc/apache2/sites-available/default. If you are going to run multiple local sites, you'll have to declare them here. For each site, add the following:
<VirtualHost *:80>
ServerName localservername
DocumentRoot /home/sites/location/httpdocs/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/sites/location/httpdocs/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
You also need to edit /etc/hosts to provide a route to your local server. Add a line:
127.0.0.1 localserver

Setup database forwarding

We could just setup mysql or other database locally. However, then you need to try and keep local and remote databases synced. If you are just reading, it's much simpler to setup an ssh tunnel to your remote server.

While the ssh for the git clone was as a plesk user of the particular website, this ssh should be performed as a user of the server i.e. it should log you in a you, not as a website. You need to make sure that mysql is NOT running locally:
sudo stop mysql
And then, type
ssh -L3306:localhost:3306 remoteserver.tld
For ease, if you save this command to a file and put it in /usr/local/bin and then "chmod +x" it, you can simply type the name of the file (e.g. connect) and the tunnel will be set up.

Connecting to the tunnelled mysql db via PHP

The other piece of glue is to realise that you can't connect to the database as localhost, you have to use 127.0.0.1, e.g.:
mysql_connect('127.0.0.1', $username, $password);
All in all, a pretty successful development environment.


Saturday, December 26, 2009

VPS.net server install

Notes from a recent installation of Ubuntu server on a UK2 cloud server.

signup
login as root@

passwd
sudo apt-get install joe
joe /etc/apt/sources.list
apt-get update
apt-get upgrade
adduser username
usermod -G admin username

joe /etc/ssh/sshd_config (permitrootlogin no)
/etc/init.d/ssh restart

logout

ssh-copy-id -i .ssh/id_rsa.pub username@host.domain.tld

ssh username@host

wget http://download1.parallels.com/Plesk/PPP9/Ubuntu8.04/parallels_installer_v3.4.1_build090204.18_os_Ubuntu_8.04_x86_64

mv parallels_installer.... /tmp/
chmod +x file
sudo ./file

follow the instructions

log into the Plesk frontend
admin:setup

setup master user details

-> updates
- -> prefs -> Check for updates upon administrator's login to control panel [Y]

-> Settings
- -> Spam Filter Settings -> Switch on server-wide greylisting spam protection [Y]

-> Control Panel Interface
- -> Interface Management

apt-get install munin-node
joe /etc/munin/munin-node.conf

#
# Example config-file for munin-node
#

log_level 4
log_file /var/log/munin/munin-node.log
port 4949
pid_file /var/run/munin/munin-node.pid
background 1
setseid 1

# Which port to bind to;
host *
user root
group root
setsid yes

# Regexps for files to ignore

ignore_file ~$
ignore_file \.bak$
ignore_file %$
ignore_file \.dpkg-(tmp|new|old|dist)$
ignore_file \.rpm(save|new)$

# Set this if the client doesn't report the correct hostname when
# telnetting to localhost, port 4949
#
#host_name localhost.localdomain
host_name [luffness.konsulting.ltd.uk]

# A list of addresses that are allowed to connect. This must be a
# regular expression, due to brain damage in Net::Server, which
# doesn't understand CIDR-style network notation. You may repeat
# the allow line as many times as you'd like

allow ^127\.0\.0\.1$
allow ^80\.2\.73\.137$

****************************
[monitoring server]
joe /etc/munin/munin.conf

[craigielaw.konsulting.ltd.uk]
address 83.170.83.182
use_node_name yes

***************************

** install mysqltuner
wget mysqltuner.pl
chmod +x mysqltuner.pl
sudo mv mysqltuner.pl /usr/local/bin/mysqltuner

** alter crontab
** allows a weekly email to test for upgrade and mysql tuning options
sudo crontab -e
add:
MAILTO=server@klever.co.uk
17 3 * * 3 apt-get update; apt-get upgrade -sy
17 4 * * 5 /usr/local/bin/mysqltuner

Monday, September 28, 2009

Ubuntu fonts

Get a raft of fonts for Ubuntu with a simple apt-get
sudo apt-get install ttf-sil-gentium ttf-dustin ttf-georgewilliams ttf-sjfonts sun-java6-fonts ttf-larabie-deco ttf-larabie-straight ttf-larabie-uncommon
Any, if Microsoft fonts are required:
sudo apt-get install msttcorefonts
Works a treat.. and you could do worse than gnome-specimen for a font previewer.

Monday, September 14, 2009

Load alert

I've been having an issue with a server whose load sporadically runs high. While trying to work out what the problem was, I needed a way to know when the load peaked.

I modified a simple script to allow me to do just that and then ran it from cron. Only problem is that if it detects a high load, an email is sent each time the cron is run (maybe every 5 minutes!)
!/bin/bash
avg=`uptime | awk '{print $8" " $9 " "$10 $11 $12 }' | tr -s , " "`
cur=`uptime | awk '{print $10}' | tr -d , | cut -d. -f1`
str="============================="
info="Curent $avg"
if [ $cur -ge 1 ]; then
info1="Server load is high presently"
touch /tmp/tmp.00
echo -e "$str\n$info\n$info1\n$str\n" >> /tmp/tmp.00
ps aux | head -1 >> /tmp/tmp.00
ps aux | sort -rn +2 | head -10 >> /tmp/tmp.00;
mail -s "Alert: Load Average for `hostname` on `date` " jeremy@yourdomainnamehere.com < /tmp/tmp.00;
rm -f /tmp/tmp.00
else
#echo -e "$str\n$info\n$str"
fi
Cron might look something like this:
*/5 * * * * /usr/local/bin/loadaverage