Revision $Id: webjob-pad-deploy-slackware-pkg.base,v 1.1.1.1 2007/03/19 19:39:34 klm Exp $ Purpose This recipe demonstrates how to deploy and verify the installation of a Slackware package using WebJob and PaD technology. Motivation The motivation for this recipe stems from the desire/need to create a reliable, hands-off approach to deploying packages. Requirements Cooking with this recipe requires an operational WebJob server. If you do not have one of those, refer to the instructions provided in the README.INSTALL file that comes with the source distribution. The latest source distribution is available here: http://sourceforge.net/project/showfiles.php?group_id=40788 Also, if you're not familiar with PaD technology, then you should read the background material found here: http://webjob.sourceforge.net/WebJob/PayloadAndDelivery.shtml Each client must be running UNIX and have basic system utilities, installpkg, removepkg, and WebJob 1.6.0 or higher installed. The commands presented throughout this recipe were designed to be executed within a Bourne shell (i.e., sh or bash). Time to Implement Assuming that you have satisfied all the requirements/prerequisites, this recipe should take less than 30 minutes to implement. Solution The solution is to use the script in Appendix 1. The purpose of this script is to construct a PaD delivery command and execute it with WebJob. The delivery command surveys the system to determine if that particular package is installed. If not, the downloaded package is deployed. However, if deployment fails, the delivery command will attempt to revert to the previous state by removing the package. Once the package is deployed, its installation is verified. The delivery command finishes by removing any temporary files. This logic, in script form, is presented here: ${SURVEY} || { { ${DEPLOY} || ${REVERT} } && ${VERIFY} } ; ${FINISH} Each of these variables can be thought of as a macro that implements one particular operation. As such, each variable can contain one or more commands and associated shell logic. The following steps describe how to implement this solution. 1. Download, acquire, or build the Slackware package you wish to deploy. 2. Before proceeding, you need to define the following variables: PKG_FILE and PAD_FILE. These variables are referenced at various points in the remaining steps. $ PKG_FILE=noname-i386-1.tgz $ PAD_FILE=${PKG_FILE}.pad 3. Construct a PaD script from the package file. $ pad-make-script --create ${PKG_FILE} > ${PAD_FILE} 4. Copy the PaD script to the WebJob server. Typically, it would go in the client's commands directory. However, if multiple clients will be involved, it should go in the common commands directory. The permissions on the PaD script should be set to mode 0644. The following commands show how this could be done using scp as the file transfer agent. $ LOCATION=/var/webjob/profiles/client_1/commands/ or $ LOCATION=/var/webjob/profiles/common/commands/ $ chmod 0644 ${PAD_FILE} $ scp -p ${PAD_FILE} you@your.webjob.server.net:${LOCATION} 5. Extract the script from Appendix 1, and install it in a suitable location (e.g., /usr/local/bin) on each client system. Set the file's mode to 0755. Use the following command to extract the script: $ sed -e '1,/^--- deploy-slackware-pkg ---$/d; /^--- deploy-slackware-pkg ---$/,$d' webjob-pad-deploy-slackware-pkg.txt > deploy-slackware-pkg Note: It may be necessary to modify the PATH variable, which is explicitly set inside the script, to suit your particular environment. 6. Test deployment on a single client. You'll need to be root before you run the script. $ ssh you@your.webjob.client.net # su - # deploy-slackware-pkg -f noname-i386-1.tgz Closing Remarks To get maximum use from the script in Appendix 1, you should deploy it to every WebJob client. This step, while not absolutely necessary, is convenient because it gives you the choice of installing packages manually (from the console or via remote shell) or automatically as a job (from the WebJob server). If possible, the SURVEY and VERIFY macros should be made more robust. Currently, they are weak in the sense that they only test the existence of the specified package file in /var/log/packages/. Author This recipe was brought to you by Klayton Monroe. Credits This work is based on previous works created (in part or whole) by the following people: Bair, Andy Monroe, Klayton Appendix 1 --- deploy-slackware-pkg --- #!/bin/sh ###################################################################### # # $Id: deploy-slackware-pkg,v 1.1.1.1 2007/03/19 19:39:34 klm Exp $ # ###################################################################### # # Copyright 2007-2007 The WebJob Project, All Rights Reserved. # ###################################################################### # # Purpose: Deploy Slackware packages via WebJob. # ###################################################################### IFS=' ' PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin PROGRAM=`basename "$0"` Usage() { echo 1>&2 echo "Usage: ${PROGRAM} [-c webjob-config] [-H webjob-home] -f pad-file" 1>&2 echo 1>&2 exit 1 } PAD_FILE= while getopts "c:f:H:" OPTION; do case ${OPTION} in c) WEBJOB_CONFIG="${OPTARG}" ;; f) PAD_FILE="${OPTARG}" ;; H) WEBJOB_HOME="${OPTARG}" ;; *) Usage ;; esac done if [ -z "${PAD_FILE}" ]; then Usage else PKG_FILE=`basename "${PAD_FILE}" .pad` PKG_NAME=`basename "${PKG_FILE}" .tgz` fi PATH=${PATH}:${WEBJOB_HOME=/usr/local/webjob}/bin export PATH SURVEY=" { echo 'Surveying...' 1>&2 ; if [ -f /var/log/packages/${PKG_NAME} ] ; then true ; else false ; fi }" DEPLOY=" { echo 'Deploying...' 1>&2 ; installpkg ${PKG_FILE} ; }" VERIFY=" { echo 'Verifying...' 1>&2 ; if [ -f /var/log/packages/${PKG_NAME} ] ; then true ; else false ; fi }" REVERT=" { echo 'Reverting...' 1>&2 ; removepkg ${PKG_NAME} ; false ; }" FINISH=" { echo 'Finishing...' 1>&2 ; rm -f %payload ; }" PAD_COMMAND=" { ${SURVEY} || { { ${DEPLOY} || ${REVERT} } && ${VERIFY} } ; ${FINISH} }" webjob -e -f ${WEBJOB_CONFIG-${WEBJOB_HOME}/etc/upload.cfg} ${PAD_FILE} ${PAD_COMMAND} --- deploy-slackware-pkg ---