Changeset 563


Ignore:
Timestamp:
12/16/2011 18:15:38 (5 months ago)
Author:
blee
Message:

Merge confexport changes from trunk.

Closes #140 and #148

Location:
branches/confman-1.9
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/confman-1.9

  • branches/confman-1.9/confexport.8

    r429 r563  
    4545repository for use by hosts running 
    4646.Xr confsync 8 . 
     47.Pp 
     48If the system is already up to date, 
     49.Nm 
     50will exit without making any changes.  This behavior can be overridden with the 
     51.Fl f 
     52option, which will force 
     53.Nm 
     54to run even if the system revision equals the export revision.  Note that the 
     55.Fl f 
     56option cannot be used to export a revision less than the system revision. 
    4757.Pp 
    4858The 
     
    103113.Xr confman.conf 5 , 
    104114.Xr cron 8 
     115.Sh BUGS 
     116When using 
     117.Nm 
     118with the CONF_EXPORT_INCREMENTAL option, changes to files that are 
     119referenced in other modules by in-repository symlinks do not cause 
     120all relevant exports to be regenerated.  This can be worked around by 
     121either disabling the CONF_EXPORT_INCREMENTAL option or running 
     122.Nm 
     123with the 
     124.Fl f 
     125flag when such changes are made. 
    105126.Sh AUTHORS 
    106127.An Chris Cowart Aq ccowart@timesinks.net 
  • branches/confman-1.9/confexport.in

    r556 r563  
    2929# This script prepares an "export" of the confman repository for system 
    3030# processes to be able to pull. It is intended to be prepared regularly 
    31 # by a cron. It may be useful to modify this script to only prepare 
    32 # the export if the repository's most recent commit post-dates the 
    33 # tarball. 
     31# by an automated process like cron. 
    3432 
    3533if [ -r @pkgdatadir@/confmancommon.sh ] ; then 
     
    4139 
    4240# This changes the behavior of some library functions (e.g. URIs, locks) 
    43 CONF_EXPORT="true" 
     41CONF_EXPORT=true 
    4442 
    4543function print_help { 
    46     echo "usage: $0 [-d]" >&4 
     44    echo "usage: $0 [-f] [-d]" >&4 
    4745    echo "Type '$0 -h' to display this help and exit." >&4 
    4846    conf_cleanExit ${1:-0} 
    4947} 
    5048 
    51 while getopts "dh" OPT 2>&4 ; do 
     49FORCE=false 
     50DEBUG=false 
     51 
     52while getopts "fdh" OPT 2>&4 ; do 
    5253    case "$OPT" in 
     54        f)  FORCE=true ;; 
    5355        d)  DEBUG=true ;; 
    5456        h)  print_help 0;; 
     
    6466    exec 1>/dev/null 
    6567fi 
     68 
     69echo "Export operation started" | conf_logger 
    6670 
    6771confexport_lock_system 
     
    8286esac 
    8387 
    84 if [ -z "$temp_conf_export" ] ; then 
     88if [ -z "${temp_conf_export}" ] ; then 
    8589    echo "Could not create tempfile. Exiting." >&2 
    8690    exit 1 
    8791fi 
    8892 
    89 echo "Beginning export operation." | conf_logger 
    90 if ! conf_export $temp_conf_export ; then 
    91     echo "The export failed. Exiting." >&2 
    92     rm -rf $temp_conf_export 
    93     exit 1 
     93if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 
     94    WORK_PATH=$(conf_tmp_dir) 
     95    conf_debug "Using temporary export working copy at ${WORK_PATH}" 
    9496else 
    95     # Prepare the new export 
    96     chown -R ${CONF_EXPORT_USER}:${CONF_EXPORT_GROUP} $temp_conf_export 
    97     chmod -R ${CONF_EXPORT_MODE} $temp_conf_export 
    98     # Switch to the new export 
    99     old_conf_export=$(conf_tmp_dir) 
    100     mv ${CONF_EXPORT_FILE} $old_conf_export 
    101     mv $temp_conf_export ${CONF_EXPORT_FILE} 
    102     # Remove the old export 
    103     rm -rf $old_conf_export 
     97    WORK_PATH="${CONF_EXPORT_WORK_PATH}" 
     98    conf_debug "Using persistent export working copy at ${WORK_PATH}" 
    10499fi 
    105100 
    106 confexport_unlock_system 
     101conf_checkout_tree 
    107102 
    108 echo "Export complete." | conf_logger 
     103repo_export="${CONF_EXPORT_STYLE}:$(conf_revision)" 
     104sys_export="$(conf_export_sysrev)" 
     105 
     106conf_debug "repo_export: ${repo_export}" 
     107conf_debug "sys_export: ${sys_export}" 
     108 
     109if [ "${sys_export}" = "${repo_export}" ]; then 
     110    if ! ${FORCE}; then 
     111        echo "System is up to date." | conf_logger 
     112        conf_cleanExit 0 
     113    fi 
     114fi 
     115 
     116repo_method=$(echo ${repo_export} | cut -d ':' -f 1) 
     117sys_method=$(echo ${sys_export} | cut -d ':' -f 1) 
     118repo_revision=$(echo ${repo_export} | cut -d ':' -f 2) 
     119sys_revision=$(echo ${sys_export} | cut -d ':' -f 2) 
     120 
     121if [ "${sys_method}" != "${repo_method}" ]; then 
     122    echo "Export style change detected: ${sys_method} -> ${repo_method}" 
     123    if ${CONF_EXPORT_INCREMENTAL}; then 
     124        echo "Ignoring CONF_EXPORT_INCREMENTAL during export style change" 
     125        CONF_EXPORT_INCREMENTAL="false" 
     126    fi 
     127fi 
     128 
     129if [ "${sys_revision}" -gt "${repo_revision}" ]; then 
     130    echo "Error: The last export was newer than the current repository.  Exiting without making changes." >&2 
     131    conf_cleanExit 1 
     132fi 
     133 
     134if ! conf_export "${temp_conf_export}" "${sys_revision}" "${repo_revision}"; then 
     135    echo "Error: The export failed. Exiting." >&2 
     136    rm -rf "${temp_conf_export}" 
     137    conf_cleanExit 1 
     138fi 
     139 
     140# Prepare the new export 
     141chown -R ${CONF_EXPORT_USER}:${CONF_EXPORT_GROUP} "${temp_conf_export}" || exit 1 
     142chmod -R ${CONF_EXPORT_MODE} "${temp_conf_export}" || exit 1 
     143 
     144# Switch to the new export 
     145old_conf_export=$(conf_tmp_dir) 
     146if [ -e "${CONF_EXPORT_FILE}" ]; then 
     147        mv "${CONF_EXPORT_FILE}" "${old_conf_export}" || exit 1 
     148fi 
     149mv "${temp_conf_export}" "${CONF_EXPORT_FILE}" 
     150 
     151conf_record_export 
     152 
     153echo "Export operation finished successfully" | conf_logger 
     154 
     155confexport_unlock_system "${system_lock}" 
     156 
     157# Remove the old export 
     158rm -rf "${old_conf_export}" 
     159 
     160# If CONF_EXPORT_WORK_PATH is not set, we were using a temporary 
     161# directory, so clean it up 
     162if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 
     163    rm -rf "${WORK_PATH}" 
     164fi 
    109165 
    110166conf_cleanExit 0 
  • branches/confman-1.9/confman.conf.5.in

    r560 r563  
    107107The export style to be used by 
    108108.Xr confexport 8 . Valid options are: repository, module, recipe. 
     109.It CONF_EXPORT_INCREMENTAL 
     110This option optimizes 
     111.Xr confexport 8 performance.  When enabled, 
     112.Xr confexport 8 will only export the changes made to the 
     113.Xr confman 8 repository since the last 
     114.Xr confexport 8 run.  This option has no effect when using repository-style 
     115exports. 
     116.It CONF_EXPORT_INCREMENTAL_LN 
     117This option further optimizes 
     118.Xr confexport 8 performance when using CONF_EXPORT_INCREMENTAL.  When enabled, 
     119.Xr confexport 8 will use 
     120.Xr ln 1 to copy unchanged exports into the new export rather than 
     121.Xr cp 1 .  This option can only be used if temporary files are created 
     122on the same filesystem partition as CONF_EXPORT_FILE. 
    109123.It CONF_FETCH_SSH_KEY 
    110124This is a private SSH keyfile for use with "sftp://" and "scp://" URIs above. 
  • branches/confman-1.9/confman.conf.in

    r559 r563  
    8080CONF_EXPORT_WORK_PATH="" 
    8181CONF_EXPORT_STYLE="repository" 
     82CONF_EXPORT_INCREMENTAL="false" 
     83CONF_EXPORT_INCREMENTAL_LN="false" 
    8284EXPORT_REPO_PROTOCOL="" 
    8385EXPORT_REPO_HOSTNAME="" 
  • branches/confman-1.9/confmanlib.sh.in

    r559 r563  
    2828 
    2929REPO_ACTION="${REPO_DB}/last_action" 
     30EXPORT_REV_FILE="${REPO_DB}/last_export" 
    3031REPO_SYNC_STATE="${REPO_DB}/state" 
    3132RECIPE_NAME="$(cat "$RECIPE_FILE" 2>/dev/null)" 
     
    377378function conf_export { 
    378379    local exportpath="$1" 
     380    local sys_revision="$2" 
     381    local export_revision="$3" 
    379382    local modules 
    380  
    381     if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 
    382         WORK_PATH=$(conf_tmp_dir) 
    383     else 
    384         WORK_PATH="${CONF_EXPORT_WORK_PATH}" 
    385     fi 
    386  
    387     conf_checkout_tree 
    388  
     383    local module 
     384    local changed_recipes 
     385    local changed_modules 
     386    local updated_recipes 
     387    local recipe 
     388    local changed_module 
     389    local changed_recipe 
     390    local recipes 
     391     
    389392    case ${CONF_EXPORT_STYLE} in 
    390393        repository) 
    391             tar -czf "$exportpath" -C "${WORK_PATH}" . 
     394            tar -czf "$exportpath" -C "${WORK_PATH}" . || return 1 
    392395            ;; 
    393396        module) 
    394             modules=$(ls -1 ${WORK_PATH} | egrep -v '^(\.svn|checkpoints)$') # until ticket $40 is resolved 
    395             for module in $modules; do 
    396                 tar -hczf "$exportpath/$module.tgz" -C "${WORK_PATH}" $module 
     397            if ! ${FORCE} && ${CONF_EXPORT_INCREMENTAL}; then 
     398                # Get the list of changed modules 
     399                # TODO: Catch in-repository symlinks, ticket #144 
     400                cd "${WORK_PATH}" 
     401                changed_modules=$(@SVN@ diff -r ${sys_revision}:${export_revision} --summarize | egrep -v '^D[^/]*$' | sed 's/^[^ ][ ]*//' | cut -d '/' -f 1 | sort | uniq | egrep -v '^(meta|checkpoints)$') 
     402                cd - >/dev/null 
     403 
     404                # Preserve old module exports where possible 
     405                for module in $(ls -1 ${WORK_PATH} | egrep -v '^(\.svn|checkpoints)$'); do 
     406                    # If this module has changed, move on to the next one 
     407                    for changed_module in ${changed_modules}; do 
     408                        if [ "${module}" = "${changed_module}" ]; then 
     409                            continue 2 
     410                        fi 
     411                    done 
     412 
     413                    # This module was not changed, so preserve its old export 
     414                    echo "Preserving old export for module: ${module}" 
     415                    if ${CONF_EXPORT_INCREMENTAL_LN}; then 
     416                        ln "${CONF_EXPORT_FILE}/${module}.tgz" "${exportpath}" || return 1 
     417                    else 
     418                        cp -p "${CONF_EXPORT_FILE}/${module}.tgz" "${exportpath}" || return 1 
     419                    fi 
     420                done 
     421 
     422                modules="${changed_modules}" 
     423            else 
     424                modules=$(ls -1 ${WORK_PATH} | egrep -v '^(\.svn|checkpoints)$') # until ticket $40 is resolved 
     425            fi 
     426 
     427            for module in ${modules}; do 
     428                echo "Generating new export for module: ${module}" 
     429                tar -hczf "${exportpath}/${module}.tgz" -C "${WORK_PATH}" ${module} || return 1 
    397430            done 
    398431            ;; 
    399432        recipe) 
    400             for recipefile in $(conf_recipe_dir)/*; do 
    401                 modules="meta $(conf_get_recipe $recipefile)" 
    402                 tar -hczf "$exportpath/${recipefile#$(conf_recipe_dir)/}.tgz" -C "${WORK_PATH}" $modules 
     433            if ! ${FORCE} && ${CONF_EXPORT_INCREMENTAL}; then 
     434                # Get the list of changed recipes 
     435                cd "$(conf_recipe_dir)" 
     436                changed_recipes=$(@SVN@ diff -r ${sys_revision}:${export_revision} --summarize | grep -v '^D' | sed 's/^[^ ]*[ ]*//' | cut -d '/' -f 1) 
     437                cd - >/dev/null 
     438                conf_debug "changed_recipes: ${changed_recipes}" 
     439 
     440                # Get the list of changed modules 
     441                # TODO: Catch in-repository symlinks, ticket #144 
     442                cd "${WORK_PATH}" 
     443                changed_modules=$(@SVN@ diff -r ${sys_revision}:${export_revision} --summarize | sed 's/^[^ ]*[ ]*//' | cut -d '/' -f 1 | sort | uniq | egrep -v '^(meta|checkpoints)$') 
     444                cd - >/dev/null 
     445                conf_debug "changed_modules: ${changed_modules}" 
     446 
     447                # Check all recipes for changes 
     448                for recipe in $(ls -1 "$(conf_recipe_dir)" | egrep -v '^\.svn$'); do 
     449                    # If this recipe is in the list of changed recipes, 
     450                    # there's no need to check it any further since it will 
     451                    # be regenerated anyway 
     452                    for changed_recipe in ${changed_recipes}; do 
     453                        if [ "${recipe}" = "${changed_recipe}" ]; then 
     454                            continue 2 
     455                        fi 
     456                    done 
     457 
     458                    # If an unchanged recipe references a changed module, 
     459                    # its export needs to be regenerated 
     460                    modules=$(conf_get_recipe $(conf_recipe_dir)/${recipe}) 
     461                    for module in ${modules}; do 
     462                        for changed_module in ${changed_modules}; do 
     463                            if [ "${module}" = "${changed_module}" ]; then 
     464                                updated_recipes="${updated_recipes} ${recipe}" 
     465                                continue 3 
     466                            fi 
     467                        done 
     468                    done 
     469 
     470                    # This recipe has neither changed nor references a 
     471                    # changed module, so preserve its old export 
     472                    echo "Preserving old export for recipe: ${recipe}" 
     473                    if ${CONF_EXPORT_INCREMENTAL_LN}; then 
     474                        ln "${CONF_EXPORT_FILE}/${recipe}.tgz" "${exportpath}" || return 1 
     475                    else 
     476                        cp -p "${CONF_EXPORT_FILE}/${recipe}.tgz" "${exportpath}" || return 1 
     477                    fi 
     478                done 
     479                conf_debug "updated_recipes: ${updated_recipes}" 
     480 
     481                recipes="${changed_recipes} ${updated_recipes}" 
     482            else 
     483                recipes=$(ls -1 "$(conf_recipe_dir)"| egrep -v '^\.svn$') 
     484            fi 
     485 
     486            for recipe in ${recipes}; do 
     487                echo "Generating new export for recipe: ${recipe}" 
     488                modules=$(conf_get_recipe $(conf_recipe_dir)/${recipe}) 
     489                tar -hczf "${exportpath}/${recipe}.tgz" -C "${WORK_PATH}" "meta/.svn/entries" "meta/recipes/${recipe}" ${modules} || return 1 
    403490            done 
    404491            ;; 
     
    409496    esac 
    410497 
    411     if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 
    412         rm -rf ${WORK_PATH} 
    413     fi 
    414      
    415498    return 0 
    416499} 
     
    9991082} 
    10001083 
     1084# Returns the revision of the last export operation on stdout 
     1085function conf_export_sysrev { 
     1086    local export_sysrev 
     1087    local rv 
     1088 
     1089    export_sysrev="none:0" 
     1090    rv=0 
     1091 
     1092    if [ -f "${EXPORT_REV_FILE}" ]; then 
     1093        if ! export_sysrev=$(cat "${EXPORT_REV_FILE}"); then 
     1094            echo "Could not read file: ${EXPORT_REV_FILE}" >&2 
     1095            export_sysrev="none:0" 
     1096            rv=1 
     1097        fi 
     1098    fi 
     1099 
     1100    echo "${export_sysrev}" 
     1101    return ${rv} 
     1102} 
     1103 
    10011104# Returns the last action of the repository on stdout 
    10021105function conf_lastact { 
     
    10131116    local revision=`conf_revision` 
    10141117    $SUDO sh -c "echo '${action}:${revision}' > $REPO_ACTION" 
     1118} 
     1119 
     1120# Records the export operation 
     1121function conf_record_export { 
     1122    local revision=$(conf_revision) 
     1123 
     1124    if ! echo "${CONF_EXPORT_STYLE}:${revision}" > "${EXPORT_REV_FILE}"; then 
     1125            echo "Could not record export to file: ${EXPORT_REV_FILE}" >&2 
     1126            return 1 
     1127    fi 
    10151128} 
    10161129 
Note: See TracChangeset for help on using the changeset viewer.