Flask-SQLAlchemy ssl-connection

It took some time before realising that client certs and keys can be specified on the connection uri while setting config values. Like this:

SQLALCHEMY_DATABASE_URI: mysql://user:password@hostname/db?ssl_key=ssl/client-key.pem&ssl_cert=ssl/client-cert.pem

Where ssl/ is a relative path from the calling app.

Later on you can confirm that the connection really was over ssl with something like:

res = db.session.execute("SHOW STATUS LIKE '%ssl%'")
for r in res:
print r

You’ll then see some info regarding your connection.

Set mtime with part of filename

Needed to go through a directory of backuped files and set the mtime. The files had the format x-yymmdd.sql.gz A recent copying of the directory had removed the original mtime attributes (note to self: use rsync with -a flag next time).

This one liner did the trick of converting them back to what they had:

for f in *.sql.gz; do touch -d $(echo $f | \
sed "s/^\w\+-\([0-9]\{2\}\)\([0-9]\{2\}\)
\([0-9]\{2\}\).*/20\1-\2-\3/") $f; done

Could this be improved? Most certainly. I havent figured out how to do repetitions in a good manner in regex

tracd with upstart on Ubuntu

After spending too many hours trying to get tracd running as a daemon on Ubuntu 10.04 I might as well share my experiences. At first I begun with  some init.d scripts I found googling for tracd init.d. The problem with them was that they were made to run tracd as root which frankly didn’t feel that great. I tried to modify them to use the –user/–chuid options to no avail. In the end I understood that the problem was not those options but that the pid file I was trying to use with the tracd command for some reason couldn’t be written.

These mishaps wasn’t only bad as I therefor started fiddling with upstart. upstart is a much more pleasant experience than classical init scripts. All I had to do was to create the file


and put

description "tracd server"
author "KO"

start on startup
stop on shutdown

expect daemon

        exec sudo -u www-data /usr/bin/tracd --daemonize --port=8000 \
	--hostname= -s /path/to/trac/project
end script

in it.

The key here was the expect daemon stanza which saved my day. After that you can use start|stop|status processname like:

sudo start tracd

Now you might wonder why I wanted to run tracd as a daemon. I was about to switch to nginx on the server running trac and the daemon way seemed the easiest.