Quickstart

Server Mechanic is about changing a server or virtual machine by applying a migration script once and only once. So you can checkin setup and adjustments to your infrastructure as scripts into your preferred source code management system.

How it works

With Server Mechanic you author changes to your machines as scripts in your favorite language, e.g. shell scripts. Server Mechanic collects these migration scripts, executes them and records them as applied in an internal database. Next time only new migrations will be executed. In case of an error you fix the problem and start over.

The Server Mechanic playground

The Server Mechanic playground (mechanic-playground) is a docker container with a mechanic preinstalled so you instantly can start playing with mechnic.

Pull from dockerhub

docker pull servermechanic/mechanic-playground

Create a playground

# create folder to mount as mechanic volume
mkdir srv-mechanic-volume

# create folder mechanic will pickup migrations from
mkdir srv-mechanic-volume/migration.d/

# start the container
docker run -d --name my-mechanic-playground \
    -v $PWD/srv-mechanic-volume:/srv/mechanic \
    mechanic-playground

List migrations already applied

docker exec -t my-mechanic-playground mechanic list-migrations

This should list an initial migration applied on startup. One migration is part of the container and is applied on first startup.

Add own migration

A migration can be written as a shell script. This is a simple example migration:

#!/bin/bash -ex

echo "# config for hooray" > /srv/mechanic/hooray.conf
exit 0

The next command places the migration script in the mechanic migrations folder and makes it executable.

cat - > srv-mechanic-volume/migration.d/20161224_hooray.sh <<EOB
#!/bin/bash -ex

echo "# config for hooray" > /srv/mechanic/hooray.conf
exit 0
EOB
chmod 755 srv-mechanic-volume/migration.d/20161224_hooray.sh

Run the Server Mechanic to apply migrations

docker exec -t my-mechanic-playground mechanic -v migrate

Query Server Mechanic if the migration has been applied

docker exec -t my-mechanic-playground mechanic list-migrations

Verify that the migration's effect is visible:

cat srv-mechanic-volume/hooray.conf