Updated on 2022-08-16 GMT+08:00

Compiling a Freezing Script

Example freezing script named appexample_freeze.sh:

#!/bin/sh
AGENT_ROOT_PATH=$1  #The root directory required when the Agent invokes the script. Functions, such as log functions, will use this variable. Do not rename this directory.
PID=$2 #The PID required when the Agent invokes the script. It is used for command output and do not rename it.
. "${AGENT_ROOT_PATH}/bin/agent_func.sh"#Reference script framework, which provides functions, such as logging, encryption, and decryption
#Result processing function, which writes operation results into given files for invokers to obtain return values.
 # Input parameter. $1: 0 indicates a success; 1 indicates a failure.
# No return value
#RESULT_FILE is defined in agent_func.sh.
function ExitWithResult()
{
    Log "[INFO]:Freeze result is $1."
    echo $1 > ${RESULT_FILE}
    chmod 666 ${RESULT_FILE}
    exit $1
}
function Main()
{
    Log "*********************************************************************"
    Log "[INFO]:Begin to freeze appexample."
    #Check whether appexample exists. If not, 0 is returned and the script exits.
    #In the process of freezing I/Os, the Agent program invokes each freezing script in sequence. If any script fails to be invoked, the whole process fails. To avoid interference from other programs, 0 should be returned when appexample cannot be found.
    which appexample
    if [ $? -ne 0 ]
    then
            Log "[INFO]:appexample is not installed."
            ExitWithResult 0
    fi
    #Invoke the actual freezing command.
    appexample -freeze
    if [ $? -ne 0 ]
    then
            Log "[INFO]:appexample freeze failed."
            #Freezing failed. Record the result and exit.
            ExitWithResult 1
    fi
    Log "[INFO]:Freeze appexample success."
    #Freezing successful. Record the result and exit.
    ExitWithResult 0
}
Main