Changeset 123


Ignore:
Timestamp:
12/04/2006 20:38:36 (5 years ago)
Author:
ccowart
Message:

Developed the pull mechanism for confman. It's ready to go into production!

Location:
trunk/confman
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/confman/confman

    r122 r123  
    9696                        conf_assemble_sing $file || return $? 
    9797                done 
     98        conf_recordAction commit 
     99        conf_markclean 
    98100                echo "Commit operation finished successfully" >&2 
    99101                rm -f $msg 
    100  
    101102        else 
    102103                print_usage 1 
     
    120121 
    121122                echo "Installation operation started." >&2 
     123        conf_commit "$LAYERS" $msg || return $? 
    122124                for layer in $LAYERS ; do 
    123                         $DEBUG && echo "Layer: $layer" >&4 
    124                         conf_commit $layer $msg || return $? 
    125                         conf_install $layer $* 
     125                        conf_install $layer "$@" 
    126126                done 
    127127                for file in $SINGULARITIES ; do 
    128128                        conf_assemble_sing $file || conf_cleanexit 
    129129                done 
     130        conf_recordAction install 
     131        if ! conf_isclean ; then 
     132            echo "WARNING: Recent 'install' operations prevented a 'sync'" >&2 
     133            echo "Running a 'commit' is highly recommended." >&2 
     134        fi 
    130135                echo "Installation operation succeeded." >&2 
    131136        fi 
     
    576581 
    577582    conf_rmattr "$attr" "$@" 
     583} 
     584 
     585function state { 
     586    if conf_isclean ; then 
     587        echo "This host is clean." 
     588    else 
     589        echo "This host may be dirty. Consider running a 'commit' operation" 
     590    fi 
    578591} 
    579592 
     
    598611    help )                          print_help "$@" ; exit 0 ;; 
    599612    setup|se* )                     setup "$@" ;; 
    600     status|st* )                    status "$@" ;; 
     613    status )                        status "$@" ;; 
     614    state )                         state ;; 
    601615    create|cr* )                    create "$@" ;; 
    602616    update|u* )                     update "$@" ;; 
  • trunk/confman/confman.conf

    r121 r123  
    3131SINGULARITIES="/etc/rc.conf" 
    3232 
     33# A place where confman can keep state 
     34REPO_DB="/var/db/confman" 
     35 
    3336# The warning message for all files 
    3437CONF_WARNING="WARNING! This file is under confman revision control." 
     
    6063#LIVE_ROOT="/home/ccowart/img" 
    6164 
    62  
  • trunk/confman/confmandoc.sh

    r122 r123  
    2828  $MYNAME import module livefile 
    2929  $MYNAME install workingfile [ workingfile ... ] 
     30  $MYNAME status [ working_copy ] 
     31  $MYNAME state 
    3032  $MYNAME ls [ workingfile | workingdirectory ] 
    3133  $MYNAME lsattr [ workingfile | workingdirectory ] 
     
    145147EOF 
    146148;; 
    147           st* ) 
     149          status ) 
    148150cat <<EOF 
    149151$MYNAME provides a command-line interface to Rescomp's server 
     
    154156 
    155157Look at the status entries for the file or directory specified by working_copy. 
     158EOF 
     159;; 
     160          state ) 
     161cat <<EOF 
     162$MYNAME provides a command-line interface to Rescomp's server 
     163configuration management system. 
     164 
     165Usage: 
     166  $MYNAME state 
     167 
     168This command indicates whether the system is "dirty" or "clean." 
     169 
     170A dirty system is one that has missed an automated "sync" operation in order 
     171to preserve changes made by installation operations occuring between the 
     172repository's export and the system's call to "sync." 
     173 
     174Dirty systems may have out-of-date configuration files. Subsquent sync or 
     175commit operations can bring the sytem up-to-date. 
    156176EOF 
    157177;; 
  • trunk/confman/confmanlib.sh

    r122 r123  
    1010 
    1111REPO_URI="${REPO_PROTOCOL}${REPO_HOSTNAME}${REPO_PATH}" 
     12REPO_ACTION="${REPO_DB}/last_action" 
     13REPO_SYNC_STATE="${REPO_DB}/state" 
    1214 
    1315# Checks out the conf tree if we don't already have it. Updates it if we do. 
     
    5557# Commits module $1 with message $2 
    5658function conf_commit { 
    57         local modules=$(echo $modules | tr ' ' ',') 
     59        local modules=$(echo $1 | tr ' ' ',') 
    5860        local msg="$2" 
    5961 
    6062    # $modules is in the form foo,bar,baz. This eval trick forces 
    6163    # curly brace expansion. 
    62         svn commit -F "$msg" $(eval echo foo/{$modules}) 
     64    if echo "$modules" | grep ',' > /dev/null ; then 
     65            svn commit -F "$msg" $(eval echo ${WORK_PATH}/{$modules}) 
     66    else 
     67        svn commit -F "$msg" ${WORK_PATH}/$modules 
     68    fi 
    6369} 
    6470 
     
    7278            remote="${CONF_EXPORT_URI#*://}" 
    7379            remote="${remote/\//:/}" 
    74             scp $remote $tmpfile  
     80            scp -p $remote $tmpfile  
    7581            ;; 
    7682        http|https|ftp) 
     
    7985        file) 
    8086            remote="${CONF_EXPORT_URI#*://}" 
    81             cp $remote $tmpfile 
     87            cp -p $remote $tmpfile 
    8288            ;; 
    8389        *) 
     
    97103# This exports a working copy of the repository to a tarball 
    98104function conf_export { 
    99     local tmpdir=`mktemp -d -t confman` 
    100105    local tarball="$1" 
    101     svn checkout "${REPO_URI}" "${tmpdir}/conf" 
    102     tar -czf "$tarball" -C "$tmpdir" conf 
    103     rm -rf "$tmpdir" 
     106    conf_checkout_tree 
     107    tar -czf "$tarball" -C "${WORK_PATH}" . 
    104108} 
    105109 
     
    159163        # See if it even exists 
    160164        file="${moduledir}${livefile}" 
    161         echo Install: $file 
    162165        if [ ! -e "$file" ] && [ -z "$1" ] ; then 
    163166                return 0 
     
    240243        local checkpoint=$2 
    241244        local chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}" 
    242         local revision=`svn info ${WORK_PATH}|awk '/Last Changed Rev:/ {print $4}'` 
     245        local revision=`conf_revision` 
    243246        echo $revision > $chkpath 
    244247        svn add $chkpath 
     
    470473} 
    471474 
     475function conf_markclean { 
     476    echo clean > $REPO_SYNC_STATE 
     477} 
     478 
     479function conf_markdirty { 
     480    echo dirty > $REPO_SYNC_STATE 
     481} 
     482 
     483function conf_isclean { 
     484    local state=`cat $REPO_SYNC_STATE` 
     485    case $state in 
     486        clean)  return 0 ;; 
     487        dirty)  return 1 ;; 
     488        *)      echo "Invalid state. Reporting dirty." >&2 ; return 1 ;; 
     489    esac 
     490} 
     491 
     492# Returns the current revision number of the repository on stdout 
     493function conf_revision { 
     494    svn info ${WORK_PATH} | awk '/Last Changed Rev:/ {print $4}' 
     495} 
     496 
     497# Returns the revision of the last commit or install operation on stdout 
     498function conf_sysrev { 
     499    cut -d ':' -f 2 $REPO_ACTION 
     500} 
     501 
     502# Returns the last action of the repository on stdout 
     503function conf_lastact { 
     504    cut -d ':' -f 1 $REPO_ACTION 
     505} 
     506 
     507# Records the specified action 
     508function conf_recordAction { 
     509    local action="$1" 
     510    local revision=`conf_revision` 
     511    echo "${action}:${revision}" > $REPO_ACTION 
     512} 
     513 
    472514# WARNING: If you refer to fd 2 in this code, this function will silently 
    473515# fail when called by trap. DO NOT ATTEMPT TO LOG TO fd 2 IN THIS FUNCTION! 
     
    484526 
    485527        echo "Removing leftover temp files..." >&4 
    486         find /tmp -maxdepth 1 -user `whoami` -name 'confman*' -exec rm -rf {} \; 
     528        find /tmp/confman* -maxdepth 0 -user `whoami` -exec rm -rf {} \; 
    487529 
    488530        # And this clears any locks we may have created on our working copy: 
  • trunk/confman/confsync.sh

    r121 r123  
    2626tarball=$(conf_fetch) 
    2727tmpdir=$(mktemp -d -t confman) 
     28 
    2829tar -xzf $tarball -C $tmpdir 
    2930rm -rf $tarball 
    30 WORK_PATH="$tmpdir/conf" 
     31WORK_PATH="$tmpdir" 
     32 
     33tar_revision=`conf_revision` 
     34sys_revision=`conf_sysrev` 
     35last_action=$(conf_lastact) 
     36 
     37if [ "x$last_action" = "xinstall" ] && [ $tar_revision -lt $sys_revision ] 
     38then 
     39    echo "Error: File system may be dirty." \ 
     40        "A commit operation is recommended." >&2 
     41    echo "Error: $tarball is out of date. Exiting without making changes." >&2 
     42    conf_markdirty 
     43    rm -rf $tmpdir 
     44    exit 1 
     45fi 
     46 
     47if [ $tar_revision -lt $sys_revision ] ; then 
     48    exit 0 
     49fi 
     50 
     51exit 
    3152 
    3253echo "Sync operation started" >&2 
     
    3960        conf_assemble_sing $file || conf_cleanexit 
    4061done 
     62conf_markclean 
     63conf_recordAction sync 
    4164echo "Sync operation finished successfully" >&2 
    4265 
    4366rm -rf $tmpdir 
    4467 
    45  
  • trunk/confman/export.sh

    r121 r123  
    2626 
    2727REPO_URI="file://$REPO_PATH" 
     28backup=`mktemp -t confman` 
    2829 
    29 conf_export $CONF_EXPORT_FILE 
     30echo "Backing up $CONF_EXPORT_FILE" 
     31cp $CONF_EXPORT_FILE $backup 
    3032 
     33echo "Beginning export operation." >&2 
     34if ! conf_export $CONF_EXPORT_FILE ; then 
     35    echo "The export failed. Restoring $CONF_EXPORT_FILE from backup." >&2 
     36    mv $backup $CONF_EXPORT_FILE 
     37    echo "Exiting." >&2 
     38    exit 1 
     39fi 
     40echo "Export complete." >&2 
     41 
     42echo "Removing $backup" 
     43rm $backup 
     44 
Note: See TracChangeset for help on using the changeset viewer.