Recently a friend of mine asked me to migrate his old server to a new provider, and I said yes. This new machine is managed by a software called Parallels Plesk. Plesk streamlines a lot of the boring and tedious tasks an administrator would have to do manually.
Now me being a proficient Linux person I thought cool, this will reduce the amount of work I have to do. I will be able to do everything either from the GUI or the command line, I said to myself. It's not until I looked at what was happening on the actual machine, when my smile vanished off my face... Every component that is manageable via Plesk has been retrofitted in some bizarre way. What will I do, how do I integrate seamlessly with these components? I don't want to break the nice GUI.
After scratching my head, poking around the filesystem and doing some research, I finally found what I was looking for. In order to configure the machine from the command line, you have to use the utilities provided by Plesk. In my case they are located under /opt/psa/ on the Ubuntu 12.04 server.
Migrating Mailboxes
The first thing that I was tasked to do was migrate all email accounts. Fortunately for me be both the old and the new system used the same set of software, the postfix and courier combo.
I started with getting a dump of all the email accounts and aliases from the original MySQL database. Since I was lazy, I loaded up the mysql prompt, did two quick selects and copied over the output of the results from one terminal to the other. Step one, check!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
old_server# mysql -u root -p mysql> use mail; mysql> select address,goto from alias where domain = 'DOMAIN'; +--------------------------------+--------------------------------+ | address | goto | +--------------------------------+--------------------------------+ | address1@DOMAIN | adress1@DOMAIN,ALIAS1@DOMAIN | | address2@DOMAIN | adress2@DOMAIN,ALIAS2@DOMAIN | +--------------------------------+--------------------------------+ mysql> select * from mailbox; ... new_server# cat > mail_aliases | address1@DOMAIN | adress1@DOMAIN,ALIAS1@DOMAIN | | address2@DOMAIN | adress2@DOMAIN,ALIAS2@DOMAIN | new_server# cat > mail_accounts .... |
Now that I had the raw data, I had to convert the nice ASCII art data into something more usable by the computer.
1 2 3 |
cat mail_accounts | sed 's/,/ /g' | sed 's/ |/,/g' | sed 's/^| //' | sed 's/\( \+, \)/,/g' | sed 's/\(, \+\)/,/g' | sed 's/, *$//' |
Before I continue, let see how we can add a new email account via Plesk... To manage the mail system we use the mail comand:
1 2 3 |
/opt/psa/bin/mail --create USERNAME@DOMAIN_NAME -passwd PASSWORD -passwd_type encrypted -mailbox true -aliases add:ALIAS_1,ALIAS_2 |
The actual mailbox will be created in /var/qmail/DOMAIN_NAME/USERNAME with the Maildir format. This fits in great with what we want to do, because the original mailbox was also in the same format, we can just copy over the files.
So we just need to iterate over the entries that we got from the MySQL database, execute the mail command, copy over the files, and set the proper permissions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#!/usr/bin/env bash SRC_MAILBOX="/root/oldroot/home/vmail" DST_MAILBOX="/var/qmail/mailnames" while read ACCOUNT; do EMAIL=$(echo ${ACCOUNT} | cut -d ',' -f 1) PASSWD=$(echo ${ACCOUNT} | cut -d ',' -f 2) MAILBOX=$(echo ${ACCOUNT} | cut -d ',' -f 4) echo "Migrating ${EMAIL}" /opt/psa/bin/mail --create "${EMAIL}" -passwd "${PASSWD}" -passwd_type encrypted -mailbox true cp -r ${SRC_MAILBOX}/${MAILBOX}/* ${DST_MAILBOX}/${MAILBOX}/Maildir chown -R popuser:popuser ${DST_MAILBOX}/${MAILBOX} echo done < mail_accounts.csv |
Finished task one, onto round two...
Migrating Apache
This is the part involving the convoluted configurations files I hinted earlier. If you look at the apache configuration files in /etc/apache2/ everything looks normal, nothing out of the ordinary, until you see that all those config files do nothing! I spent half a day reading those configs and figuring out how Plesk manages it's virtual domains. I have yet to fully understand how it works, but I know enough to get by, for now at least.
Plesk stores all of it's apache related stuff in /var/www/, and thats fairly standard. The most important directory there is vhosts. That's where all the magic happens, where the management panel stores all of its domains. For each domain you setup in the web GUI, you get a matching directory.
When you get your server from the provider, there will be always be at least one default domain. Usually it's a auto-generated domain based on the IP of your machine. That domain unfortunately is here to stay, Plesk does not allow you to remove it.
The directory structure of a domain should be something similar to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
drwxr-xr-x 14 root root 4096 Jan 31 19:57 . drwxr-xr-x 9 root root 4096 Jan 31 19:57 .. drwxr-x--- 5 user psaserv 4096 Jan 30 14:32 anon_ftp drwxr-x--- 3 user psaserv 4096 Jan 30 14:32 cgi-bin drwxr-x--- 11 user psaserv 4096 Jan 31 23:17 other_domain drwxr-x--- 3 root psaserv 4096 Feb 1 02:42 conf drwxr-xr-x 2 root psaserv 4096 Jan 30 14:32 error_docs drwxr-xr-x 2 root root 4096 Jan 30 14:32 etc drwxr-x--- 9 user psaserv 4096 Jan 31 20:58 httpdocs drwxr-x--- 2 root psaserv 4096 Jan 30 14:32 pd drwx------ 2 user root 4096 Jan 30 14:32 private dr-xr-x--- 7 root psaserv 4096 Jan 30 14:32 statistics drwxr-xr-x 2 root psaserv 4096 Jan 30 14:32 subdomains drwxr-xr-x 2 root psaserv 4096 Jan 30 14:32 web_users |
In the case of the default domain, the httpdocs directory is the default apache root directory. All the configuration files are located in conf, but these are auto-generated files and should not be edited. You might see multiple files with numbers, these are the revisions of the configs, symlinks point to latest version. Every time you modify the configuration via the Panel, a new set of configs are generated.
If you wish to provide your own configuration file, you should call it vhost.conf/vhost_ssl.conf and put it in the conf directory. Execute the following to load your files:
1 2 3 |
/opt/psa/admin/sbin/httpdmng --reconfigure-domain DOMAIN_NAME |
For those interested, I just found some documentation relating to Linux administration with Plesk. Everything is starting to become clearer on how I should manage this beast.
That's all
For now I will leave you with what I have written so far. This is all the Plesk specific information I wanted to share, I'm going back to work getting everything migrated properly. Hopefully you have glimpsed some useful nuggets of information from my adventures into the wonderful world of Plesk.
I read a lot of interesting content here. Probably you
spend a lot of time writing, i know how to save you a lot of time, there is an online tool
that creates readable, SEO friendly articles in seconds,
just type in google — laranitas free content source