Tuesday, 16 October 2012

The truth about blogging the truth about health research: blogged

I attended a quick, lunchtime, course entitled Blogging the truth about health research.

Sadly @cebmblog could not attend, but ably deputised by @peterjgill.

This course was a quick tour of why the social web is important for primary care researchers.

Blogging helps to formulate your own thoughts.

It enables you to gain a style understandable by non-academics.

Blogging bypasses peer review, which is great for junior academics.

By informing others of your views before you meet in person blogging can enable the most productive use of face to face time.

Case study Rosiglitazone: the debunk message did not get out.

Sadly the lack of debunking led to a number of deaths before the drug stopped being widely used.

Case study: twitter as a collaborative tool

Autism brain scan: 20 adults with vs 20 without. 90% accuracy!!

This paper was summarised in a Wellcome Trust press release.

@bengoldacre tweeted that he could not find the original paper.

@cebmblog tweeted the original and blogged it. This was picked up by the Guardian and led to the press release being altered.

Twitter enables you to participate in the hive mind.

Trial by twitter: can be a bit traumatic.

PLOS - Measuring the impact of research

Before the web there were only slow, late methods of measuring research's impact

  • peer review
  • citation counting

PLOS - altmetrics

PLOS enables a number of measures of a papers impact. Altmetics are more nuanced and detailed

  • more complex
  • measure aggregate impact of research
  • fast and open
  • track impact outside of academia

Rather preaching to the choir, as far as this blogger is concerned, but a very good session, which gave us all something to think about.

Adding launcher icon for STS to Ubuntu 12.04

Googling for ubuntu add menu icon is an unfruitful experience, as Ubuntu keep changing the default windowing system.

I eventually had more luck with unity sts launcher

With the help of a colleague I arrived at:

  1. Create a file called ~/.local/share/applications/sts.desktop
    [Desktop Entry]
    Name=STS
    GenericName=Spring Tool Suite
    X-GNOME-FullName=Spring Tool Suite
    Comment=Java Editor from SpringSource
    Exec=/home/timp/bin/sts
    Icon=/home/timp/springsource/sts-3.1.0.RELEASE/icon.xpm
    Terminal=false
    Type=Application
    Categories=GNOME;
    StartupNotify=true
    X-Ubuntu-Gettext-Domain=sts
    
    
  2. Invoke by searching for sts in Unity search ("Unity Dash Home")
  3. When application is invoked right click on menu icon and click Lock to Launcher

Note that full paths are required for files referred to in the .desktop content model; tilde form file names do not work.

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

Done.

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 ]
then
   git pull
   echo 'drop database r2;' | mysql -u root
   echo 'create database r2;' | mysql -u root
   mysql -u root r2 < repository.sql
fi

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.

start)
if [ -z "$JAVA_HOME" ]; then
log_failure_msg "no JDK found - please set JAVA_HOME"
exit 1
fi
if [ ! -d "$CATALINA_BASE/conf" ]; then
log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
exit 1
fi
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:

[mysqld]

innodb_file_per_table

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

FAT CHANCE.


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

NOPE


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.

Tuesday, 7 August 2012

Trusting a secured Maven repository

There are two parts to this

Set up ~/.m2/settings.xml

<settings 
    xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"> 
  <servers> 
    <server> 
       <id>wwarn-read</id> 
       <username>mavenuser</username>
       <password>*****</password>
    </server>
<!-- for deployment -->
    <server>
      <id>wwarn</id>
      <username>user</username>
      <privateKey>/home/user/.ssh/id_rsa</privateKey>
      <passphrase>mypassphrase</passphrase>
      <directoryPermissions>775</directoryPermissions>
      <filePermissions>664</filePermissions>
    </server>
  </servers> 
  <profiles> 
    <profile> 
      <id>wwarn</id> 
      <activation> 
        <activeByDefault>true</activeByDefault> 
      </activation> 
      <repositories> 
        <repository> 
          <id>wwarn-read</id> 
          <url>https://maven.wwarn.org/</url> 
        </repository> 
      </repositories> 
    </profile> 
  </profiles>
</settings>

See http://maven.apache.org/guides/mini/guide-deployment-security-settings.html

Set up self-signed cert from maven.wwarn.org

The default password really is changeit. I would advise not changing it :)


sudo su
scp maven.wwarn.org:/etc/ssl/certs/server.crt .
cp /etc/ssl/certs/java/cacerts /etc/ssl/certs/java/cacerts.$$.bak
# The default password is changeit
# If this is the second time through
keytool -delete -alias wwarn-maven-repo -file server.crt \
  -keystore /etc/ssl/certs/java/cacerts
keytool -import -alias wwarn-maven-repo -file server.crt \ 
  -keystore /etc/ssl/certs/java/cacerts

Or on windows something like


keytool.exe -import -file c:\users\richardc\Desktop\stuff\server.crt -alias maven.wwarn.org -keystore "C:\Program Files\Java\jdk1.6.0_21\jre\lib\security\cacerts"