Automate package installation in ColdFusion (2021 release)

Overview

In ColdFusion (2021 release), there is a package manager to manage the installation/uninstallation of various packages.

In this document, we explain the steps of automating the process of package installation/updates and apply the process to multiple instances of ColdFusion.

Pre-requisites

Install the required packages in a single instance of a ColdFusion installation.

For example, you have installed the packages: axisawsdynamodb, and awss3.

The packages administrator and adminapi are pre-installed.

You can now export the server state to a file. We will be using this same file to install/update these packages in all other ColdFusion instances.

Export state
Export state

Export server state

You can export the server state in ColdFusion in two ways:

  1. CFPM utility
  2. ColdFusion Administrator

CFPM utility

  1. Launch the CFPM utility in via a command line.
  2. Run the command- export <path to a file>\currentServerState.txt
Export
Export

ColdFusion Administrator

  1. Launch ColdFusion Administrator > Package Manager.
  2. Click the button- Export Server State.
Export server state
Export server state

The required file gets downloaded.

Import

The next step is to automate the entire flow. But before that, let's see how you can use the file which was created in the previous step.

The Import command is supported only through the CFPM utility.

CFPM utility

  1. Launch the CFPM utility in via a command line.
  2. Run the command- import <path to a file>\currentServerState.txt

The command installs all the required packages (and also apply the server updates, if available),

Import packages
Import packages

Apply the script

Now that you can import or export the state of a server, let’s see how you can automate this entire process.

You can use a sample script file (Windows and non-Windows), which you can download from the location below. You can even create your own script file to automate this process.

下载

Windows

Assume that you have the following:

  • ColdFusion home: C:\ColdFusion2021
  • Instances:
    • cfusion
    • instance1
    • instance2
    • instance3
    • instance4

Also, you've installed all required packages in cfusion and have exported the server state.

To apply the server state in the rest of the instances, follow the steps below:

  1. Copy the following files in a directory, for example, is C:\Updates.

    • updates.bat
    • currentServerState.txt
  2. Launch a command prompt. From the prompt, run the command:

    updates.bat C:\ColdFusion2021 C:\Updates\currentServerState.txt instance1 instance2 instance 3 instance 4

    The command will install the packages, axisawsdynamodb, and awss3 along with the administrator and adminapi packages in all the four instances without any manual intervention.

Linux

Assume that you have the following:

  • ColdFusion home: /opt/ColdFusion2021
  • Instances:
    • cfusion
    • instance1
    • instance2
    • instance3
    • instance4

Also, you've installed all required packages in cfusion and have exported the server state.

To apply the server state in the rest of the instances, follow the steps below:

  1. Launch a terminal in your <Path to CF Home>/cfusion/bin directory.

  2. Copy the file updates.sh to the directory <Path to CF Home>/cfusion/bin

  3. On the terminal window opened, run the command:

    ./updates.sh /opt/ColdFusion2021 <path to>/currentServerState.txt instance1 instance2 instance3 instance4

    The command will install the packages, axisawsdynamodb, and awss3 along with the administrator and adminapi packages in all the four instances without any manual intervention.

If you face any issues when automating this flow, contact us at:

Appendix

Updates.bat

@echo off 
setlocal enabledelayedexpansion 
 
:: USAGE 
:: update.bat C:\ColdFusion C:\cfpackages.txt instance1 instance2 ...... 
:: First argument is the ColdFusion home directory 
:: Second argument is the file which was exported from a server 
:: From there on are all the instances of CF where you want to apply the updates to 
 
set argCount=0 
for %%x in (%*) do ( 
   set /A argCount+=1 
   set argVec[!argCount!]=%%~x 
) 
set pathToExportedFile="!argVec[2]!" 
set pathToCFHome=!argVec[1]! 
 
for /L %%i in (3,1,%argCount%) do ( 
 echo Executing "%pathToCFHome%\!argVec[%%i]!\bin\cfpm.bat" import %pathToExportedFile% 
 call "%pathToCFHome%\!argVec[%%i]!\bin\cfpm.bat" import %pathToExportedFile% 
) 
 
pause

Updates.sh

#!/bin/bash 
 
ARGUMENTS=() 
declare count=1 
declare pathToExportedFile='' 
declare pathToCFHome='' 
 
for var in "$@" 
do 
 if [ $count == 1 ] 
 then 
  pathToCFHome=("$var") 
 elif [ $count == 2 ] 
 then 
  pathToExportedFile=("$var") 
 else 
  ARGUMENTS+=("$var") 
 fi 
 count=$((count+1)) 
done 
 
for i in "${ARGUMENTS[@]}" 
do 
 SCRIPT_PATH="${pathToCFHome}/${i}/bin/cfpm.sh" 
 echo "Executing: ${SCRIPT_PATH} import ${pathToExportedFile}" 
    . "${SCRIPT_PATH}" "import" "${pathToExportedFile}" 
done
Adobe 徽标

登录到您的帐户