вот текст скрипта:
#!/bin/sh
#
# Copyright (c) 2011-2012 Siemens PLM Software Inc. All rights reserved
# *************************************************************************
# Title: splmld_cntl
# Purpose: Program to shutdown and restart ugslmd & lmgrd daemons.
# *************************************************************************
#Version of Siemens PLM Server
LICENSE_VER=6.4.2.1
# Installation directory of Siemens PLM License Server files.
LICENSE_DIR="/usr/Siemens/PLMLicenseServer"
PATH=/sbin:/usr/sbin:/usr/bin:/bin:"$LICENSE_DIR":$PATH ; export PATH
# Unset any aliases to preclude any colisions.
unalias -a >/dev/null 2>&-
# License file supplied by Siemens PLM Software.
LICENSE_FILE="$LICENSE_DIR/splm6.lic"
# Log file for startup and lmgrd messages.
LOG_FILE="/usr/Siemens/PLMLicenseServer/splm_ugslmd.log"
#Vendor Daemon Name
VENDOR_DAEMON=ugslmd
#License Manager Daemon
LICENSE_DAEMON=lmgrd
#Scriptname
SCRIPTNAME=`basename $0`
#Machine name
MACHINE=`uname`
RESTARTED=0
init() {
# Do a quick check to make sure LICENSE_DIR is still there at runtime. It
# may have been deleted after the install, so just exit as a no-op.
[ -d "${LICENSE_DIR}" ] || {
echo "ERROR: cannot find $LICENSE_DIR"
exit 1
}
# Check whether we can find the license file. Won't run without it.
if [ ! -f "${LICENSE_FILE}" ] || [ ! -r "${LICENSE_FILE}" ] # Check for the file.
then
echo "ERROR: cannot find $LICENSE_FILE"
exit 1
fi
if [ -f "$LOG_FILE" ] && [ ! -w "$LOG_FILE" ] ;
then
echo "ERROR: You do not have enough permission to perform the requested operation"
exit 1
fi
cd "$LICENSE_DIR"
}
#Returns pid and ppid for a process
#Takes process name as argument
get_pid_and_ppid() {
case $MACHINE in
Darwin) #Machine type MacOS
set -- `ps -A | grep -v grep | grep "$1"`
echo $1
;;
*) #All other types
set -- `ps -ef | grep -v grep | grep "$1"`
echo $2 $3
;;
esac
}
#AIX takes more time to start and stop services
wait_if_aix() {
[ $MACHINE = AIX ] && {
sleep 15
}
}
#checks if a process is running or not
is_process_running() {
case $MACHINE in
Darwin) #Machine type MacOS
ps -A | grep -v grep | grep "$1" > /dev/null
;;
*) # All other types
ps -ef | grep -v grep | grep "$1" > /dev/null
;;
esac
}
#print serivce error if any
print_service_status() {
exit_code=$1
[ $exit_code -ne 0 ] && {
echo "ERROR: Could not $2 service $3"
exit $exit_code
}
}
start_daemon() {
#check if vendor daemon is already running
is_process_running $VENDOR_DAEMON && {
echo "Service splmd is already running"
exit 0
}
echo "Starting service splmld. Please wait..."
#If restarted wait for additional time
[ $RESTARTED -eq 1 ] && {
RESTARTED=0
sleep 10
#Wait additional time for AIX to release ports
wait_if_aix
}
# $MAC_FLG is set if started from launchd on MacOS
if [ ! -z "$MAC_FLG" ] && [ "$MACHINE" = "Darwin" ]
then
"$LICENSE_DIR"/lmgrd -c "$LICENSE_FILE" $MAC_FLG >> "$LOG_FILE" 2>&1
else
"$LICENSE_DIR"/lmgrd -c "$LICENSE_FILE" >> "$LOG_FILE" 2>&1
fi
print_service_status $? "start" "$VENDOR_DAEMON"
#Wait for vendor daemon to be up
sleep 5
is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" || {
echo "ERROR: License manager daemon could not be started, please refer to $LOG_FILE for more information"
exit 1
}
is_process_running $VENDOR_DAEMON || {
echo "NOTE: Please wait for a few minutes to fully initialize the vendor daemon (ugslmd)"
exit 0
}
}
stop_daemon() {
is_process_running $VENDOR_DAEMON || is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" || {
echo "Service splmld is already stopped"
exit 0
}
echo "Stopping service splmld. Please wait..."
for PROCESS in "$LICENSE_DIR/$LICENSE_DAEMON" $VENDOR_DAEMON ;
do
retval=`get_pid_and_ppid "$PROCESS"`
pid=`echo "$retval" | awk '{print $1}'` # Assigns pid
ppid=`echo "$retval" | awk '{print $2}'` #Assigns ppid
if [ ! -z "$pid" ] && [ "$PROCESS" = "$LICENSE_DIR/$LICENSE_DAEMON" ]
then
kill -15 $pid > /dev/null 2>&-
print_service_status $? "stop" "$LICENSE_DAEMON"
sleep 15
is_process_running "${PROCESS}" && {
kill -9 $pid > /dev/null 2>&-
print_service_status $? "stop" "$LICENSE_DAEMON"
sleep 15
}
elif [ ! -z "$pid" ] && [ "$PROCESS" = "$VENDOR_DAEMON" ]
then
kill -15 $pid > /dev/null 2>&-
print_service_status $? "stop" "$VENDOR_DAEMON"
sleep 2
[ ! -z "$ppid" ] && [ is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" ] && {
kill -15 $ppid > /dev/null 2>&-
print_service_status $? "stop" "$VENDOR_DAEMON"
sleep 15
}
#Try hard killing it if soft kill fails
is_process_running "${PROCESS}" && {
kill -9 $pid > /dev/null 2>&-
print_service_status $? "stop" "$VENDOR_DAEMON"
sleep 2
[ ! -z "$ppid" ] && [ is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" ] && {
kill -9 $ppid > /dev/null 2>&-
print_service_status $? "stop" "$VENDOR_DAEMON"
sleep 15
}
}
fi
done
#Wait additional time for AIX to release ports
wait_if_aix
}
print_status() {
is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" && {
echo "Checking for service $LICENSE_DAEMON : RUNNING"
} || {
echo "Checking for service $LICENSE_DAEMON : STOPPED"
}
is_process_running $VENDOR_DAEMON && {
echo "Checking for service $VENDOR_DAEMON : RUNNING"
} || {
echo "Checking for service $VENDOR_DAEMON : STOPPED"
}
}
if [ "$MACHINE" = "Darwin" ] && [ ! -z "$2" ]
then
MAC_FLG=$2
fi
case "$1" in
start)
init
start_daemon
;;
stop)
init
stop_daemon
;;
restart)
init
is_process_running $VENDOR_DAEMON || {
start_daemon
exit 0
}
RESTARTED=1
stop_daemon
start_daemon
;;
status)
print_status
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
#
# Copyright (c) 2011-2012 Siemens PLM Software Inc. All rights reserved
# *************************************************************************
# Title: splmld_cntl
# Purpose: Program to shutdown and restart ugslmd & lmgrd daemons.
# *************************************************************************
#Version of Siemens PLM Server
LICENSE_VER=6.4.2.1
# Installation directory of Siemens PLM License Server files.
LICENSE_DIR="/usr/Siemens/PLMLicenseServer"
PATH=/sbin:/usr/sbin:/usr/bin:/bin:"$LICENSE_DIR":$PATH ; export PATH
# Unset any aliases to preclude any colisions.
unalias -a >/dev/null 2>&-
# License file supplied by Siemens PLM Software.
LICENSE_FILE="$LICENSE_DIR/splm6.lic"
# Log file for startup and lmgrd messages.
LOG_FILE="/usr/Siemens/PLMLicenseServer/splm_ugslmd.log"
#Vendor Daemon Name
VENDOR_DAEMON=ugslmd
#License Manager Daemon
LICENSE_DAEMON=lmgrd
#Scriptname
SCRIPTNAME=`basename $0`
#Machine name
MACHINE=`uname`
RESTARTED=0
init() {
# Do a quick check to make sure LICENSE_DIR is still there at runtime. It
# may have been deleted after the install, so just exit as a no-op.
[ -d "${LICENSE_DIR}" ] || {
echo "ERROR: cannot find $LICENSE_DIR"
exit 1
}
# Check whether we can find the license file. Won't run without it.
if [ ! -f "${LICENSE_FILE}" ] || [ ! -r "${LICENSE_FILE}" ] # Check for the file.
then
echo "ERROR: cannot find $LICENSE_FILE"
exit 1
fi
if [ -f "$LOG_FILE" ] && [ ! -w "$LOG_FILE" ] ;
then
echo "ERROR: You do not have enough permission to perform the requested operation"
exit 1
fi
cd "$LICENSE_DIR"
}
#Returns pid and ppid for a process
#Takes process name as argument
get_pid_and_ppid() {
case $MACHINE in
Darwin) #Machine type MacOS
set -- `ps -A | grep -v grep | grep "$1"`
echo $1
;;
*) #All other types
set -- `ps -ef | grep -v grep | grep "$1"`
echo $2 $3
;;
esac
}
#AIX takes more time to start and stop services
wait_if_aix() {
[ $MACHINE = AIX ] && {
sleep 15
}
}
#checks if a process is running or not
is_process_running() {
case $MACHINE in
Darwin) #Machine type MacOS
ps -A | grep -v grep | grep "$1" > /dev/null
;;
*) # All other types
ps -ef | grep -v grep | grep "$1" > /dev/null
;;
esac
}
#print serivce error if any
print_service_status() {
exit_code=$1
[ $exit_code -ne 0 ] && {
echo "ERROR: Could not $2 service $3"
exit $exit_code
}
}
start_daemon() {
#check if vendor daemon is already running
is_process_running $VENDOR_DAEMON && {
echo "Service splmd is already running"
exit 0
}
echo "Starting service splmld. Please wait..."
#If restarted wait for additional time
[ $RESTARTED -eq 1 ] && {
RESTARTED=0
sleep 10
#Wait additional time for AIX to release ports
wait_if_aix
}
# $MAC_FLG is set if started from launchd on MacOS
if [ ! -z "$MAC_FLG" ] && [ "$MACHINE" = "Darwin" ]
then
"$LICENSE_DIR"/lmgrd -c "$LICENSE_FILE" $MAC_FLG >> "$LOG_FILE" 2>&1
else
"$LICENSE_DIR"/lmgrd -c "$LICENSE_FILE" >> "$LOG_FILE" 2>&1
fi
print_service_status $? "start" "$VENDOR_DAEMON"
#Wait for vendor daemon to be up
sleep 5
is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" || {
echo "ERROR: License manager daemon could not be started, please refer to $LOG_FILE for more information"
exit 1
}
is_process_running $VENDOR_DAEMON || {
echo "NOTE: Please wait for a few minutes to fully initialize the vendor daemon (ugslmd)"
exit 0
}
}
stop_daemon() {
is_process_running $VENDOR_DAEMON || is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" || {
echo "Service splmld is already stopped"
exit 0
}
echo "Stopping service splmld. Please wait..."
for PROCESS in "$LICENSE_DIR/$LICENSE_DAEMON" $VENDOR_DAEMON ;
do
retval=`get_pid_and_ppid "$PROCESS"`
pid=`echo "$retval" | awk '{print $1}'` # Assigns pid
ppid=`echo "$retval" | awk '{print $2}'` #Assigns ppid
if [ ! -z "$pid" ] && [ "$PROCESS" = "$LICENSE_DIR/$LICENSE_DAEMON" ]
then
kill -15 $pid > /dev/null 2>&-
print_service_status $? "stop" "$LICENSE_DAEMON"
sleep 15
is_process_running "${PROCESS}" && {
kill -9 $pid > /dev/null 2>&-
print_service_status $? "stop" "$LICENSE_DAEMON"
sleep 15
}
elif [ ! -z "$pid" ] && [ "$PROCESS" = "$VENDOR_DAEMON" ]
then
kill -15 $pid > /dev/null 2>&-
print_service_status $? "stop" "$VENDOR_DAEMON"
sleep 2
[ ! -z "$ppid" ] && [ is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" ] && {
kill -15 $ppid > /dev/null 2>&-
print_service_status $? "stop" "$VENDOR_DAEMON"
sleep 15
}
#Try hard killing it if soft kill fails
is_process_running "${PROCESS}" && {
kill -9 $pid > /dev/null 2>&-
print_service_status $? "stop" "$VENDOR_DAEMON"
sleep 2
[ ! -z "$ppid" ] && [ is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" ] && {
kill -9 $ppid > /dev/null 2>&-
print_service_status $? "stop" "$VENDOR_DAEMON"
sleep 15
}
}
fi
done
#Wait additional time for AIX to release ports
wait_if_aix
}
print_status() {
is_process_running "$LICENSE_DIR/$LICENSE_DAEMON" && {
echo "Checking for service $LICENSE_DAEMON : RUNNING"
} || {
echo "Checking for service $LICENSE_DAEMON : STOPPED"
}
is_process_running $VENDOR_DAEMON && {
echo "Checking for service $VENDOR_DAEMON : RUNNING"
} || {
echo "Checking for service $VENDOR_DAEMON : STOPPED"
}
}
if [ "$MACHINE" = "Darwin" ] && [ ! -z "$2" ]
then
MAC_FLG=$2
fi
case "$1" in
start)
init
start_daemon
;;
stop)
init
stop_daemon
;;
restart)
init
is_process_running $VENDOR_DAEMON || {
start_daemon
exit 0
}
RESTARTED=1
stop_daemon
start_daemon
;;
status)
print_status
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
2) куда скрипт запихнуть?