cron pgrep reload a process/service

The problem with

36 * * * * pgrep -f 'puppetd' > /dev/null 2>&1 || /etc/init.d/puppet restart

is that the pgrep matches
/bin/sh -c pgrep -f puppetd ... when the whole line is launched by cron.

You need to use a more complex pattern like ^ruby.*/puppetd:

36 * * * * pgrep -f '^ruby.*/puppetd' > /dev/null 2>&1 || /etc/init.d/puppet restart

clone WordPress blog

I couldn’t find any receipt to clone a WordPress blog. A user needed to have a test copy of his blog.
Here is mine. I hope it can be useful to others.

Copy the WP:

cd /path/to/myblog
cd ..
cp -a myblog test-myblog
cd test-myblog
vi wp-config.php # adapt DB_NAME DB_USER DB_PASSWORD
for f in `grep myblog . -rl` ; do perl -pi~ -e 's/myblog/test-myblog/g' $f; done

Prepare the DB for the clone:

mysqldump -u root -p -B blog_myblog > blog_myblog.dump
vi blog_myblog.dump
# :%s/blog_myblog/blog_test_myblog/g
# :%s/myblog/test-myblog/g
perl -pE 's/(s:(\d+?):\\"([^"]*?test-myblog[^"]*?)\\")/ "s:" . (${2} + 5) . ":\\\"$3\\\"" /eg' blog_myblog.dump > blog_test_myblog.dump
# NOTE: 5 is the character difference between "myblog" and "test-myblog"

This is the magic here. Because WordPress stores string lengths along with strings in the DB.
We need to adapt them in the dump to be imported into the new DB for the clone. Otherwise, the clone won’t be fully functional.
Of course, a quicker alternative is to chose a name with the same length.

Create the database for the clone:

mysql -u root -p < blog_test_myblog.dump
mysql -u root -p
CREATE user "myuser"@"localhost";
SET password FOR "myuser"@"localhost" = password("secret");
GRANT ALL ON blog_test_myblog.* TO "myuser"@"localhost";

Adapt the apache conf:

vi /etc/apache2/sites-available/myblog
/etc/init.d/apache2 reload

systemctl zsh completion

While starting to write a completion function for systemctl, I found out there was already an existing completion script for bash shipped with systemd: systemctl-bash-completion.sh. I tried to use it in zsh (using bashcompinit) but encountered errors. So I finished my zsh completion function, now inspired from _yum …and bash-completion.sh. It should be reasonably helpful. Comments are very welcome.

It can be found on my github account

concert Origamini

4 mars 2011
19:00au22:00

Concert au Musée des Beaux-Arts de Lyon avec l’ensemble Origamini