Histórico da Página
Para a inicialização dos serviços por meio de scripts, será é necessário criá-los no diretório /etc/init.d/
Copie o conteúdo pertinente de cada script, e caso não tenha utilizado . Se os caminhos sugeridos neste manual não foram utilizados, altere-os nos scripts para não se deparar com ocorrerem erros do tipo “Programa Programa não instalado”instalado.
Dica |
---|
Os scripts já estão parametrizados para iniciar, parar e reiniciar (start, stop e restart) os serviços necessários para o Protheus. |
Nota | ||
---|---|---|
| ||
Estes scripts estão parametrizados para RedHat, Oracle Linux e SUSE. |
Utilize Você pode utilizar o comando vim para abrir um novo arquivo no diretório:[root@tpsrv01 ~]# vim /etc/init.d/totvsappbalance
Bloco de código | ||
---|---|---|
| ||
[root@tpsrv01 ~]# vim /etc/init.d/ |
...
totvsappbroker [root@tpsrv01 ~]# vim /etc/init.d/ |
...
totvsappsec01 [root@tpsrv01 ~]# vim /etc/init.d/ |
...
totvsappsec02 [root@tpsrv01 ~]# vim /etc/init.d/totvsdbaccess |
...
[root@tpsrv01 ~]# vim /etc/init.d/totvslicensesrv |
Para cada execução do comando vim, será aberto o editor de texto do Linux.
Aviso |
---|
♦ A partir da release 12.1.2210, o LockServer não é mais utilizado. |
Conteúdo dos scripts
Bloco de códigoexpand | ||||||
---|---|---|---|---|---|---|
| ||||||
#ckconfig: 2345 84 10 #description: Starts and stops DBAccess ######################################### # CONFIGURACAO DO SERVICO # ######################################### #Inserir o nome do executavel prog="dbaccess64" #Inserir o caminho do diretorio do executavel pathbin="/totvs/protheus/microsiga bin/dbaccess" progbin="${pathbin}/${prog}" pidfile="/var/run/${prog}.pid" lockfile="/var/lock/subsys/${prog}" ################################################################# #Configuracao de ULIMIT # ################################################################# #open files - (-n) openFiles=65536 #stack size - (kbytes, -s) stackSize=1024 #core file size - (blocks, -c) coreFileSize=unlimited #file size - (blocks, -f) fileSize=unlimited #cpu time - (seconds, -t) cpuTime=unlimited #virtual memory - (-v) virtualMemory=unlimited ################################# # FIM DA CONFIGURACAO # ################################# ################################# ################################# #Source function library. functions="/etc/init.d/functions" if [ -e ${functions} ] ; then . /etc/init.d/functions else echo "$functions not installed" exit 5 fi RETVAL=0 #Verifica se o executavel tem permissao correta e se esta acessivel test -x $progbin || { echo "$progbin not installed"; if [ "$1" = "stop" ]; then exit 0; else exit 5; fi;} #Prepara as ulimit para o servico do DBAccess ulimit -n} #Exporta o caminho da aplicacao como outro caminho que contem as bibliotecas export LD_LIBRARY_PATH=${pathbin}:${LD_LIBRARY_PATH} #Prepara as ulimit para o servico do DBAccess ulimit -n ${openFiles} ulimit -s ${stackSize} ulimit -c ${coreFileSize} ulimit -f ${fileSize} ulimit -t ${cpuTime} ulimit -v ${virtualMemory} #Acessa o diretorio configurado na variavel PATHBIN cd $pathbin #Variaveis de Output red=`tput setaf 1` green=`tput setaf 2` reset=`tput sgr0` #Function Start start() { if [ -z `pidof -x $progbin` ] ; then echo "Starting $prog... " daemon $progbin >/dev/null & #exec ./${prog} >/dev/null & RETVAL=$? if [ ${RETVAL} -eq 0 ]; then touch ${lockfile} touch ${pidfile} pidof -x ${progbin} > ${pidfile} sleep 1 echo "PID : " `cat ${pidfile}` echo "${prog} running : ${green}[ OK ]${reset}" else echo "Failed to start ${prog} : ${red}[ Failure ]${reset}" fi echo else echo "$prog is ${green}Started${reset} pid `pidof -x $progbin`" fi } #Function Stop stop() { if [ ! -z `pidof -x ${progbin}` ] ; then killproc $progbin #pkill -f ${prog} echo rm -f $lockfile rm -f $pidfile echo -n "Stopping ${prog}." while [ ! -z `pidof -x ${progbin}` ] do echo -n "." sleep 1 done echo echo "${prog} is Stopped ${red}[ Stopped ]${reset}" else echo "${prog} is not running ${red}[ Stopped ]${reset}" fi } status() { pid=$(pidof -x ${progbin}) progport=$(lsof -Pp ${pid} | grep '(LISTEN)' | awk '{ print $9}' | cut -d: -f2 | xargs) list=$(ps -eo pid,start_time,cputime,pcpu,pmem,stat,size,nlwp,comm | grep ${pid}) start_time=$(echo $list | awk '{ print $2 }') cputime=$(echo $list | awk '{ print $3 }') pcpu=$(echo $list | awk '{ print $4 }') pmem=$(echo $list | awk '{ print $5 }') stat=$(echo $list | awk '{ print $6 }') size=$(echo $list | awk '{ print $7 }') nlwp=$(echo $list | awk '{ print $8 }') comm=$(echo $list | awk '{ print $9 }') size=$(echo "$(bc <<< "scale=2;$size/1024") MB") echo "PROCESS : ${comm}" echo "PORT : ${progport}" echo "PID : ${pid}" echo "STARTED : ${start_time}" echo "TIME : ${cputime}" echo "%CPU : ${pcpu}" echo "%MEM : ${pmem}" echo "MEMORY : ${size}" echo "STATUS : ${stat} ${green}[ running ]${reset}" echo "THREADS : ${nlwp}" } #MAIN case "$1" in start) start ;; stop) stop ;; status) if [ ! -z `pidof -x $progbin` ] ; then echo "Status process : ${green}[ OK ]${reset}" status else echo "Status process : ${red}[ Failure ]${reset}" echo "Program $prog is not running!" fi ;; restart) stop sleep 10 start sleep 10 status ;; condrestart) if test "x`pidof -x $progbin`" != x; then stop start fi ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" exit 1 esac exit 0 |
Bloco de códigoexpand | ||||||
---|---|---|---|---|---|---|
| ||||||
#ckconfig: 2345 84 10 #description: Starts and stops program ################################# # CONFIGURACAO DO SERVICO # ################################# #Inserir o nomedo executavel do executavel prog="appsrvlinux" #Inserir o caminho do diretorio do executavel pathbin="/totvs/microsiga/protheus12 protheus/bin/applocksrv appsec01" ################################# # Configuracao de ULIMIT # ################################# #open files - (-n) openFiles=65536 #stack size - (kbytes, -s) stackSize=1024 #core file size - (blocks, -c) coreFileSize=unlimited #file size - (blocks, -f) fileSize=unlimited #cpu time - (seconds, -t) cpuTime=unlimited #virtual memory - (-v) virtualMemory=unlimited ######################### # FIM DA CONFIGURACAO # ######################### #Caminho absoluto do executavel progbin="${pathbin}/${prog}" #Caminho absoluto do arquivo .pid pidfile="/var/run/${prog}.pid" #Caminho absoluto do arquilo de lock lockfile="/var/lock/subsys/${prog}" #Caminho absoluto do arquivo de log (script) logfile="${pathbin}/log_${prog}.log" #Source function library. functions="/etc/init.d/functions" if [ -e ${functions} ] ; then . /etc/init.d/functions else echo "$functions not installed" exit 5 fi RETVAL=0 #Verifica se o executavel tem permissao correta e se esta acessivel test -x $progbin || { echo "$progbin not installed";if if [ "$1" = "stop" ]; then exit 0;else else exit 5; fi;} #Prepara as ulimit para o servico ulimit -n} #Exporta o caminho da aplicacao como outro caminho que contem as bibliotecas export LD_LIBRARY_PATH=${pathbin}:${LD_LIBRARY_PATH} #Prepara as ulimit para o servico ulimit -n ${openFiles} ulimit -s ${stackSize} ulimit -c ${coreFileSize} ulimit -f ${fileSize} ulimit -t ${cpuTime} ulimit -v ${virtualMemory} #Variaveis de Output red=`tput setaf 1` green=`tput setaf 2` reset=`tput sgr0` logmsg="$(date) | $(whoami) | $0 | $1 |" #Acessa o diretorio configurado na variavel PATHBIN cd ${pathbin} #Function Start start() { if [ -z `pidof -x ${prog}` ] ; thenecho echo "Starting ${prog}... "exec exec ./${prog} >/dev/null &RETVAL RETVAL=$?if if [ ${RETVAL} -eq 0 ]; thentouch touch ${lockfile}touch touch ${pidfile}pidof pidof -x ${prog} > ${pidfile} sleep 1 echosleep 1 echo "PID : `cat ${pidfile}`"echo echo "${prog} running : ${green}[ OK ]${reset}"echo echo "${logmsg} ${prog} Started" >> ${logfile} else echoelse echo "Failed to start ${prog} : ${red}[ Failure ]${reset}"echo echo "${logmsg} Failed to start ${prog}" >> ${logfile} fi echo else echofi echo else echo "${prog} is ${green}Started${reset} pid `pidof -x ${prog}`"echo echo "${logmsg} ${prog} already started" >> ${logfile} fi } #Function Stop stop() { if [ ! -z `pidof -x ${prog}` ] ; thenkillproc killproc ${prog} >/dev/null &#pkill #pkill -f ${prog} echo rmecho rm -f $lockfilerm rm -f$pidfile echo $pidfile echo -n "Stopping ${prog}."while while [ ! -z `pidof -x ${prog}`] do echo] do echo -n "." sleep 1 done echo echosleep 1 done echo echo "${prog} is Stopped ${red}[ Stopped ]${reset}"echo echo "${logmsg} ${prog} stopped" >> ${logfile} else echoelse echo "${prog} is not running ${red}[ Stopped ]${reset}"echo echo "${logmsg} ${prog} already stopped" >> ${logfile} fi } #Function Status status() { pid=$(pidof -x ${prog}) progport=$(lsof -Pp ${pid} | grep '(LISTEN)' | awk '{ print $9}' | cut -d: -f2 | xargs) list=$(ps -eo pid,start_time,cputime,pcpu,pmem,stat,size,nlwp,comm | grep ${pid}) start_time=$(echo $list | awk '{ print $2 }') cputime=$(echo $list | awk '{ print $3 }') pcpu=$(echo $list | awk '{ print $4 }') pmem=$(echo $list | awk '{ print $5 }') stat=$(echo $list | awk '{ print $6 }') size=$(echo $list | awk '{ print $7 }') nlwp=$(echo $list | awk '{ print $8 }') comm=$(echo $list | awk '{ print $9 }') size=$(echo "$(bc <<< "scale=2;$size/1024") MB") echo "PROCESS : ${comm}" echo"PORT : "PORT : ${progport}" echo "PID: : ${pid}" echo "STARTED : ${start_time}" echo"TIME : "TIME : ${cputime}" echo"%CPU : "%CPU : ${pcpu}" echo"%MEM : "%MEM : ${pmem}" echo"MEMORY : "MEMORY : ${size}" echo"STATUS : "STATUS : ${green}[ running ]${reset}" echo "THREADS : ${nlwp}" } #MAIN case "$1" in start) start start ;; stop) stop stop ;; status)if if [ ! -z `pidof -x ${prog}` ] ; thenecho echo "Status process : ${green}[ OK ]${reset}" status else echo "Status process :status else echo "Status process : ${red}[ Failure ]${reset}"echo echo "Program $prog is not running!" fi fi ;; restart) stop sleep 2 start sleep 2 status ;; log) catstop sleep 2 start sleep 2 status ;; log) cat ${logfile}echo echo "More details at ${logfile}" ;; *)echo echo $"Usage: $0 {start|stop|restart|status|log}" exit 1 esac exit 0 | ||||||
Expandir | ||||||
exit 1
esac
exit 0
|
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#ckconfig: 2345 84 10 #description: Starts and stops program ################################# # CONFIGURACAO DO SERVICO # ################################# #Inserir o nomedo executavel do executavel prog="appsrvlinux" #Inserir o caminho do diretorio do executavel pathbin="/totvs/microsiga protheus/protheus12/ bin/ appslv01appsec02" ################################# # Configuracao de ULIMIT # ################################# #open files - (-n) openFiles=65536 #stack size - (kbytes, -s) stackSize=1024 #core file size - (blocks, -c) coreFileSize=unlimited #file size - (blocks, -f) fileSize=unlimited #cpu time - (seconds, -t) cpuTime=unlimited #virtual memory - (-v) virtualMemory=unlimited ######################### # FIM DA CONFIGURACAO # ######################### #Caminho absoluto do executavel progbin="${pathbin}/${prog}" #Caminho absoluto do arquivo .pid pidfile="/var/run/${prog}.pid" #Caminho absoluto do arquilo de lock lockfile="/var/lock/subsys/${prog}" #Caminho absoluto do arquivo de log (script) logfile="${pathbin}/log_${prog}.log" #Source function library. functions="/etc/init.d/functions" if [ -e ${functions} ] ; then . /etc/init.d/functions else echo "$functions not installed" exit 5 fi RETVAL=0 #Verifica se o executavel tem permissao correta e se esta acessivel test -x $progbin || { echo "$progbin not installed";if [ if [ "$1" = "stop" ]; then exit 0;else exit else exit 5; fi;} #Prepara as ulimit para o servico ulimit -n} #Exporta o caminho da aplicacao como outro caminho que contem as bibliotecas export LD_LIBRARY_PATH=${pathbin}:${LD_LIBRARY_PATH} #Prepara as ulimit para o servico ulimit -n ${openFiles} ulimit -s ${stackSize} ulimit -c ${coreFileSize} ulimit -f ${fileSize} ulimit -t ${cpuTime} ulimit -v ${virtualMemory} #Variaveis de Output red=`tput setaf 1` green=`tput setaf 2` reset=`tput sgr0` logmsg="$(date) | $(whoami) | $0 | $1 |" #Acessa o diretorio configurado na variavel PATHBIN cd ${pathbin} #Function Start start() { if [ -z `pidof -x ${prog}` ] ;then echo then echo "Starting ${prog}..." exec " exec ./${prog} >/dev/null& RETVAL & RETVAL=$?if [ if [ ${RETVAL} -eq 0 ];then touch then touch ${lockfile}touch touch ${pidfile}pidof -x pidof -x ${prog} > ${pidfile} sleep 1 echo "PID : `catsleep 1 echo "PID : `cat ${pidfile}`"echo echo "${prog} running : ${green}[ OK ]${reset}"echo echo "${logmsg} ${prog} Started" >> ${logfile} else echoelse echo "Failed to start ${prog}: : ${red}[ Failure ]${reset}"echo echo "${logmsg} Failed to start ${prog}" >> ${logfile} fi echo else echofi echo else echo "${prog} is ${green}Started${reset} pid `pidof -x ${prog}`"echo echo "${logmsg} ${prog} already started" >> ${logfile} fi } #Function Stop stop() { if [ ! -z `pidof -x ${prog}` ] ;then killproc then killproc ${prog} >/dev/null& #pkill & #pkill -f ${prog} echo rmecho rm -f$lockfile rm $lockfile rm -f$pidfile echo $pidfile echo -n "Stopping ${prog}."while [ ! while [ ! -z `pidof -x ${prog}`] do echo -n "." sleep 1 done echo echo] do echo -n "." sleep 1 done echo echo "${prog} isStopped Stopped ${red}[ Stopped ]${reset}"echo echo "${logmsg} ${prog} stopped" >> ${logfile} else echoelse echo "${prog} is not running ${red}[ Stopped ]${reset}"echo echo "${logmsg} ${prog} already stopped" >> ${logfile} fi } #Function Status status() { pid=$(pidof -x ${prog}) progport=$(lsof -Pp ${pid} | grep '(LISTEN)' | awk '{ print $9}' | cut -d: -f2 | xargs) list=$(ps -eo pid,start_time,cputime,pcpu,pmem,stat,size,nlwp,comm | grep ${pid}) start_time=$(echo $list | awk '{ print $2 }') cputime=$(echo $list | awk '{ print $3 }') pcpu=$(echo $list | awk '{ print $4 }') pmem=$(echo $list | awk '{ print $5 }') stat=$(echo $list | awk '{ print $6 }') size=$(echo $list | awk '{ print $7 }') nlwp=$(echo $list | awk '{ print $8 }') comm=$(echo $list | awk '{ print $9 }') size=$(echo "$(bc <<< "scale=2;$size/1024") MB")echo "PROCESS : echo "PROCESS : ${comm}" echo"PORT : "PORT : ${progport}" echo"PID : "PID : ${pid}" echo"STARTED : "STARTED : ${start_time}" echo"TIME : "TIME : ${cputime}" echo"%CPU : "%CPU : ${pcpu}" echo"%MEM : "%MEM : ${pmem}" echo"MEMORY : "MEMORY : ${size}" echo"STATUS : "STATUS : ${green}[ running ]${reset}" echo "THREADS: : ${nlwp}" } #MAIN case "$1" in start) start start ;; stop) stop ;; status) if [ ! -z `pidof -xstop) stop ;; status) if [ ! -z `pidof -x ${prog}` ] ;then echo then echo "Statusprocess : process : ${green}[ OK ]${reset}" status else echo "Status process :status else echo "Status process : ${red}[ Failure ]${reset}" echo "Program $prog is not running!" fi ;; restart) stop sleep 2 start sleep 2 status ;; log) cat ${logfile} echo "More details at ${logfile}" ;; *) echo $"Usage: $0echo "Program $prog is not running!" fi ;; restart) stop sleep 2 start sleep 2 status ;; log) cat ${logfile} echo "More details at ${logfile}" ;; *) echo $"Usage: $0 {start|stop|restart|status|log}" exit 1 esac exit 0 |
Expandir | ||
---|---|---|
| ||
#ckconfig: 2345 84 10 #description: Starts and stops program ################################# # CONFIGURACAO DO SERVICO # ################################# #Inserir o nome do executavel prog="appsrvlinux" #Inserir o caminho do diretorio do executavel pathbin="/totvs/microsiga/protheus12/bin/appslv02" ################################# # Configuracao de ULIMIT # ################################# #open files - (-n) openFiles=65536 #stack size - (kbytes, -s) stackSize=1024 #core file size - (blocks, -c) coreFileSize=unlimited #file size - (blocks, -f) fileSize=unlimited #cpu time - (seconds, -t) cpuTime=unlimited #virtual memory - (-v) virtualMemory=unlimited ######################### # FIM DA CONFIGURACAO # ######################### #Caminho absoluto do executavel progbin="${pathbin}/${prog}" #Caminho absoluto do arquivo .pid pidfile="/var/run/${prog}.pid" #Caminho absoluto do arquilo de lock lockfile="/var/lock/subsys/${prog}" #Caminho absoluto do arquivo de log (script) logfile="${pathbin}/log_${prog}.log" #Source function library. functions="/etc/init.d/functions" if [ -e ${functions} ] ; then . /etc/init.d/functions else echo "$functions not installed" exit 5 fi RETVAL=0 #Verifica se o executavel tem permissao correta e se esta acessivel test -x $progbin || { echo "$progbin not installed"; if [ "$1" = "stop" ]; then exit 0; else exit 5; fi; } #Prepara as ulimit para o servico ulimit -n ${openFiles} ulimit -s ${stackSize} ulimit -c ${coreFileSize} ulimit -f ${fileSize} ulimit -t ${cpuTime} ulimit -v ${virtualMemory} #Variaveis de Output red=`tput setaf 1` green=`tput setaf 2` reset=`tput sgr0` logmsg="$(date) | $(whoami) | $0 | $1 |" #Acessa o diretorio configurado na variavel PATHBIN cd ${pathbin} #Function Start start() { if [ -z `pidof -x ${prog}` ] ; then echo "Starting ${prog}... " exec ./${prog} >/dev/null & RETVAL=$? if [ ${RETVAL} -eq 0 ]; then touch ${lockfile} touch ${pidfile} pidof -x ${prog} > ${pidfile} sleep 1 echo "PID : `cat ${pidfile}`" echo "${prog} running : ${green}[ OK ]${reset}" echo "${logmsg} ${prog} Started" >> ${logfile} else echo "Failed to start ${prog} : ${red}[ Failure ]${reset}" echo "${logmsg} Failed to start ${prog}" >> ${logfile} fi echo else echo "${prog} is ${green}Started${reset} pid `pidof -x ${prog}`" echo "${logmsg} ${prog} already started" >> ${logfile} fi } #Function Stop stop() { if [ ! -z `pidof -x ${prog}` ] ; then killproc ${prog} >/dev/null & #pkill -f ${prog} echo rm -f $lockfile rm -f $pidfile echo -n "Stopping ${prog}." while [ ! -z `pidof -x ${prog}` ] do echo -n "." sleep 1 done echo echo "${prog} is Stopped ${red}[ Stopped ]${reset}" echo "${logmsg} ${prog} stopped" >> ${logfile} else echo "${prog} is not running ${red}[ Stopped ]${reset}" echo "${logmsg} ${prog} already stopped" >> ${logfile} fi } #Function Status status() { pid=$(pidof -x ${prog}) progport=$(lsof -Pp ${pid} | grep '(LISTEN)' | awk '{ print $9}' | cut -d: -f2 | xargs) list=$(ps -eo pid,start_time,cputime,pcpu,pmem,stat,size,nlwp,comm | grep ${pid}) start_time=$(echo $list | awk '{ print $2 }') cputime=$(echo $list | awk '{ print $3 }') pcpu=$(echo $list | awk '{ print $4 }') pmem=$(echo $list | awk '{ print $5 }') stat=$(echo $list | awk '{ print $6 }') size=$(echo $list | awk '{ print $7 }') nlwp=$(echo $list | awk '{ print $8 }') comm=$(echo $list | awk '{ print $9 }') size=$(echo "$(bc <<< "scale=2;$size/1024") MB") echo "PROCESS : ${comm}" echo "PORT : ${progport}" echo "PID : ${pid}" echo "STARTED : ${start_time}" echo "TIME : ${cputime}" echo "%CPU : ${pcpu}" echo "%MEM : ${pmem}" echo "MEMORY : ${size}" echo "STATUS : ${green}[ running ]${reset}" echo "THREADS : ${nlwp}" } #MAIN case "$1" in start) start ;; stop) stop ;; status) if [ ! -z `pidof -x ${prog}` ] ; then echo "Status process : ${green}[ OK ]${reset}" status else echo "Status process : ${red}[ Failure ]${reset}" echo "Program $prog is not running!" fi ;; restart) stop sleep 2 start sleep 2 status ;; log) cat ${logfile} echo "More details at ${logfile}" ;; *) echo $"Usage: $0 {start|stop|restart|status|log}" exit 1 esac exit 0 |
exit 1
esac
exit 0 |
Bloco de código | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/bin/bash
#description: Starts and stops
#########################################
# CONFIGURACAO DO SERVICO #
#########################################
#Inserir o nome do executavel
prog="appsrvlinux"
# Substitua para o tipo do broker
# Tipos possiveis:
# balance_smart_client_desktop
# balance_http
# balance_telnet
# balance_web_services
# Confira a doc em https://tdn.totvs.com/display/tec/Balanceamento+de+carga+com+broker
broker_type="BROKER_REPLACE"
#Inserir o caminho do diretorio do executavel
pathbin="/totvs/protheus/bin/appbroker"
progbin="${pathbin}/${prog}"
pidfile="/var/run/${prog}.pid"
lockfile="/var/lock/subsys/${prog}"
#################################################################
#Configuracao de ULIMIT
#################################################################
#open files - (-n)
openFiles=65536
#stack size - (kbytes, -s)
stackSize=1024
#core file size - (blocks, -c)
coreFileSize=unlimited
#file size - (blocks, -f)
fileSize=unlimited
#cpu time - (seconds, -t)
cpuTime=unlimited
#virtual memory - (-v)
virtualMemory=unlimited
#################################
# FIM DA CONFIGURACAO #
#################################
##################################################################
##################################################################
#Source function library.
| ||||||
Expandir | ||||||
| ||||||
#ckconfig: 2345 84 10 #description: Starts and stops program ################################# # CONFIGURACAO DO SERVICO # ################################# #Inserir o nome do executavel prog="appsrvlinux" #Inserir o caminho do diretorio do executavel pathbin="/totvs/microsiga/protheus12/bin/appbalance" ################################# # Configuracao de ULIMIT # ################################# #open files - (-n) openFiles=65536 #stack size - (kbytes, -s) stackSize=1024 #core file size - (blocks, -c) coreFileSize=unlimited #file size - (blocks, -f) fileSize=unlimited #cpu time - (seconds, -t) cpuTime=unlimited #virtual memory - (-v) virtualMemory=unlimited ######################### # FIM DA CONFIGURACAO # ######################### #Caminho absoluto do executavel progbin="${pathbin}/${prog}" #Caminho absoluto do arquivo .pid pidfile="/var/run/${prog}.pid" #Caminho absoluto do arquilo de lock lockfile="/var/lock/subsys/${prog}" #Caminho absoluto do arquivo de log (script) logfile="${pathbin}/log_${prog}.log" #Source function library. functions="/etc/init.d/functions" if [ -e ${functions} ] ; then . /etc/init.d/functions else echo "$functions not installed" exit 5 fi RETVAL=0 #Verifica se o executavel tem permissao correta e se esta acessivel test -x $progbin || { echo "$progbin not installed";if [ if [ "$1" = "stop" ]; then exit 0;else exit else exit 5; fi; } #Prepara as ulimit para o servico do DBAccess ulimit -n ${openFiles} ulimit -s ${stackSize} ulimit -c ${coreFileSize} ulimit -f ${fileSize} ulimit -t ${cpuTime} ulimit -v ${virtualMemory} #Variaveis de Output #Acessa o diretorio configurado na variavel PATHBIN cd $pathbin #Variaveis de Output red=`tput setaf 1` green=`tput setaf 2` reset=`tput sgr0` logmsg="$(date) | $(whoami) | $0 | $1 |" #Acessa o diretorio configurado na variavel PATHBIN cd ${pathbin} #Function Start start() { if [ -z `pidof -x ${prog}` ] ; then echo "Starting ${prog}... " exec ./${prog} >/dev/null & RETVAL=$? if [ ${RETVAL} -eq 0 ]; then touch ${lockfile} touch ${pidfile} pidof -x ${prog} > ${pidfile} sleep 1 echo "PID : `cat ${pidfile}`" echo "${prog} running : ${green}[ OK ]${reset}" echo "${logmsg} ${prog} Started" >> ${logfile} else echo "Failed to start ${prog} : ${red}[ Failure ]${reset}" echo "${logmsg} Failed to start ${prog}" >> ${logfile} fi echo else echo "${prog} isreset=`tput sgr0` export LD_LIBRARY_PATH=${pathbin} #Function Start start() { if [ -z `pidof -x $progbin` ] ; then echo "Starting $prog... " daemon $progbin -${broker_type} -a >/dev/null & #exec ./${prog} >/dev/null & RETVAL=$? if [ ${RETVAL} -eq 0 ]; then touch ${lockfile} touch ${pidfile} pidof -x ${progbin} > ${pidfile} sleep 1 echo "PID : " `cat ${pidfile}` echo "${prog} running : ${green}[ OK ]${reset}" else echo "Failed to start ${prog} : ${red}[ Failure ]${reset}" fi echo else echo "$prog is ${green}Started${reset} pid `pidof -x${prog}`" echo "${logmsg} ${prog} already started" >> ${logfile} fi } #Function Stop stop() { if [ ! -z `pidof -x ${prog}` ] ; then killproc ${prog} >/dev/null & #pkill -f ${prog} echo rm -f $lockfile rm -f $pidfile echo -n "Stopping ${prog}." while [ ! -z `pidof -x ${prog}` ] do echo -n "." sleep 1 done echo echo "${prog} is Stopped ${red}[ Stopped ]${reset}" echo "${logmsg} ${prog} stopped" >> ${logfile} else echo "${prog} is not running ${red}[ Stopped ]${reset}" echo "${logmsg} ${prog} already stopped" >> ${logfile} fi } #Function Status status() { pid=$(pidof -x ${prog}) progport=$(lsof -Pp ${pid} | grep '(LISTEN)' | awk '{ print $9}' | cut -d: -f2 | xargs) list=$(ps -eo$progbin`" fi } #Function Stop stop() { if [ ! -z `pidof -x ${progbin}` ] ; then #killproc $progbin #pkill -f ${prog} daemon $progbin -${broker_type} -o echo rm -f $lockfile rm -f $pidfile echo -n "Stopping ${prog}." while [ ! -z `pidof -x ${progbin}` ] do echo -n "." sleep 1 done echo echo "${prog} is Stopped ${red}[ Stopped ]${reset}" else echo "${prog} is not running ${red}[ Stopped ]${reset}" fi } status() { pid=$(pidof -x ${progbin}) progport=$(lsof -Pp ${pid} | grep '(LISTEN)' | awk '{ print $9}' | cut -d: -f2 | xargs) list=$(ps -eo pid,start_time,cputime,pcpu,pmem,stat,size,nlwp,comm | grep ${pid}) start_time=$(echo $list | awk '{ print $2 }') cputime=$(echo $list | awk '{ print $3 }') pcpu=$(echo $list | awk '{ print $4 }') pmem=$(echo $list | awk '{ print $5 }') stat=$(echo $list | awk '{ print $6 }') size=$(echo $list | awk '{ print $7 }') nlwp=$(echo $list | awk '{ print $8 }') comm=$(echo $list | awk '{ print $9 }') size=$(echo "$(bc <<< "scale=2;$size/1024") MB") echo "PROCESS: : ${comm}" echo"PORT : "PORT : ${progport}" echo"PID : "PID : ${pid}" echo "STARTED: : ${start_time}" echo "TIME : ${cputime}" echo "%CPU : ${pcpu}" echo "%MEM : ${pmem}" echo "MEMORY : ${size}" echo "STATUS : ${green}[ runningecho "TIME : ${cputime}" echo "%CPU : ${pcpu}" echo "%MEM : ${pmem}" echo "MEMORY : ${size}" echo "STATUS : ${stat} ${green}[ running ]${reset}" echo "THREADS: : ${nlwp}" } #MAIN case} #MAIN case "$1" in start) start start ;; stop) stop ;; status) if [ ! -z `pidof -x ${prog}` ] ; then echo "Status process :stop ;; status) if [ ! -z `pidof -x $progbin` ] ; then echo "Status process : ${green}[ OK ]${reset}" status else echo "Status process :status else echo "Status process : ${red}[ Failure ]${reset}"echo echo "Program $prog is not running!" fi fi ;; restart) stop sleep 2 start sleep 2 status ;; log) cat ${logfile} echo "More details at ${logfile}" ;; *) echo $"Usage: $0restart) stop sleep 10 start sleep 10 status ;; condrestart) if test "x`pidof -x $progbin`" != x; then stop start fi ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status|log }" exit 1 esac exit 0 | ||||||
exit 1
esac
exit 0 |
Bloco de código | ||||||
---|---|---|---|---|---|---|
| ||||||
#ckconfig: 2345 84 10 #description: Starts and stops program ################################# # CONFIGURACAO DO SERVICO # ################################# #Inserir o nomedo executavel do executavel prog="appsrvlinux" #Inserir o caminho do diretorio do executavel pathbin="/totvs/protheus/bin/licenseserver" ################################# # Configuracao de ULIMIT # ################################# #open files - (-n) openFiles=65536 #stack size - (kbytes, -s) stackSize=1024 #core file size - (blocks, -c) coreFileSize=unlimited #file size - (blocks, -f) fileSize=unlimited #cpu time - (seconds, -t) cpuTime=unlimited #virtual memory - (-v) virtualMemory=unlimited ######################### # FIM DA CONFIGURACAO # ######################### #Caminho absoluto do executavel progbin="${pathbin}/${prog}" #Caminho absoluto do arquivo .pid pidfile="/var/run/${prog}.pid" #Caminho absoluto do arquilo de lock lockfile="/var/lock/subsys/${prog}" #Caminho absoluto do arquivo de log (script) logfile="${pathbin}/log_${prog}.log" #Source function library. functions="/etc/init.d/functions" if [ -e ${functions} ] ; then . /etc/init.d/functions else echo "$functions not installed" exit 5 fi RETVAL=0 #Verifica se o executavel tem permissao correta e se esta acessivel test -x $progbin || { echo "$progbin not installed";if [ if [ "$1" = "stop" ]; then exit 0;else exit else exit 5; fi;} #Prepara as ulimit para o servico ulimit -n} #Exporta o caminho da aplicacao como outro caminho que contem as bibliotecas export LD_LIBRARY_PATH=${pathbin}:${LD_LIBRARY_PATH} #Prepara as ulimit para o servico ulimit -n ${openFiles} ulimit -s ${stackSize} ulimit -c ${coreFileSize} ulimit -f ${fileSize} ulimit -t ${cpuTime} ulimit -v ${virtualMemory} #Variaveis de Output red=`tput setaf 1` green=`tput setaf 2` reset=`tput sgr0` logmsg="$(date) | $(whoami) | $0 | $1 |" #Acessa o diretorio configurado na variavel PATHBIN cd ${pathbin} #Function Start start() { if [ -z `pidof -x ${prog}` ] ;then echo then echo "Starting ${prog}..." exec " exec ./${prog} >/dev/null& RETVAL & RETVAL=$?if [ if [ ${RETVAL} -eq 0 ];then touch then touch ${lockfile}touch touch ${pidfile}pidof pidof -x ${prog} > ${pidfile} sleep 1 echo "PID : `catsleep 1 echo "PID : `cat ${pidfile}`"echo echo "${prog} running : ${green}[ OK ]${reset}"echo echo "${logmsg} ${prog} Started" >> ${logfile} else echoelse echo "Failed to start ${prog}: : ${red}[ Failure ]${reset}"echo echo "${logmsg} Failed to start ${prog}" >> ${logfile} fi echo else echofi echo else echo "${prog} is ${green}Started${reset} pid `pidof -x ${prog}`"echo echo "${logmsg} ${prog} already started" >> ${logfile} fi } #Function Stop stop() { if [ ! -z `pidof -x ${prog}` ] ;then killproc then killproc ${prog} >/dev/null& #pkill & #pkill -f ${prog} echo rmecho rm -f$lockfile rm $lockfile rm -f$pidfile echo $pidfile echo -n "Stopping ${prog}."while [ ! while [ ! -z `pidof -x ${prog}` ] do echo -n "." sleep 1 done echo echo}` ] do echo -n "." sleep 1 done echo echo "${prog} isStopped Stopped ${red}[ Stopped ]${reset}"echo echo "${logmsg} ${prog} stopped" >> ${logfile} else echoelse echo "${prog} is not running ${red}[ Stopped ]${reset}"echo echo "${logmsg} ${prog} already stopped" >> ${logfile} fi } #Function Status status() { pid=$(pidof -x ${prog}) progport=$(lsof -Pp ${pid} | grep '(LISTEN)' | awk '{ print $9}' | cut -d: -f2 | xargs) list=$(ps -eo pid,start_time,cputime,pcpu,pmem,stat,size,nlwp,comm | grep ${pid}) start_time=$(echo $list | awk '{ print $2 }') cputime=$(echo $list | awk '{ print $3 }') pcpu=$(echo $list | awk '{ print $4 }') pmem=$(echo $list | awk '{ print $5 }') stat=$(echo $list | awk '{ print $6 }') size=$(echo $list | awk '{ print $7 }') nlwp=$(echo $list | awk '{ print $8 }') comm=$(echo $list | awk '{ print $9 }') size=$(echo "$(bc <<< "scale=2;$size/1024") MB") echo "PROCESS: : ${comm}" echo"PORT : "PORT : ${progport}" echo"PID : "PID : ${pid}"echo "STARTED : echo "STARTED : ${start_time}" echo"TIME : "TIME : ${cputime}" echo"%CPU : "%CPU : ${pcpu}" echo"%MEM : "%MEM : ${pmem}"echo "MEMORY : " echo "MEMORY : ${size}" echo"STATUS : "STATUS : ${green}[ running ]${reset}" echo "THREADS: : ${nlwp}" } #MAIN case "$1" in start) start start ;; stop) stop stop ;; status)if [ ! if [ ! -z `pidof -x ${prog}` ] ;then echo then echo "Statusprocess : process : ${green}[ OK ]${reset}" status else echo "Status process :status else echo "Status process : ${red}[ Failure ]${reset}" echo "Program $prog is not running!" fi ;; restart) stop sleep 2 start sleep 2 status ;; log) cat ${logfile} echo "More details at ${logfile}" ;; *) echo $"Usage: $0" echo "Program $prog is not running!" fi ;; restart) stop sleep 2 start sleep 2 status ;; log) cat ${logfile} echo "More details at ${logfile}" ;; *) echo $"Usage: $0 {start|stop|restart|status|log}" exit 1 esac exitexit 1 esac exit 0 |
Nota |
---|
Os scripts precisam ter permissão para executar os serviços. Para iniciá-los, demos as seguintes permissões: [root@tpsrv01 init.d]# chmod 775 +x totvs* |
Informações | ||
---|---|---|
| ||
Os scripts de iniciar os serviços foram criados pela engenharia Engenharia e homologados no cenário do teste sistêmico, onde os testes foram realizados no Linux. |
Utilizando os scripts
Os serviços tem a seguinte ordem de inicialização:
01 - LockServer (totvsapplocksrv)02 - License Server (totvsapplicensesrv)
03 02 - Dbaccess (totvsdbaccess)
04 03 - Slaves Secundários (totvsappslv01 totvsappsec01 e totvsappslv02totvsappsec02)
05 04 - Balance Broker (totvsappbalancetotvsappbroker)
Informações | ||
---|---|---|
| ||
Você deverá estar no diretório Para conseguir executar os scripts, acesse o diretório /etc/init.d para conseguir executar os scripts. |
Abaixo, está a relação dos comandos para iniciar, parar e consultar a situação dos serviços:
Comandos para iniciar serviços (start) | ./totvsapplocksrv start ./totvsapplicensesrv start ./totvsdbaccess start ./totvsappbalance totvsappbroker start ./totvsappslv01 totvsappsec01 start ./totvsappslv02 totvsappsec02 start |
Comandos para parar serviços (stop) | ./totvsapplocksrv stop ./totvsapplicensesrv stop ./totvsdbaccess stop ./totvsappbalance totvsappbroker stop ./totvsappslv01 totvsappsec01 stop ./totvsappslv02 totvsappsec02 stop |
Comandos para verificar o status dos serviços (status) | ./totvsappslv02 totvsappsec02 status ./totvsappslv01 totvsappsec01 status ./totvsappbalance totvsappbroker status ./totvsdbaccess status ./totvsapplicensesrv status ./totvsapplocksrv status |
...