When you are building a server on a cloud like Amazon’s EC2, its quite typical to create a shell script to automate the process. This saves you time when you need to create a test server or god-forbid, your production server dies. But one of the challenges in creating these scripts is that some packages display a UI asking for user input. Two common examples of this are mysql (root password) and postfix (server type, root email, etc).

The solution to this is to use preseeding. This is where you tell the debian installer, in advance, the response to each of the questions it would normally ask when it installs the package. The command-line tools used to preseed are part of the debconf-utils package. So the 1st step is to make sure these are installed.

sudo apt-get -y install debconf-utils

Now you can go ahead and figure out which settings need to be set for each package. Let’s use mysql as an example. The easiest way to do this is to install the package manually and then use the debconfig-get-selections command to query the list of settings.


# sudo apt-get -y install mysql-server
# sudo debconf-get-selections | grep mysql
...
mysql-server-5.1 mysql-server/root_password_again password
mysql-server-5.1 mysql-server/root_password password
mysql-server-5.1 mysql-server/start_on_boot boolean true

So what we need to do now is create a preseed file with the above settings and then pass it to the debian installer using the debconf-set-selections command.

# echo "mysql-server-5.1 mysql-server/root_password password $MYSQL_ROOT_PWD" > mysql.preseed
# echo "mysql-server-5.1 mysql-server/root_password_again password $MYSQL_ROOT_PWD" >> mysql.preseed
# echo "mysql-server-5.1 mysql-server/start_on_boot boolean true" >> mysql.preseed
# cat mysql.preseed | sudo debconf-set-selections
# apt-get -y install mysql-server

Once the values have been set, you can run apt-get to install the package without prompting for any inputs.

One final note, if you have a lot of servers or rebuild them on a regular basis, you should probably be looking at Puppet or Chef.

  • Share/Bookmark