Tuesday, 18 September 2012

Creating a Bare Git Repository and Polling it

What we are trying to do is create a database on one machine, dump it in a way which is most diff friendly and commit the dump to a change control system (git).

On another machine we want to poll git and when there is a change rebuild the database.

Creating a Bare Repository

A bare repository is one which does not have a working copy checked out.

A bare repository is how you implement a system similar to a CVS or SVN repository: a hub repository.

sudo su
apt-get install git-core
cd /srv
mkdir git
mkdir git/repository.git
cd git/repository.git
git init --bare

cd ..
chown -R jenkins:tomcat7 repository.git


To create the database on another machine first time through:

git clone timp@app4.wwarn.ox.ac.uk:/srv/chassis-data/git/repository.git
cd repository 
echo 'create database r2;' |mysql -u root

mysql -u root r2 < repository.sql

Now we can poll for changes:

git fetch > build_log.txt 2>&1
if [ -s build_log.txt ]
   git pull
   echo 'drop database r2;' | mysql -u root
   echo 'create database r2;' | mysql -u root
   mysql -u root r2 < repository.sql

Then just pop it into Jenkins

Monday, 17 September 2012

Ensuring Jenkins can delete files created by Tomcat7

The problem is that Jenkins is not root. In the past the work Jenkins is doing would be done by root invoked from cron.

Our scenario is to build and deploy to Tomcat7 and then invoke the deployed web service from Jenkins. The web service downloads a lot of files to a cache. Once a week we want to clear the cache, from Jenkins, but the files in the cache are owned by Tomcat7.

The solution is to put Jenkins and Tomcat7 into the same group.

Edit the tomcat startup script /etc/init.d/tomcat7 and change the umask value to 002.

if [ -z "$JAVA_HOME" ]; then
log_failure_msg "no JDK found - please set JAVA_HOME"
exit 1
if [ ! -d "$CATALINA_BASE/conf" ]; then
log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
exit 1
log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT6_USER --exec "$JAVA_HOME/bin/java" > /dev/null; then
# Regenerate POLICY_CACHE file
umask 002
echo "// AUTO-GENERATED FILE from /etc/tomcat6/policy.d/" > "$POLICY_CACHE"
echo "" >> "$POLICY_CACHE"
cat $CATALINA_BASE/conf/policy.d/*.policy >> "$POLICY_CACHE"

Make Jenkins a member of the tomcat7 group.

usermod -G tomcat7 jenkins

Restart tomcat7 and Jenkins

/etc/init.d/tomcat7 restart
/etc/init.d/jenkins restart

change premisions on existing cache

chmod -R g+w .

Run Jenkins manually:

The job should succeed next weekend.

Friday, 14 September 2012

Rebuilding MySQL databases without filling your disk

To reclaim disk space used by an old MySQL database it is not sufficient to drop the database. This is a famous 2003 bug. It is unbelievable that an infrastructure element as crucial and ubiquitous as MySQL has any outstanding bugs, let alone loads.

Assuming you are using InnoDb tables (the only sane choice if you want normal SQL functionality, such as transactions) then by default the data will be stored all on one big file. You will not be allowed to move the data unless you configure appArmor.

Another approach is to dump, drop, delete and recreate your databases.

Machine spec

The machine is a VM running Ubuntu

Linux version 3.2.0-23-generic (buildd@crested) (gcc version 4.6.3 (Ubuntu/Linar
o 4.6.3-1ubuntu4) ) #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012

The default MySQL setup is not great so setup some more sensible ones. Additionally lest put databases in separate files:



I am, writing this from the position of recovering from a filled disk, with a single innodata1 file. I have more space on another partition but you cannot just use a symlink because of this bug. So the first we need to get to a working position, DON'T

cd /var/lib/mysql
rm ibdata1
rm ib_logfile0
rm ib_logfile1

So lets move our modified /etc/mysql/my.cnf out of the way and reinstall mysql.

mv /etc/mysql/my.cnf . 
apt-get remove --purge mysql-server
apt-get install mysql-common
apt-get install mysql-server

However this still left stuff hanging around, so:

rm -rf /etc/mysql
rm -rf /var/lib/mysql

Then reinstall and copy our saved config back:

apt-get install mysql-server
/etc/init.d/mysql stop
cp ~/my.cnf /etc/mysql/
/etc/init.d/mysql start


apt-get install apparmor-utils
aa-complain /usr/sbin/mysqld


apt-get remove --purge apparmor
/etc/init.d/mysql stop
cp ~/my.cnf /etc/mysql/
/etc/init.d/mysql start

/etc/init.d/mysql stop
rm /var/lib/mysql/ib_logfile0
rm /var/lib/mysql/ib_logfile1
/etc/init.d/mysql start

Setup mysql user

create user 'repo_builder'@'localhost' identified by 'scrt';
grant all privileges on *.* to 'repo_builder'@'localhost' with grant option;

create database chassisPruned;
create database curated_files;

Restart Jenkins then kick off the job

/etc/init.d/jenkins start

Just need to enable this process to be repeated before each build...

Tuesday, 11 September 2012

HTC Desire Android will not power off - SOLVED

My HTC Desire lost the ability to power off. Holding down the off button would send it to sleep, but the power down menu no longer appeared.

Initial googling suggested that this was due to an update, but as my wife and i have the same model on the same network I thought that unlikely.

I found the answer here Lost power menu (Android Revolution HD™ 6.1.1), it is described as an odd bug in 6.1: the issue with this can be resolved by activating secure credentials. go to settings, security and check use secure credentials and you'll be able to access your power menu again

Goto Settings/Security/Use secure credentials
(This will only be available if you have set a password for the credential store)
Check Use secure credentials.
Magic: power down now works.
you can uncheck it again and it continues to work.