简体   繁体   中英

How to change symlink to old version if latest version is not working

I have a conf file product which launches the product application at startup.

Application folder structure:

home/
    jamnes/
          product/
                 installation/
                             product1.0
                             product2.0
                 symlinktoproduct/
                                run.sh

product.conf file:

# Product start file
#
# Starts the Product App and respawns when it quits

description     " Product Application"

start on desktop-session-start
stop on runlevel [!2345]

respawn
exec /home/james/product/symlinktoproduct/run.sh

if user upgrade the application we are placing new version in installation folder and changing symlinktoproduct->latestversion

Issue:

How can i point to old version product file if latest version is not working.

shell i have any checks in conf file weather latest version is working or not.

could some one help me out of this.

OS: Ubuntu

You can add a check in conf file:

exec ( basedir="/home/jamnes/product"
  current_product="${basedir}/symlinktoproduct"

  function run_product {
    echo "Running product `ls -l ${current_product}`"
    ${current_product}/run.sh
    return $?
  }

  # run the latest product
  run_product || {

      # if run.sh returns non-zero exit code, then run previous product
      echo "ERROR: running product `ls -l ${current_product}`"

      # get name of previous product by listing previous entry from installation directory.
      # Assume alphabetical sort order.
      prev_version=`ls -1 ${basedir}/installation | tail -2 | head -1`
      echo "Rollback too previous version [$prev_version]";

      # remove previous link
      rm -f ${current_product}

      # relink current product to the previous version
      ln -sf ${basedir}/installation/${prev_version} ${current_product}

      # run product again. Now previous version is executed.
      run_product
  }
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM