Converting an openvz to lxc container

To properly migrate an old openvz container to a new lxc container can be a bit tricky, but I finally succeeded to find a proper way with a minimal downtime.

It starts with a vzdump of the current container:

vzdump 108 --remove 1 --mode snapshot --compress lzo --storage backup09 --node clust-10 --bwlimit 0 --size 8192

–remove 1 says it’s allowed to remove the previous dump, if there is any
–mode snapshot says it’s making a live dump of a running container (no downtime)
–compress lzo is a light but efficient compress method
–bwlimit 0 is important if you can handle speeds over 80000 kb/s, which is default bwlimit
–size 8192 will fix input/output errors on certain lvm storages with low free diskspace

Above command will result in a file which you can use later in a pct restore command.

Directadmin: Cannot find the script

I was having some problems on different servers when i tried to reload a service.

It was displaying “Cannot find the script” for all services

This probably started when we upgraded to CB 2.0….

Anyhow you can fix this by editing the “/usr/local/directadmin/conf/directadmin.conf” and change/add the following value to: systemd=1

Reload DirectAdmin afterwords and you should be able to restart services from directadmin again.

 

Got error ‘Primary script unknown’ after update PHP-FPM + Apache 2.4

After a update_versions in DirectAdmin I got this error on a sites error log:

[client 1.2.3.4:62903] AH01071: Got error 'Primary script unknown\n'

The URL it self gave:

File not found.

Yesterday everything was working fine. After updating Apache 2.4.x and PHP-FPM (5.6) I figured it had to do something with those services.

But the app (CodeEgniter) was running in a subfolder. The main folder contained a WordPress install and was working fine.

So after some time I tried to play with the .htaccess file, and I succeeded. I changed this old .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteBase /fc2/

To this new variation:

RewriteBase /fc2/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /fc2/index.php [L]

Don’t ask me why, but the Primary script unknown is gone.

So in this case it had nothing to do with ProxyHandler, ProxyPass or other configuration issues between PHP-FPM and Apache. Just a little .htaccess error which results in a bug.

Days of the week array

This snippet will give you the days of the week but human-readable in your own language.

today=$(date +%u)
yesterday=$((today-1))

dagen=(
        'zondag'
        'maandag'
        'dinsdag'
        'woensdag'
        'donderdag'
        'vrijdag'
        'zaterdag'
        'zondag'
      )

today=${dagen[$vandaag]}
yesterday=${dagen[$gisteren]}

Now you can use $today and $yesterday as variables in folder names, usefull for back-ups.

Move Proxmox VM to another node

If you migrate a VM to another node via Proxmox it will rsync the server twice. But you never know how long the first one will take. So before I use the migrate function I use this little line to do a manual rsync.

This way I can rsync whenever I want and start the migrate on the end of the evening so the night will not take unexpected long 🙂

/usr/bin/rsync -aHAX --delete --numeric-ids --sparse /var/lib/vz/private/100 root@10.0.0.1:/var/lib/vz/private

Install SpamFighter and BlockCracking with Exim and dkim

This is what I use to set-up my DirectAdmin boxes with Exim, SpamAssassin, SpamFighter, BlockCracking and dkim.

cd /usr/local/directadmin/custombuild 

./build set clamav yes
./build set exim yes
./build set eximconf yes
./build set eximconf_release 4.4
./build set blockcracking yes
./build set easy_spam_fighter yes
./build set spamassassin yes
./build set sa_update daily

./build update
./build exim
./build clamav
./build spamassassin
./build exim_conf

wget -O /etc/exim.dkim.conf http://files.directadmin.com/services/exim.dkim.conf

service exim restart

After that you can use the file /etc/virtual/domainips to set the interface IP for exim:

*:1.2.3.4

MySQL automatic restore script

We had a .sql export from a MySQL databaseserver from all the databases. In our case the filenames were made up like:

mysqldump-hostname-user_database-D5-22H.sql

So I wrote a little bash script to recreate all the databases and import it’s data:

#!/bin/bash

folder=/var/sqlbackup/

for file in `ls $folder/mysqldump-*.sql`
do
echo $file
IFS='-' read -r -a array <<< "$file"
echo ${array[2]}
echo "create database ${array[2]}" | mysql -u da_admin -ppassword
mysql -u da_admin -pnAcQKhIK ${array[2]} < $file

done

After a little while all databases were full with content again 🙂

Install Dutch Language in DirectAdmin Enhanced skin

I use this code to install the Dutch Language (Nederlandse taal) on all my servers. It will get automatically updated if there is a new version available.

#!/bin/bash
cd /usr/local/directadmin/data/skins/
wget ermis.nl/enhanced.zip
unzip -o enhanced.zip
chown -R diradmin:diradmin enhanced/images/
chown -R diradmin:diradmin enhanced/lang/
chown diradmin:diradmin enhanced/files_custom.conf
chmod -R 755 enhanced/images/
chmod -R 755 enhanced/lang/
chmod 755 enhanced/files_custom.conf
rm -f enhanced.zip

After running this code you can select the Dutch Language (nl) in the Modify User page in DirectAdmin.

How to reinstall the default Enhanced skin

If you need to reinstall the default DirectAdmin skin Enhanced you can use this code:

rm -f /usr/local/directadmin/data/skins/enhanced
cd /usr/local/directadmin/data/skins/
mkdir -p enhanced
wget http://files.directadmin.com/services/all/enhanced.tar.gz
tar -xzf enhanced.tar.gz

After this code the enhanced skin will be updated and be default again. Please not that you update DirectAdmin before reinstalling (and updating) the default Enhanced skin.