descriptionTools for creating deployable scripts/programs
homepage URLhttp://www.polettix.it/cgi-bin/wiki.pl/Programming/deployable
ownerflavio@polettix.it
last changeTue, 27 Aug 2013 12:59:39 +0000
Content tags:
Add:
readme

OVERVIEW

deployable is a suite of programs that help easing the system administrator life.

It is based upon the following workflow to distribute changes in a molteplicity of servers:

For the first issue, you'll probably have various files/scripts/programs that you will need to perform a given activity. The deployable script helps you select all the needed components that you need in the target server, and bundles them all inside a single, self-contained script that is ready to be run in the target machine. In this way, you'll only have to worry about taking one single file. Think about making an archive, but adding some logic to make it executable and instruct it to execute some specific programs.

For the second issue, it's mainly a matter of handling the transfer of the deploy script to the target servers, and execute them. This is obviously only a matter of sftp/ssh, but if you have more than 2 servers you'll quickly get tired of writing shell commands and passwords. To ease your life in this field, deploy is your friend: just tell it which is the script, and the list of target servers.

CONTENTS

The deployable project contains the following files:

deployable (the script)
generates self-contained scripts with all the files that you want to ship as part of your deployment task;
deploy
helps you distribute and execute the deploy script generated with deployable above in all the relevant servers;
mobundle
bundles Perl modules inside a Perl script, in order to ensure that those modules will be available in the target system (works only for Pure Perl modules);
remote
script that is used by deployable to generate the self-contained scripts that can be distributed like advanced tarballs;
Makefile
support file for embedding Archive::Tar inside remote

TYPICAL USAGE

In a typical usage, you check some upgrade procedure in a staging environment, and come up with:

Suppose that you come up with the following situation:

  # files that must be simply installed under "/", after stripping
  # the initial "/project/target-root/" part
  /project/target-root/etc/apache2/httpd.conf
  /project/target-root/etc/hosts
  /project/target-root/etc/HOSTNAME
  /project/target-root/opt/project/project.pl
  
  # scripts to be executed in the target directory, set as executable
  /project/01-check-network.sh
  /project/02-ntpdate.sh
  /project/03-create-users.sh
  
  # files to support scripts, not set as executable
  /project/userlist

In order to put all this stuff into a single executable perl file you use deployable. In particular, you can instruct this program about where you would like to put all the relevant stuff:

  cd /project
  deployable --all-exec -o deploy-script.pl --root target-root *.sh userlist

This command produces the deploy-script.pl script that is compound of two parts:

The tarball is organised as follows:

In the example above, all the suff in target-root is placed under root; all the other files (the three scripts and the support file) are put inside the here directory:

  deployable/config.pl
  here/01-check-network.sh
  here/02-ntpdate.sh
  here/03-create-users.sh
  here/userlist
  root/etc/apache2/httpd.conf
  root/etc/hosts
  root/etc/HOSTNAME
  root/opt/project/project.pl

The first part of the produced script is able to extract this tarball from itself and figure out where the different pieces have to be put. In particular, stuff under the root directory will be installed in /, and the other files in a temporary directory for further processing.

After the extraction is completed, the produced script checks if any program should be executed. Having passed the C<--all-exec>, all executable files in the temporary directory will be executed; the order will be that resulting froma lexicographical sorting of the file names, so it's a good idea to put a leading number in order to control the execution closely.

Once you have this single script containing all what you need, plus the logic to start the deploy process in the target machine, you can put it in the target and execute it. If it's a matter of one-two servers, you can upload it, login and execute it. If you have more servers, you can use deploy:

   deploy -s deployable-script.pl host1 host2 host3

Calling this program will initially ask you for a password if you pass an empty password on the command line. If you're relying on SSH certificates, just hit return. After this, it will begin uploading and executing in all the given servers.

Thus, in a matter of two commands, you can pack all your stuff and deploy it!

shortlog
2013-08-27 Flavio Polettiadded support for DEPLOYABLE_DISABLE_PASSTHROUGHmaster
2013-08-27 Flavio Poletticoped with empty archives
2013-08-27 Flavio Polettiadded short option for passthrough
2013-08-27 Flavio Polettimerged from repo
2013-08-16 Flavio PolettiMerge branch 'generic-remote'
2013-08-12 Flavio Polettifinalized passthrough feature w/ testsgeneric-remote
2013-08-12 Flavio Polettiadded a test
2013-08-12 Flavio Polettiadded and rationalized some options
2013-08-12 Flavio Polettipassing "rest" of @ARGV to subcommands
2013-08-12 Flavio PolettiMerge branch 'better-tar'
2013-08-12 Flavio Polettiusing single quote char as apostrophebetter-tar
2013-08-12 Flavio Polettiadded test for --inspect
2013-08-12 Flavio Polettibetter error reporting when using bad options
2013-08-12 Flavio Polettiremoved unneeded variables
2013-08-12 Flavio Polettiadded test for listing
2013-08-12 Flavio Polettiadapted list for "here" to list for "root"
...
heads
12 months ago master
13 months ago generic-remote
13 months ago better-tar