Как настроить ansible playbook для работы с kornshell - PullRequest
0 голосов
/ 15 апреля 2020

Написание ansible - playbook, для запуска скрипта kornshell.

Как настроить ansible для запуска kornshell на указанном c сервере?

---
- name: Start server manager agent
  hosts: 192.168.1.85
  become: yes
  become_user: jde920
  tasks:

  - name: Set ksh
    shell: ksh (not sure how to set here)

  - name: start Agent
    async: 10
    poll: 0
    shell: "./startAgent"
    args:
      chdir: "/u01/jde_home/SCFHA/bin/"

  - name: Wait for 5 seconds
    wait_for:
      timeout: 5

  - name: Start Service
    async: 10
    poll: 0
    #ansible_shell_executable: ksh
    shell: "./RunOneWorld.sh"
    args:
      chdir: "/u01/jdedwards/e920/system/bin32/"

  - name: Validate Service is up
    tags: JDE_Enterprise
    wait_for:
      host: "localhost"
      port: 6017
      delay: 20
      timeout: 60
      state: started
      msg: "JDE Enterprise Service is not Running"

Мне удалось найти файл, который задает среду $ SYSTEM, ниже приведен код. Имя файла сценария называется enterpriseone. sh

# Following has to be replaced in this file:
#
# ORACLE_HOME (if Oracle is installed)
# DB2DIR (if DB2 is installed)
# DB2INSTANCE name of user owning DB2 instance
# File Updated Tue Mar 05 16:37:23 MYT 2019 - TR 9.2.3
OS_NAME=`uname -s`

EVRHOME=/u01/jdedwards/e920
export EVRHOME

DB2INSTANCE=
export DB2INSTANCE

DB2DIR=
export DB2DIR

DB2BASEDIR=
export DB2BASEDIR

ORCL_USER_ACCT=
export ORCL_USER_ACCT

ORACLE_HOME=/u01/oracle/product/12.1.0/client_1
export ORACLE_HOME

ORACLE_SID=e1db
export ORACLE_SID

set +u
SYSTEM=$EVRHOME/system
export SYSTEM
APPDEV=$EVRHOME/appdev
export APPDEV

#
# Location of INI files
JDE_BASE=$EVRHOME/ini
export JDE_BASE

## Set the binary folder to 32 or 64 bit based on the setup configuration
if [ $OS_NAME = "HP-UX" ]; then
    BUILDTYPE=$(file $SYSTEM/lib/libjdenet.so | grep 'ELF-64')
else
    BUILDTYPE=$(file $SYSTEM/lib/libjdenet.so | grep '64-bit')
fi

if [ -n "$BUILDTYPE" ]; then
   BIN_FOLDER=bin64
else
   BIN_FOLDER=bin32
fi

PATH=$PATH:$SYSTEM/$BIN_FOLDER
export PATH

ICU_DATA=$SYSTEM/locale/xml/
export ICU_DATA

ACRO_RES_DIR=$SYSTEM/resource/cmap
export ACRO_RES_DIR

PSRESOURCEPATH=$SYSTEM/resource/cidfont:$ACRO_RES_DIR
export PSRESOURCEPATH

#
# Call tools service pack specific environment variable
# setup script.  This script is required for running 
# the enterprise server.  If this script does not exist
# in your $SYSTEM/$BIN_FOLDER directory, the E1 Tools Release
# may need to be updated to a newer version.

if [ -f ${SYSTEM}/$BIN_FOLDER/toolsenv.sh ] ; then
      . ${SYSTEM}/$BIN_FOLDER/toolsenv.sh
fi

Ниже приведен фактический сценарий оболочки (RunOneWorld. sh), который я использую ansible для вызова:

## Set the binary folder to 32 or 64 bit based on the setup configuration
OS_NAME=`uname -s`
if [ $OS_NAME = "HP-UX" ]; then
    BUILDTYPE=$(file $SYSTEM/lib/libjdenet.so | grep 'ELF-64')
else
    BUILDTYPE=$(file $SYSTEM/lib/libjdenet.so | grep '64-bit')
fi

if [ -n "$BUILDTYPE" ]; then
   BIN_FOLDER=bin64
else
   BIN_FOLDER=bin32
fi

LOGFILE=$SYSTEM/$BIN_FOLDER"/startstop.log"

## Set START_NEW_LOGFILE=1 if you want to rewrite the logfile at each startup
START_NEW_LOGFILE=0

CLEAR_LOGS=1

## Set MULTI_INSTANCE=1 if you are running multiple instances of OneWorld
## under the same Unix user id.
MULTI_INSTANCE=0

set +u
USER=$(whoami)

HOST=$(hostname)
OSTYPE=$(uname)

## On AIX, process id shows up in column 2, it's column 1 on others...
if [ $OSTYPE = "AIX" ]
  then
    COLUMN=2
  else
    COLUMN=1
fi

unset SILENT_MODE
if [ "$1" = "-s" ] ; then
    SILENT_MODE=1
fi

## In MULTI_INSTANCE mode, we need to be able to find the INI file to get
## certain settings.  If we can't, then exit with an error.
if [ "$MULTI_INSTANCE" = "1" ] ; then
    MFLAG="-m"
    if [ -f ./JDE.INI ] ; then
      PORT_NBR=$(grep "^serviceNameListen" ./JDE.INI | sed 's/.*=//')
    elif [ -f $JDE_BASE/JDE.INI ] ; then
      PORT_NBR=$(grep "^serviceNameListen" $JDE_BASE/JDE.INI | sed 's/.*=//')
    else
      if [ -z "$SILENT_MODE" ] ; then
          print "     This script cannot support multiple instances of"
          print "     OneWorld without access to a JDE.INI file."
          print "     You must either set the $JDE_BASE environment"
          print "     variable correctly, or turn off MULTI_INSTANCE"
          print "     mode in the RunOneWorld.sh script."
          print "       exiting..." 
      fi
      print "     This script cannot support multiple instances of" >> $LOGFILE
      print "     OneWorld without access to a JDE.INI file." >> $LOGFILE
      print "     You must either set the $JDE_BASE environment" >> $LOGFILE
      print "     variable correctly, or turn off MULTI_INSTANCE" >> $LOGFILE
      print "     mode in the RunOneWorld.sh script." >> $LOGFILE
      print "       exiting..."  >> $LOGFILE
      exit 1
    fi
fi

#---------------------------------------------------------------------- #
# FUNCTION DEFINITIONS...
#---------------------------------------------------------------------- #
function GetPIDS
{
  if [ "$MULTI_INSTANCE" = "1" ]
    then
      PIDS=$(ps -ef | grep $USER | grep $PORT_NBR | grep -v grep | awk '{print $2}')
      PIDS="$(ps -ef | grep $USER | grep $SYSTEM | grep -v grep | awk '{print $2}') $PIDS"
    else
      PIDS=$(ps -u $USER | grep jdenet | awk '{print $'$COLUMN'}')
  fi
  if [ "$PIDS" = " " ] ; then
      PIDS=""
  fi
}

function CheckForProcesses
{
  GetPIDS
  if [ -n "$PIDS" ] ; then
      if [ -z "$SILENT_MODE" ] ; then
          print "     There are already OneWorld processes"
          print "     running for this user / instance..."
          print "       exiting..." 
      fi
      print "     There are already OneWorld processes" >> $LOGFILE
      print "     running for this user / instance..." >> $LOGFILE
      print "       exiting..."  >> $LOGFILE
      exit 1
  fi
}

function CheckIPC
{
  $SYSTEM/$BIN_FOLDER/rmics.sh $MFLAG >> $LOGFILE
  if [ ! $? = 0 ] ; then
      if [ -z "$SILENT_MODE" ] ; then
          print "     IPC resource conflict -"
          print "  You may need to change the startIPCKeyValue in your INI file,"
          print "  or your JDE_BASE environment variable may be set incorrectly."
          print "       exiting..." 
      fi
      ## (error message already written to $LOGFILE by rmics.sh)
      exit 1
  fi
}


#---------------------------------------------------------------------- #
# MAIN PROCESSING...
#---------------------------------------------------------------------- #

## First, let's make sure the log file directory is valid - otherwise, all
## of the log messages will disappear.

LOGDIR=$(dirname $LOGFILE)
if [ ! -d $LOGDIR ] ; then
    print " Invalid directory name for LOGFILE - "
    print "  $LOGDIR"
    print " You must correct RunOneWorld.sh and retry."
    exit 1
fi

if [ "$START_NEW_LOGFILE" = "1" ] ; then
    rm $LOGFILE
fi

if [ "$CLEAR_LOGS" = "1" ] ; then
    ## If the log directory is a link, figure out what it points to...
    if [ -L $EVRHOME/log ]; then
        REAL_LOGDIR=$(ls -l $EVRHOME/log | awk '{print $NF}')
    else
        REAL_LOGDIR=$EVRHOME/log
    fi

    rm -rf $REAL_LOGDIR.prev
    mv $REAL_LOGDIR $REAL_LOGDIR.prev
    mkdir $REAL_LOGDIR
fi

print "**********************************************************" >> $LOGFILE
if [ ! $? = 0 ] ; then
    print " Unable to write to the logfile - "
    print "  $LOGFILE"
    print " You might not have permission to write to this file or directory."
    print " Make sure file permissions are set correctly and retry."
    exit 1
fi

if [ -z "$SILENT_MODE" ] ; then
    print "$(date)  Starting JD Edwards OneWorld on $HOST"
fi
print "$(date)  Starting JD Edwards OneWorld on $HOST" >> $LOGFILE

CheckForProcesses

if [ ! "$1" = "-n" ] ; then
   CheckIPC
fi

print "     Starting jdenet_n..." >> $LOGFILE
cd $SYSTEM/$BIN_FOLDER
$SYSTEM/$BIN_FOLDER/jdenet_n > $SYSTEM/$BIN_FOLDER/jdenet_n.log 2>&1 &

sleep 2
GetPIDS
if [ -z "$PIDS" ] ; then
    if [ -z "$SILENT_MODE" ] ; then
        print "     The jdenet_n process did not start..."
        print "       Check the jdenet_n.log, or the log file associated"
        print "       with the jdenet_n process id." 
    fi
    print "     The jdenet_n process did not start..." >> $LOGFILE
    print "       Check the jdenet_n.log, or the log file associated" >> $LOGFILE
    print "       with the jdenet_n process id." >> $LOGFILE
    exit 1
fi

print "     Running cleanup to check for unfinished jobs..." >> $LOGFILE
$SYSTEM/$BIN_FOLDER/cleanup &

if [ -z "$SILENT_MODE" ] ; then
    print "\n$(date)   JD Edwards OneWorld startup complete.\n"
fi
print "\n$(date)   JD Edwards OneWorld startup complete.\n" >> $LOGFILE

exit 0

Итак, чтобы запустить службу, я просто сделаю команду следующим образом: cd $ SYSTEM / bin32 ./RunOneWorld.sh

Ответы [ 2 ]

0 голосов
/ 15 апреля 2020

Я изменил соответственно следующее, но скрипт все еще не запускается.

---
- name: Start server manager agent
  hosts: 192.168.1.85
  become: yes
  become_user: jde920
  tasks:

  - name: start Agent
    async: 10
    poll: 0
    shell: "./startAgent"
    args:
      chdir: "/u01/jde_home/SCFHA/bin/"

  - name: Wait for 5 seconds
    wait_for:
      timeout: 5

  - name: Start JDE Enterprise Service
    async: 10
    poll: 0
    shell: "./RunOneWorld.sh"
    args:
      chdir: "/$SYSTEM/bin32/"
      executable: /usr/bin/ksh

  - name: Validate JDE Enterprise Service is up
    tags: JDE_Enterprise
    wait_for:
      host: "localhost"
      port: 6017
      delay: 20
      timeout: 60
      state: started
      msg: "JDE Enterprise Service is not Running"

Я пытался проверить вручную, и он работает на реальном сервере.

$ /usr/bin/ksh /$SYSTEM/bin32/RunOneWorld.sh
  Wed Apr 15 14:17:03 +08 2020  Starting JD Edwards OneWorld on CBD2ELENT

  Wed Apr 15 14:17:05 +08 2020   JD Edwards OneWorld startup complete.
0 голосов
/ 15 апреля 2020

Для модуля shell используйте параметр executable вместо

  - name: Start Service
    async: 10
    poll: 0
    shell: "./RunOneWorld.sh"
    args:
      chdir: "/u01/jdedwards/e920/system/bin32/"
      executable: /bin/ksh
...