forked from andresaquino/monopse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monopse.sh
executable file
·1480 lines (1350 loc) · 47.9 KB
/
monopse.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# vim: set ts=2 sw=2 sts=2 si ai et:
# monopse.sh - An small shell for those applications that nobody wants to restart ;)
# =-=
#
# Developer
# Andres Aquino <aquino(at)hp.com>
#
#
# set minimal environment
APNAME="monopse"
APHOME=${HOME}
APPATH=${APHOME}/${APNAME}
APLOGD=${APPATH}/logs
APTEMP=${APLOGD}/temp
APLEVL="DEBUG"
APLOGS=
VIEWLOG=false
VIEWMLOG=false
# user environment
. ${APHOME}/.${APNAME}rc
# load user functions
. ${APPATH}/libutils.sh
set_environment
## MAIN ##
##
# corroborar que no se ejecute como usuario r00t
if [ "`id -u`" -eq "0" ]
then
if [ "${MAILACCOUNTS}" = "_NULL_" ]
then
printto "Hey, i can't run as root user "
else
${MAIL} -s "Somebody tried to run me as r00t user" "${MAILACCOUNTS}" < "$@" > /dev/null 2>&1 &
log_action "WARN" "Somebod tried to run me as r00t, sending warn to ${MAILACCOUNTS}"
fi
fi
# set complete application's environment
TOSLEEP=0
MAILTOADMIN=
MAILTODEVELOPER=
MAILTORADIO=
MAXSAMPLES=3
MAXSLEEP=2
APVISUALS=false
APPRCS=
START=false
STOP=false
DIS=false
ENABLE=false
RESTART=false
STATUS=false
ALLAPPLICATIONS=false
NOTFORCE=true
FASTSTOP=false
MAILACCOUNTS="_NULL_"
FILTERWL="_NULL_"
CHECKCONFIG=false
SUPERTEST=false
STATUS=false
DEBUG=false
ERROR=true
FAST=false
MAXLOGSIZE=500
THREADDUMP=false
VIEWREPORT=false
VIEWGROUP=false
VIEWEXTENDED=false
VIEWHISTORY=false
MAINTENANCE=false
SVERSION=false
APPTYPE="STAYRESIDENT"
UNIQUELOG=false
PREEXECUTION="_NULL_"
POSTEXECUTION="_NULL_"
PARAMSAPP=""
OPTIONS=
VERSION="`cat ${APPATH}/VERSION | sed -e 's/-rev/ Rev./g'`"
RELEASE=`openssl dgst -md5 ${APPATH}/${APNAME}.sh | rev | cut -c-4 | rev`
typeset -i pos
#
# log_backup
# respaldar logs para que no se generen problemas de espacio.
log_backup () {
# local apps
APTAR=`which tar`
APZIP=`which gzip`
#
# filename: monopse/monopse-cci-20080516-2230.tar.gz
DAYOF=`date '+%Y%m%d-%H%M'`
cd ${APTEMP}
if [ -e ${APLOGT}.date ]
then
DAYOF="`cat ${APLOGT}.date`"
rm -f ${APLOGT}.date
fi
mkdir -p ${DAYOF}
mv ${APLOGP}.log ${DAYOF}/ > /dev/null 2>&1
mv ${APLOGP}.err ${DAYOF}/ > /dev/null 2>&1
mv ${APLOGT}.allps ${DAYOF}/ > /dev/null 2>&1
mv ${APLOGT}.lock ${DAYOF}/ > /dev/null 2>&1
mv ${APLOGT}.pid ${DAYOF}/ > /dev/null 2>&1
mv ${APLOGT}.ppid ${DAYOF}/ > /dev/null 2>&1
mv ${APLOGT}.ps ${DAYOF}/ > /dev/null 2>&1
mv ${APLOGT}.pss ${DAYOF}/ > /dev/null 2>&1
rm ${APLOGT}.inprogress > /dev/null 2>&1
touch ${APLOGP}.log
LOGSIZE=`du -sk "${DAYOF}" | cut -f1`
RESULT=$((${LOGSIZE}/1024))
# Si esta habilitado el fast-stop(--forced), no se comprime la informacion
#rm -f ${APLOGT}.lock
${FASTSTOP} && log_action "WARN" "Ups,(doesn't compress) hurry up is to late for sysadmin !"
${FASTSTOP} && return 0
# reportar action
log_action "DEBUG" "The sizeof ${APLOGP}.log is ${LOGSIZE}M, proceeding to compress"
# si el tamaño del archivo .log sobrepasa los MAXLOGSIZE en megas
# entonces hacer un recorte para no saturar el filesystem
if [ ${RESULT} -gt ${MAXLOGSIZE} ]
then
log_action "WARN" "The sizeof ${APLOGP}.log is ${LOGSIZE}M, i need reduce it to ${MAXLOGSIZE}M"
SIZE=$((${MAXLOGSIZE}*1024*1024))
tail -c${SIZE} ${DAYOF}/${APPRCS}.log > ${DAYOF}/${APPRCS}
rm -f ${DAYOF}/${APPRCS}.log
mv ${DAYOF}/${APPRCS} ${DAYOF}/${APPRCS}.log
fi
#
# por que HP/UX tiene que ser taaan estupido ? ?
# backup de log | err | pid para análisis
# tar archivos | gzip -c > file-log
$APTAR -cvf ${APLOGP}_${DAYOF}.tar ${DAYOF} > /dev/null 2>&1
$APZIP -c ${APLOGP}_${DAYOF}.tar > ${APLOGP}_${DAYOF}.tar.gz
LOGSIZE=`du -sk ${APLOGP}_${DAYOF}.tar.gz | cut -f1`
log_action "INFO" "Creating ${APLOGP}_${DAYOF}.tar.gz file with ${LOGSIZE}M of size"
rm -f ${APLOGP}_${DAYOF}.tar
rm -fr ${DAYOF}
}
#
# check_configuration
# corroborar que los parametros/archivos sean correctos y existan en el filesystem
check_configuration () {
PROCESS=${1}
SHOWLOG=${2}
# existe el archivo de configuracion ?
FILESETUP="${APPATH}/setup/${PROCESS}-${APNAME}.conf"
log_action "DEBUG" "Testing ${FILESETUP}"
CHECKTEST=false
if [ -r ${FILESETUP} ]
then
CHECKTEST=true
. ${FILESETUP}
# Validar parametros
[ -d ${PATHAPP} ] || CHECKTEST=false
log_action "DEBUG" "Testing PATHAPP=${PATHAPP} ($CHECKTEST)"
[ -f ${PATHAPP}/${STARTAPP} ] || CHECKTEST=false
log_action "DEBUG" "Testing STARTAPP=${PATHAPP}/${STARTAPP} ($CHECKTEST)"
[ ! -z "${FILTERAPP}" ] || CHECKTEST=false
log_action "DEBUG" "Testing FILTER=/${FILTERAPP}//${FILTERLANG}/ ($CHECKTEST)"
[ ! -z "${UPSTRING}" ] || CHECKTEST=false
log_action "DEBUG" "Testing UPSTRING=${UPSTRING} ($CHECKTEST)"
[ ! -z "{DOMAIN_NAME}" ] && export DOMAIN_NAME
fi
if ${CHECKTEST}
then
if [ "${SHOWLOG}" = "YES" ]
then
printto "File: ${FILESETUP}\n--"
awk '/^[a-zA-Z]/{print}' ${FILESETUP}
fi
log_action "DEBUG" "All parameters seem to be correct "
return 0
else
log_action "DEBUG" "Uhmmm, maybe some parameter is incorrect "
return 1
fi
}
# *
# verificar que el servidor weblogic (en el caso de los appsrv's se encuentre arriba y operando,
# de otra manera, ejecutar una rutina _plugin_ para iniciar el servicio )
check_weblogicserver() {
# si se dio de alta la variable FILTERWL(weblogic.Server), entonces se tiene que buscar si existe el proceso de servidor WEBLOGIC
if [ ${FILTERWL} != "_NULL_" ]
then
log_action "INFO" "Check if exists an application server manager of WebLogic"
# existe algun proceso de weblogic.Server ?
if [ "${APSYSO}" = "HP-UX" ]
then
WLPROCESS=`ps -fex | grep "${FILTERWL}" | wc -l | cut -f1 -d\ `
else
WLPROCESS=`ps fea | grep "${FILTERWL}" | wc -l | cut -f1 -d\ `
fi
# si no es así, levantar el servidor y esperar 3 minuto
WLSLEEP=60*3
if [ ${WLPROCESS} -eq "0" ]
then
log_action "WARN" "Dont exists an application server manager of WebLogic, starting an instance of"
nohup sh ${WLSAPP} {$PARAMSAPP} 2> ${APLOGP}-WLS.err > ${APLOGP}-WLS.log &
sleep ${WLSLEEP}
fi
fi
}
# *
# realizar un kernel full thread dump sobre el proceso indicado.
# sobre procesos non-java va a valer queso, por que la señal 3 es para hacer un volcado de memoria.
# monopse --application=resin --threaddump=5
# por defecto, el ftd se almacena en el filesystem log de la aplicación; si se detecta que se esta
# incrementando el uso del filesystem, conserva los mas recientes
make_fullthreaddump() {
# para cuando son procesos JAVA StandAlone (WL, Tomcat, etc...)
log_action "DEBUG" "Change to ${PATHAPP}"
[ -r ${APLOGT}.pid ] && PID=`tail -n1 ${APLOGT}.pid`
# para cuando son procesos ONDemand (iPlanet, ...)
[ -r ${APLOGT}.plist -a ${FILTERAPP} ] && PID=`head -n1 ${APLOGT}.pid`
# meter una marca para saber desde donde vamos a sacar datos del log
ftdFILE="${APLOGP}_`date '+%Y%m%d-%H%M%S'`.ftd"
touch "${ftdFILE}"
log_action "DEBUG" "Taking ${APLOGP}.log to extract the FTP on ${ftdFILE}"
tail -f "${APLOGP}.log" > ${ftdFILE} 2>&1 &
# enviar el FTD al PID, N muestras cada T segs
times=0
timeStart=`date`
while [ $times -ne $MAXSAMPLES ]
do
#kill -3 $PID
printto "Sending a FTD to PID $PID at `date '+%H:%M:%S'`"
log_action "INFO" "Sending a FTD to PID $PID at `date '+%H:%M:%S'`"
wait_for "Getting information of $PID... " $MAXSLEEP
times=$(($times+1))
done
#
# generar encabezado y limpiar basura
log_action "INFO" "Check file: $ftdFILE"
printto "Ok, check file $ftdFILE"
tFILE=`wc -l ${ftdFILE} | awk '{print $1}'`
gFILE=`nl -ba ${ftdFILE} | grep "Full thread dump" | grep "Java HotSpot" | head -n1 | awk '{print $1}'`
total=$(($tFILE-$gFILE+1))
log_action "DEBUG" "Total: $total, where tFile=$tFILE and gFile=$gFILE"
tail -n${total} ${ftdFILE} > ${ftdFILE}.tmp
printto "-------------------------------------------------------------------------------" > ${ftdFILE}
printto "-------------------------------------------------------------------------------" >> ${ftdFILE}
printto "JAVA FTD" >> ${ftdFILE}
printto "-------------------------------------------------------------------------------" >> ${ftdFILE}
printto "Host: `hostname`" >> ${ftdFILE}
printto "ID's: `id`" >> ${ftdFILE}
printto "Date: ${timeStart}" >> ${ftdFILE}
printto "Appl: ${APPRCS}" >> ${ftdFILE}
printto "Smpl: ${MAXSAMPLES}" >> ${ftdFILE}
printto "-------------------------------------------------------------------------------" >> ${ftdFILE}
cat ${ftdFILE}.tmp >> ${ftdFILE}
# enviar por correo
if [ "${MAILACCOUNTS}" != "_NULL_" ]
then
${MAIL} -s "${APPRCS} FULL THREAD DUMP ${timeStart} (${ftdFILE})" "${MAILACCOUNTS}" < ${ftdFILE} > /dev/null 2>&1 &
log_action "INFO" "Sending a full thread dump(${ftdFILE}) by mail to ${MAILACCOUNTS}"
fi
rm -f ${ftdFILE}.tmp
return 0
}
# *
# report_status
# generar reporte via mail para los administradores
reports_status () {
local TYPEOPERATION STATUS STRSTATUS FILESTATUS
TYPEOPERATION=${1}
STATUS=${2}
if [ "${STATUS}" -eq "0" ]
then
STRSTATUS="SUCCESS"
FILESTATUS="${APLOGP}.log"
log_action "INFO" "The application ${TYPEOPERATION} ${STRSTATUS}"
else
STRSTATUS="FAILED"
FILESTATUS="${APLOGT}.err"
log_action "ERR" "The application ${TYPEOPERATION} ${STRSTATUS}"
fi
#
# solo enviar si la operacion fue correcta o no
printto "${APPRCS} ${TYPEOPERATION} ${STRSTATUS}, see also ${APLOGP}.log for information"
if [ "${MAILACCOUNTS}" != "_NULL_" ]
then
# y mandarlo a bg, por que si no el so se apendeja, y por este; este arremedo de programa :-P
${MAIL} -s "${APPRCS} ${TYPEOPERATION} ${STRSTATUS}" -r "${MAILACCOUNTS}" > /dev/null 2>&1 &
log_action "INFO" "Report ${APPRCS} ${TYPEOPERATION} ${STRSTATUS} to ${MAILACCOUNTS}"
fi
}
#
# show application's version
show_version () {
printto "${APNAME} ${VERSION} (${RELEASE})"
printto "${APPROF}\n"
if [ ${SVERSION} ]
then
printto "Developed by"
printto "Andres Aquino <andres.aquino(at)gmail.com>"
printto "Maintainer by"
printto "Jimmy R. Lili <cosvernautaux(at)gmail.com>"
fi
}
#
# parametros
while [ $# -gt 0 ]
do
case "${1}" in
-a=*|--application=*)
APPRCS=`echo "$1" | sed 's/^--[a-z-]*=//'`
APPRCS=`echo "${APPRCS}" | sed 's/^-a=//'`
set_proc "${APPRCS}"
APPINST[${pos}]=$(echo $APPRCS)
pos=$pos+1
;;
--start|start)
START=true
ERROR=false
if ${STOP} || ${STATUS} || ${CHECKCONFIG}
then
ERROR=true
fi
;;
--stop|stop)
STOP=true
ERROR=false
if ${START} || ${STATUS} || ${CHECKCONFIG}
then
ERROR=true
fi
;;
--dis|disable)
DIS=true
ERROR=false
if ${START} || ${STATUS} || ${CHECKCONFIG} || ${STOP} || ${RESTART} || ${ENABLE}
then
ERROR=true
fi
;;
--en|enable)
ENABLE=true
ERROR=false
if ${START} || ${STATUS} || ${CHECKCONFIG} || ${STOP} || ${RESTART} || ${DIS}
then
ERROR=true
fi
;;
--restart|restart)
RESTART=true
ERROR=false
if ${START} || ${STOP} || ${CHECKCONFIG}
then
ERROR=true
fi
;;
--all|all)
ALLAPPLICATIONS=true
ERROR=false
if ${DEBUG} || ${VIEWHISTORY} || ${VIEWREPORT} || ${STATUS} || ${VIEWGROUP}
then
ERROR=true
fi
;;
--status|-s|status)
STATUS=true
ERROR=false
if ${START} || ${STOP} || ${CHECKCONFIG}
then
ERROR=true
fi
;;
--log|-l)
VIEWHISTORY=true
ERROR=false
if ${START} || ${STOP} || ${CHECKCONFIG} || ${STATUS}
then
ERROR=true
fi
;;
--maintenance|-m)
MAINTENANCE=true
ERROR=false
if ${START} || ${STOP} || ${CHECKCONFIG} || ${STATUS}
then
ERROR=true
fi
;;
--report|-r)
VIEWREPORT=true
ERROR=false
if ${START} || ${STOP} || ${CHECKCONFIG} || ${STATUS}
then
ERROR=true
fi
;;
--greport|-gr)
VIEWGROUP=true
ERROR=false
# if ${START} || ${STOP} || ${CHECKCONFIG} || ${STATUS}
# then
# ERROR=true
# fi
;;
--extended|-e)
VIEWEXTENDED=true
ERROR=false
;;
--forced|-f)
NOTFORCE=false
FASTSTOP=true
ERROR=false
;;
--uniquelog|-u)
UNIQUELOG=true
ERROR=false
;;
-t=*|--threaddump=*)
THREADDUMP=true
ERROR=false
MAXVALUES=`echo "$1" | sed 's/^--[a-z-]*=//'`
MAXVALUES=`echo "${MAXVALUES}" | sed 's/^-t=//'`
if [ $MAXVALUES != "--threaddump" ]
then
MAXSAMPLES=`echo $MAXVALUES | sed 's/\,.*//'`
MAXSLEEP=`echo "$1" | sed 's/.*\,//'`
fi
if ${START} || ${CHECKCONFIG}
then
ERROR=true
fi
;;
--threaddump|-t)
THREADDUMP=true
ERROR=false
MAXSAMPLES=3
MAXSLEEP=10
if ${START} || ${CHECKCONFIG}
then
ERROR=true
fi
;;
-v|--verbose)
VIEWLOG=true
ERROR=false
;;
-vv)
VIEWLOG=true
VIEWMLOG=true
ERROR=false
;;
--quiet|-q)
VIEWLOG=false
VIEWMLOG=false
ERROR=false
;;
--fast|fast)
FAST=true
ERROR=false
if ${CHECKCONFIG} || ${THREADDUMP} || ${VIEWMLOG} || ${VIEWREPORT} || ${MAINTENANCE} || ${VIEWGROUP}
then
ERROR=true
fi
;;
--debug|-d)
DEBUG=true
ERROR=false
if ${START} || ${STOP} || ${STATUS}
then
ERROR=true
fi
;;
--check-config|-c)
CHECKCONFIG=true
ERROR=false
if ${START} || ${STOP} || ${STATUS}
then
ERROR=true
fi
;;
--test)
SUPERTEST=true
;;
--version)
SVERSION=true
show_version
exit 0
;;
--help|-h)
printto "Usage: ${APNAME} [OPTION]..."
printto "Example: "
printto " monopse start [APNAME]"
printto " monopse stop [APNAME]"
printto " monopse restart [APNAME 1] [APPNAME 2]... [APPNAME N]"
printto "start up or stop applications like WebLogic, Fuego, Resin, etc."
printto "Mandatory arguments in long format."
printto "\t-a, --application=APPNAME use this application, required "
printto "\t --all all registered applications "
printto "\t --start, start start appName "
printto "\t --stop, stop stop appName "
printto "\t --dis, disable Disable an AppName (the AppName can not start in this status)"
printto "\t --en, enable Enable an AppName in status DISABLED"
printto "\t --restart restart appName "
printto "\t --fast, fast send execution to background "
printto "\t-s, --status verify the status of appName "
printto "\t --quiet doesn't show execution output of application "
printto "\t-v, --verbose send output execution to terminal "
printto "\t-r, --report show an small report about domains "
printto "\t-m, --maintenance execute all shell plugins in maintenance directory "
printto "\t-t, --threaddump send a 3 signal via kernel by 3 times "
printto "\t --threaddump=COUNT,INTERVAL send a 3 signal via kernel, COUNT times between INTERVAL "
printto "\t-c, --check-config check config application (see ${APNAME}-${APNAME}.conf) "
printto "\t-vv send output execution and ${APNAME} execution to terminal "
printto "\t-d, --debug debug logs and processes in the system "
printto "\t-gr, --greport show the groups configured in order to restart, start, stop"
printto "\t-e, --extended show an extend report about AppName"
printto "\t --version show version "
printto "\t-h, --help show help "
printto "Each APPNAME refers to one application on the server. "
printto "In case of threaddump options, COUNT refers of times sending kill -3 signal between "
printto "INTERVAL time in seconds \n"
printto "Report bugs to <andres.aquino(at)gmail.com> \n"
exit 0
;;
*)
# FEAT
# ahora ya es posible usar el monopse $APP [options] sin usar el parametro -a o --application
# cute ^.^!
#echo ${#APPRCS}
#[ ${#APPRCS} -eq 0 ] && APPRCS="${1}"
APPRCS="${1}"
check_configuration "${APPRCS}"
LASTSTATUS=$?
if [ ${ENABLE} = false ]
then
if [ ${LASTSTATUS} -eq 0 ]
then
log_action "DEBUG" "${APPRCS} seems correct"
set_proc "${APPRCS}"
APPINST[${pos}]=$(echo $APPRCS)
pos=$pos+1
else
log_action "DEBUG" "${APPRCS} seems corrupted"
report_status "i" "${APPRCS} does not exist, please check your parameters."
exit 1
fi
fi
;;
esac
OPTIONS="${OPTIONS}\n${1}"
shift
done
# verificar opciones usadas
if ${SUPERTEST}
then
printto "Apps Environment"
printto "--"
printto "APPNAME = ${APNAME}"
printto "USER = ${APUSER}"
printto "HOME = ${APHOME}"
printto "VERSION = ${VERSION}"
printto "RELEASE = ${RELEASE}"
printto "PROCESS = ${APPRCS}"
printto "CURRENT = ${APDATE}"
printto "IPADDRESS = ${IPADDRESS}"
printto "HOSTNAME = ${APHOST}"
printto "--"
printto "APLEVL = ${APLEVL}"
printto "APPATH = ${APPATH}"
printto "APLOGD = ${APLOGD}"
printto "APLOGS = ${APLOGS}"
printto "APLOGP = ${APLOGP}"
printto "APTEMP = ${APTEMP}"
for app in ${APPATH}/setup/*-monopse.conf
do
echo "APSETP = ${app}"
done
exit 0
fi
#
if ${ERROR}
then
printto "Usage: ${APNAME} [OPTION]...[--help]"
exit 0
else
#
# CHECKCONFIG -- Verificar los parámetros del archivo de configuración
for AP in "${APPINST[@]}"
do
APPRCS=${AP}
if ${CHECKCONFIG}
then
check_configuration "${APPRCS}" "YES"
LASTSTATUS=$?
if [ ${LASTSTATUS} -eq 0 ]
then
report_status "*" "${APPRCS} seems correct"
else
report_status "?" "${APPRCS} seems corrupted"
fi
#exit ${LASTSTATUS}
fi
#exit ${LASTSTATUS}
done
#
# verificar que la configuración exista, antes de ejecutar el servicio
if ! ${ALLAPPLICATIONS}
then
if [ ${#APPRCS} -ne 0 ]
then
BVIEWLOG=${VIEWLOG}
VIEWLOG=false
check_configuration "${APPRCS}"
get_process_id "${FILTERAPP},${FILTERLANG}"
[ $? -ne 0 ] && CHECKCONFIG=true
[ ${TOSLEEP} -eq 0 ] && TOSLEEP=5
TOSLEEP="$((60*$TOSLEEP))"
VIEWLOG=${BVIEWLOG}
else
CANCEL=true
${STATUS} && CANCEL=false
${VIEWREPORT} && CANCEL=false
${VIEWGROUP} && CANCEL=false
${VIEWEXTENDED} && CANCEL=false
${VIEWHISTORY} && CANCEL=false
${MAINTENANCE} && CANCEL=false
${DEBUG} && CANCEL=false
if ${CANCEL}
then
printto "Usage: ${APNAME} [OPTION]...[--help]"
exit 1
fi
fi
fi
#
# RESTART -- guess... ?
if ${RESTART}
then
OPTIONAL=
${VIEWLOG} && OPTIONAL="${OPTIONAL} --verbose" || OPTIONAL="${OPTIONAL} --quiet"
${FAST} && OPTIONAL="${OPTIONAL} --fast"
if ${ALLAPPLICATIONS}
then
for APMAIN in ${APPATH}/setup/*-monopse.conf
do
MAPPFILE=`basename ${APMAIN%-*.conf}`
log_action "DEBUG" "Executing restart over ${MAPPFILE} "
wait_for "Stopping ${MAPPFILE} application" 1
${APPATH}/${APNAME} --application=${MAPPFILE} stop --forced --quiet
RESULT=$?
wait_for "Starting ${MAPPFILE} application" 1
[ ${RESULT} -eq 0 ] && ${APPATH}/${APNAME} --application=${MAPPFILE} start ${OPTIONAL}
done
else
for AP in "${APPINST[@]}"
do
APPRCS=${AP}
wait_for "Stopping ${APPRCS} application" 2
${APPATH}/${APNAME} --application=${APPRCS} stop --forced ${OPTIONAL}
RESULT=$?
wait_for "Starting ${APPRCS} application" 2
[ ${RESULT} -eq 0 ] && ${APPATH}/${APNAME} --application=${APPRCS} start ${OPTIONAL}
done
fi
fi
#
# START -- Iniciar la aplicación indicada en el archivo de configuración
if ${START}
then
APPRCS=${AP}
#
# que sucede si intentan dar de alta el proceso nuevamente
# verificamos que no exista un bloqueo (Dummies of Proof)
if ${ALLAPPLICATIONS}
then
OPTIONAL=
${VIEWLOG} && OPTIONAL="${OPTIONAL} --verbose" || OPTIONAL="${OPTIONAL} --quiet"
${FAST} && OPTIONAL="${OPTIONAL} --fast"
for APMAIN in ${APPATH}/setup/*.conf
do
MAPPFILE=`basename ${APMAIN%-*}`
${APPATH}/${APNAME} --application=${MAPPFILE} start ${OPTIONAL}
done
# como ya termino, no tiene caso seguir
exit 0
fi
TOSLEEP="$(($TOSLEEP*2))"
process_running
LASTSTATUS=$?
if [ -f ${APLOGT}.lock ]
then
# es posible que si existe el bloqueo, pero que el proceso
# no este trabajando, entonces verificamos usando los PID's
if [ ${LASTSTATUS} -ne 0 ]
then
log_action "DEBUG" "${APPRCS} have a lock process file without application, maybe a bug brain developer ?"
[ -f ${APLOGT}.lock ] && log_action "DEBUG" "Exists a lock process without an application in memory, remove it and start again automagically"
# mover archivos a directorio monopse/20080527-0605
wait_for "We need a backup of logfiles right?, wait" 1
log_backup
else
report_status "i" "${APPRCS} running right now!"
exit 0
fi
else
# es posible que el archivo de lock no exista pero la aplicación este ejecutandose
if [ ${LASTSTATUS} -eq 0 ]
then
touch "${APLOGT}.lock"
report_status "i" "${APPRCS} running right now!"
log_action "DEBUG" "The application lost the lock file, but is running actually"
exit 0
fi
fi
#
# ejecutar el shell para iniciar la aplicación y verificar que esta exista
cd ${PATHAPP}
if [ ${#STARTAPP} -ne 0 ]
then
log_action "DEBUG" "ready to execute ${STARTAPP} "
# si se indican la variables, entonces
# verificar que el weblogic server este ejecutandose
[ $WLSAPP ] && check_weblogicserver
#
# ejecutar el PREEXECUTION
if [ ${PREEXECUTION} != "_NULL_" ]
then
sh ${PREEXECUTION} > ${APLOGT}.pre 2>&1
log_action "DEBUG" "Executing ${PREEXECUTION}, logging to ${APLOGT}.pre"
fi
#
# iniciar la aplicación
wait_for "${APPRCS} in progress of execution" 1
wait_for "CLEAR"
if ${UNIQUELOG}
then
${VIEWMLOG} && wait_for "${APPRCS} executing, wait wait wait! (uniquelog)\n" 1
nohup sh ${STARTAPP} ${PARAMSAPP} > ${APLOGP}.log 2>&1 &
log_action "DEBUG" "Executing ${STARTAPP} with ${APLOGP}.log as logfile, with unique output ..."
else
${VIEWMLOG} && wait_for "${APPRCS} executing, wait wait wait! (log and err)\n" 1
nohup sh ${STARTAPP} ${PARAMSAPP} 2> ${APLOGP}.err > ${APLOGP}.log &
log_action "DEBUG" "Executing ${STARTAPP}, ${APLOGP}.log as logfile, ${APLOGP}.err as errfile ..."
fi
date '+%Y%m%d-%H%M' > ${APLOGT}.date
# summary en lock para un post-analisis
printto "Options used when monopse was called:\n ${OPTIONS}" > ${APLOGT}.lock
printto "\nDate:\n`date '+%Y%m%d %H:%M'`" >> ${APLOGT}.lock
fi
#
# a trabajar ... !
LASTSTATUS=1
ONSTOP=1
SPECT=200
LASTLINE=""
LINE="`tail -n1 ${APLOGP}.log`"
INWAIT=true
if ${FAST}
then
touch ${APLOGT}.inprogress
INWAIT=false
fi
wait_for "Getting PID's and lock process files ..." 1
while (${INWAIT})
do
filter_in_log "${UPSTRING}" ${SPECT}
LASTSTATUS=$?
wait_for "Waiting for ${APPRCS} execution, be patient ..." 2
[ ${LASTSTATUS} -eq 0 ] && report_status "*" "process ${APPRCS} start successfully"
[ ${LASTSTATUS} -eq 0 ] && log_action "DEBUG" "Great!, the ${APPRCS} start successfully"
[ ${LASTSTATUS} -eq 0 ] && INWAIT=false
[ ${LASTSTATUS} -eq 0 ] && break
if [ "${LINE}" != "${LASTLINE}" ]
then
${VIEWLOG} && printto " | ${LINE}"
LINE="$LASTLINE"
wait_for "CLEAR"
printto " | ${LINE}"
fi
ONSTOP="$(($ONSTOP+1))"
SPECT="$(($SPECT+100))"
[ $ONSTOP -ge $TOSLEEP ] && report_status "?" "Uhm, something goes wrong with ${APPRCS}"
[ $ONSTOP -ge $TOSLEEP ] && INWAIT=false;
LASTLINE="`tail -n1 ${APLOGP}.log`"
done
# buscar los PID's
${FAST} && report_status "*" "process ${APPRCS} started, please verify..."
get_process_id "${FILTERAPP},${FILTERLANG}"
printto "\nPID:\n" >> "${APLOGT}.lock" 2>&1
cat ${APLOGT}.pid >> "${APLOGT}.lock" 2>&1
# FIX
# SI LA APLPICACION CORRE UNA SOLA VEZ, ELIMINAR EL .lock
[ ${APPTYPE} = "RUNONCE" ] && rm -f "${APLOGT}.lock" && log_backup
####exit ${LASTSTATUS}
fi
#
# STOP -- Detener la aplicación sea por instrucción o deteniendo el proceso, indicado en el archivo de configuración
if ${STOP}
then
# para todas las aplicaciones
if ${ALLAPPLICATIONS}
then
OPTIONAL=
${VIEWLOG} && OPTIONAL="${OPTIONAL} --verbose" || OPTIONAL="${OPTIONAL} --quiet"
${FASTSTOP} && OPTIONAL="${OPTIONAL} --forced"
${FAST} && OPTIONAL="${OPTIONAL} --fast"
for APMAIN in ${APPATH}/setup/*-monopse.conf
do
MAPPFILE=`basename ${APMAIN%-*.conf}`
${APPATH}/${APNAME} --application=${MAPPFILE} stop ${OPTIONAL}
done
# como ya termino, no tiene caso seguir
if ${DIS}
then
log_action "DEBUG" "Option Disable, the monopse continue to run it"
else
exit 0
fi
fi
#
# verificar que la aplicación para hacer shutdown se encuentre en el dir
# checar en 10 ocasiones hasta que el servicio se encuentre abajo
LASTSTATUS=0
STRSTATUS="FORCED SHUTDOWN"
[ ${#STOPAPP} -eq 0 ] && NOTFORCE=false && FASTSTOP=true
[ ${#DOWNSTRING} -eq 0 ] && NOTFORCE=false && FASTSTOP=true
#
# que sucede si intentan dar de baja el proceso nuevamente
# verificamos que exista un bloqueo (DoP) y PID
log_action "DEBUG" "Stopping the application, please wait ..."
TOSLEEP="$(($TOSLEEP/2))"
process_running
FNEXIST=true
[ -s ${APLOGT}.pid ] && FNEXIST=false
if ${FNEXIST}
then
printto "uh, ${APPRCS} is not running currently, tip: ${APNAME} --report"
log_action "INFO" "The application is down"
exit 0
fi
# ejecutar el postexecution
if [ ${POSTEXECUTION} != "_NULL_" ]
then
log_action "DEBUG" "Executing ${POSTEXECUTION}, logging to ${APLOGT}.post"
sh ${POSTEXECUTION} > ${APLOGT}.post 2>&1
LASTSTATUS=$?
if [ ${LASTSTATUS} -ne 0 ]
then
report_status "?" "some problems with ${POSTEXECUTION}, ERROR_CODE: ${LASTSTATUS}"
exit 1
fi
report_status "*" "Good, all clear..."
fi
#
# si es necesario que el stop sea forzado
check_configuration "${APPRCS}"
if ${TOFORCE}
then
NOTFORCE=false
FASTSTOP=true
else
NOTFORCE=true
FASTSTOP=false
report_status "i" "Option forced deactivaded in file conf, let me run in normal mode"
fi
if ${NOTFORCE}
then
#
cd ${PATHAPP}
if [ -f ${STOPAPP} ]
then
STRSTATUS="NORMAL SHUTDOWN"
nohup sh ${PATHAPP}/${STOPAPP} >> ${APLOGP}.log 2>&1 &
log_action "INFO" "Shutdown application, please wait..."
fi
#
# a trabajar ... !
LASTSTATUS=1
ONSTOP=1
INWAIT=true
LASTLINE=""
LINE="`tail -n1 ${APLOGP}.log `"
INWAIT=true
while ($INWAIT)
do
filter_in_log "${DOWNSTRING}"
process_running
LASTSTATUS=$?
[ ${LASTSTATUS} -ne 0 ] && report_status "*" "process ${APPRCS} was killed in normal mode"
[ ${LASTSTATUS} -ne 0 ] && log_action "DEBUG" "Yeah! the ${APPRCS} died placid and successfully (pray for it)"
[ ${LASTSTATUS} -ne 0 ] && INWAIT=false
if [ "${LINE}" != "${LASTLINE}" ]
then
${VIEWLOG} && printto " | ${LINE}"
LINE="$LASTLINE"
fi
# tiempo a esperar para refrescar out en la pantalla
wait_for "Waiting for ${APPRCS} termination, be patient ..." 1
ONSTOP="$((${ONSTOP}+1))"
log_action "DEBUG" "uhmmm, OnStop = ${ONSTOP} vs ToSleep = ${TOSLEEP}"
if [ ${ONSTOP} -gt ${TOSLEEP} ]
then
INWAIT=false
log_action "WARN" "We have a problem Houston, ${APPRCS} stills remains in memory !"
fi
LASTLINE="`tail -n1 ${APLOGP}.log `"
done
log_backup
fi
#
# si no se cancelo el proceso por la buena, entonces pasamos a la mala
if [ ${LASTSTATUS} -eq 0 ]
then
# si el stop es con FORCED, y es una aplicacion JAVA enviar FTD
#if [ ${FILTERLANG} = "java" -a ${THREADDUMP} = true ]
if [ ${THREADDUMP} = true ]
then
# monopse -a=app stop -f -t=3,10
# se aplica un fullthreaddump de 3 muestras cada 10 segundos antes de detener el proceso de manera forzada.