File: filter

package info (click to toggle)
service-wrapper-java 3.5.3%2Brepack-0%2Bnmu1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,308 kB
  • sloc: sh: 29,865; ansic: 17,338; java: 11,392; xml: 2,417; makefile: 95; cpp: 32
file content (1341 lines) | stat: -rwxr-xr-x 44,524 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
#! /bin/sh

#
# Copyright (c) 1999, 2010 Tanuki Software, Ltd.
# http://www.tanukisoftware.com
# All rights reserved.
#
# This software is the proprietary information of Tanuki Software.
# You shall use it only in accordance with the terms of the
# license agreement you entered into with Tanuki Software.
# http://wrapper.tanukisoftware.com/doc/english/licenseOverview.html
#
# Java Service Wrapper sh script.  Suitable for starting and stopping
#  wrapped Java applications on UNIX platforms.
#

#-----------------------------------------------------------------------------
# These settings can be modified to fit the needs of your application
# Optimized for use with version 3.5.3 of the Wrapper.

# Application
APP_NAME="filter"
APP_LONG_NAME="Filter Case"

# Wrapper
WRAPPER_CMD="../bin/wrapper"
WRAPPER_CONF="../test/filter.conf"

# Priority at which to run the wrapper.  See "man nice" for valid priorities.
#  nice is only used if a priority is specified.
PRIORITY=

# Location of the pid file.
PIDDIR="."

# If uncommented, causes the Wrapper to be shutdown using an anchor file.
#  When launched with the 'start' command, it will also ignore all INT and
#  TERM signals.
#IGNORE_SIGNALS=true

# Wrapper will start the JVM asynchronously. Your application may have some
#  initialization tasks and it may be desirable to wait a few seconds
#  before returning.  For example, to delay the invocation of following
#  startup scripts.  Setting WAIT_AFTER_STARTUP to a positive number will
#  cause the start command to delay for the indicated period of time 
#  (in seconds).
# 
WAIT_AFTER_STARTUP=0

# If set, wait for the wrapper to report that the daemon has started
WAIT_FOR_STARTED_STATUS=true
WAIT_FOR_STARTED_TIMEOUT=120

# If set, the status, start_msg and stop_msg commands will print out detailed
#   state information on the Wrapper and Java processes.
#DETAIL_STATUS=true

# If specified, the Wrapper will be run as the specified user.
# IMPORTANT - Make sure that the user has the required privileges to write
#  the PID file and wrapper.log files.  Failure to be able to write the log
#  file will cause the Wrapper to exit without any way to write out an error
#  message.
# NOTE - This will set the user which is used to run the Wrapper as well as
#  the JVM and is not useful in situations where a privileged resource or
#  port needs to be allocated prior to the user being changed.
#RUN_AS_USER=

# The following two lines are used by the chkconfig command. Change as is
#  appropriate for your application.  They should remain commented.
# chkconfig: 2345 20 80
# description: Filter Case

# When installing on On Mac OSX platforms, the following domain will be used to
#  prefix the plist file name.
PLIST_DOMAIN=org.tanukisoftware.wrapper
 
# Initialization block for the install_initd and remove_initd scripts used by
#  SUSE linux distributions.
### BEGIN INIT INFO
# Provides: filter
# Required-Start: $local_fs $network $syslog
# Should-Start: 
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Filter Case
# Description: @app.description@
### END INIT INFO

# Do not modify anything beyond this point
#-----------------------------------------------------------------------------

# Required for HP-UX Startup
if [ `uname -s` = "HP-UX" -o `uname -s` = "HP-UX64" ] ; then
        PATH=$PATH:/usr/bin
fi

# Get the fully qualified path to the script
case $0 in
    /*)
        SCRIPT="$0"
        ;;
    *)
        PWD=`pwd`
        SCRIPT="$PWD/$0"
        ;;
esac

# Resolve the true real path without any sym links.
CHANGED=true
while [ "X$CHANGED" != "X" ]
do
    # Change spaces to ":" so the tokens can be parsed.
    SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
    # Get the real path to this script, resolving any symbolic links
    TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
    REALPATH=
    for C in $TOKENS; do
        # Change any ":" in the token back to a space.
        C=`echo $C | sed -e 's;:; ;g'`
        REALPATH="$REALPATH/$C"
        # If REALPATH is a sym link, resolve it.  Loop for nested links.
        while [ -h "$REALPATH" ] ; do
            LS="`ls -ld "$REALPATH"`"
            LINK="`expr "$LS" : '.*-> \(.*\)$'`"
            if expr "$LINK" : '/.*' > /dev/null; then
                # LINK is absolute.
                REALPATH="$LINK"
            else
                # LINK is relative.
                REALPATH="`dirname "$REALPATH"`""/$LINK"
            fi
        done
    done

    if [ "$REALPATH" = "$SCRIPT" ]
    then
        CHANGED=""
    else
        SCRIPT="$REALPATH"
    fi
done

# Change the current directory to the location of the script
cd "`dirname "$REALPATH"`"
REALDIR=`pwd`

# If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
#  the working directory is later changed.
FIRST_CHAR=`echo $PIDDIR | cut -c1,1`
if [ "$FIRST_CHAR" != "/" ]
then
    PIDDIR=$REALDIR/$PIDDIR
fi
# Same test for WRAPPER_CMD
FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1`
if [ "$FIRST_CHAR" != "/" ]
then
    WRAPPER_CMD=$REALDIR/$WRAPPER_CMD
fi
# Same test for WRAPPER_CONF
FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1`
if [ "$FIRST_CHAR" != "/" ]
then
    WRAPPER_CONF=$REALDIR/$WRAPPER_CONF
fi

# Process ID
ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
STATUSFILE="$PIDDIR/$APP_NAME.status"
JAVASTATUSFILE="$PIDDIR/$APP_NAME.java.status"
PIDFILE="$PIDDIR/$APP_NAME.pid"
LOCKDIR="/var/lock/subsys"
LOCKFILE="$LOCKDIR/$APP_NAME"
pid=""

# Resolve the location of the 'ps' command
PSEXE="/usr/ucb/ps"
    if [ ! -x "$PSEXE" ]
    then
        PSEXE="/usr/bin/ps"
        if [ ! -x "$PSEXE" ]
        then
            PSEXE="/bin/ps"
            if [ ! -x "$PSEXE" ]
            then
                eval echo  'Unable to locate "ps".'
                eval echo  'Please report this message along with the location of the command on your system.'
                exit 1
            fi
        fi
    fi

# Resolve the os
DIST_OS=`uname -s | tr [A-Z] [a-z] | tr -d ' '`
case "$DIST_OS" in
    'sunos')
        DIST_OS="solaris"
        ;;
    'hp-ux' | 'hp-ux64')
        # HP-UX needs the XPG4 version of ps (for -o args)
        DIST_OS="hpux"
        UNIX95=""
        export UNIX95   
        ;;
    'darwin')
        DIST_OS="macosx"
        ;;
    'unix_sv')
        DIST_OS="unixware"
        ;;
    'os/390')
        DIST_OS="zos"
        ;;
esac

# Resolve the architecture
if [ "$DIST_OS" = "macosx" ]
then
    OS_VER=`sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*'`
    DIST_ARCH="universal"
    if [[ "$OS_VER" < "10.5.0" ]]
    then
        DIST_BITS="32"
    else
        DIST_BITS="64"
    fi
    APP_PLIST_BASE=${PLIST_DOMAIN}.${APP_NAME}
    APP_PLIST=${APP_PLIST_BASE}.plist
else
    DIST_ARCH=
    DIST_ARCH=`uname -p 2>/dev/null | tr [A-Z] [a-z] | tr -d ' '`
    if [ "X$DIST_ARCH" = "X" ]
    then
        DIST_ARCH="unknown"
    fi
    if [ "$DIST_ARCH" = "unknown" ]
    then
        DIST_ARCH=`uname -m 2>/dev/null | tr [A-Z] [a-z] | tr -d ' '`
    fi
    case "$DIST_ARCH" in
        'athlon' | 'i386' | 'i486' | 'i586' | 'i686')
            DIST_ARCH="x86"
            if [ "${DIST_OS}" = "solaris" ] ; then
                DIST_BITS=`isainfo -b`
            else
                DIST_BITS="32"
            fi
            ;;
        'amd64' | 'x86_64')
            DIST_ARCH="x86"
            DIST_BITS="64"
            ;;
        'ia32')
            DIST_ARCH="ia"
            DIST_BITS="32"
            ;;
        'ia64' | 'ia64n' | 'ia64w')
            DIST_ARCH="ia"
            DIST_BITS="64"
            ;;
        'ip27')
            DIST_ARCH="mips"
            DIST_BITS="32"
            ;;
        'power' | 'powerpc' | 'power_pc' | 'ppc64')
            if [ "${DIST_ARCH}" = "ppc64" ] ; then
                DIST_BITS="64"
            else
                DIST_BITS="32"
            fi
            DIST_ARCH="ppc"
            if [ "${DIST_OS}" = "aix" ] ; then
                if [ `getconf KERNEL_BITMODE` -eq 64 ]; then
                    DIST_BITS="64"
                else
                    DIST_BITS="32"
                fi
            fi
            ;;
        'pa_risc' | 'pa-risc')
            DIST_ARCH="parisc"
            if [ `getconf KERNEL_BITS` -eq 64 ]; then
                DIST_BITS="64"
            else
                DIST_BITS="32"
            fi    
            ;;
        'sun4u' | 'sparcv9' | 'sparc')
            DIST_ARCH="sparc"
            DIST_BITS=`isainfo -b`
            ;;
        '9000/800' | '9000/785')
            DIST_ARCH="parisc"
            if [ `getconf KERNEL_BITS` -eq 64 ]; then
                DIST_BITS="64"
            else
                DIST_BITS="32"
            fi
            ;;
        '2097')
            DIST_ARCH="390"
            DIST_BITS="32"
            ;;
    esac
fi

# OSX always places Java in the same location so we can reliably set JAVA_HOME
if [ "$DIST_OS" = "macosx" ]
then
    if [ -z "$JAVA_HOME" ]; then
        JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
    fi
fi

# Test Echo
ECHOTEST=`echo -n "x"`
if [ "$ECHOTEST" = "x" ]
then
    ECHOOPT="-n "
else
    ECHOOPT=""
fi


gettext() {
    echo "$1"
}

outputFile() {
    if [ -f "$1" ]
    then
        eval echo  '  $1  Found but not executable.';
    else
        echo "  $1"
    fi
}

# Decide on the wrapper binary to use.
# If the bits of the OS could be detected, we will try to look for the
#  binary with the correct bits value.  If it doesn't exist, fall back
#  and look for the 32-bit binary.  If that doesn't exist either then
#  look for the default.
WRAPPER_TEST_CMD=""
if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS" ]
then
    WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
    if [ ! -x "$WRAPPER_TEST_CMD" ]
    then
        chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
    fi
    if [ -x "$WRAPPER_TEST_CMD" ]
    then 
        WRAPPER_CMD="$WRAPPER_TEST_CMD"
    else
        outputFile "$WRAPPER_TEST_CMD"
        WRAPPER_TEST_CMD=""
    fi
fi
if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" -a -z "$WRAPPER_TEST_CMD" ]
then
    WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
    if [ ! -x "$WRAPPER_TEST_CMD" ]
    then
        chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
    fi
    if [ -x "$WRAPPER_TEST_CMD" ]
    then 
        WRAPPER_CMD="$WRAPPER_TEST_CMD"
    else
        outputFile "$WRAPPER_TEST_CMD"
        WRAPPER_TEST_CMD=""
    fi
fi
if [ -f "$WRAPPER_CMD" -a -z "$WRAPPER_TEST_CMD" ]
then
    WRAPPER_TEST_CMD="$WRAPPER_CMD"
    if [ ! -x "$WRAPPER_TEST_CMD" ]
    then
        chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
    fi
    if [ -x "$WRAPPER_TEST_CMD" ]
    then 
        WRAPPER_CMD="$WRAPPER_TEST_CMD"
    else
        outputFile "$WRAPPER_TEST_CMD"
        WRAPPER_TEST_CMD=""
    fi
fi
if [ -z "$WRAPPER_TEST_CMD" ]
then
    eval echo  'Unable to locate any of the following binaries:'
    outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
    if [ ! "$DIST_BITS" = "32" ]
    then
        outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
    fi
    outputFile "$WRAPPER_CMD"

    exit 1
fi


# Build the nice clause
if [ "X$PRIORITY" = "X" ]
then
    CMDNICE=""
else
    CMDNICE="nice -$PRIORITY"
fi

# Build the anchor file clause.
if [ "X$IGNORE_SIGNALS" = "X" ]
then
   ANCHORPROP=
   IGNOREPROP=
else
   ANCHORPROP=wrapper.anchorfile=\"$ANCHORFILE\"
   IGNOREPROP=wrapper.ignore_signals=TRUE
fi

# Build the status file clause.
if [ "X$DETAIL_STATUS$WAIT_FOR_STARTED_STATUS" = "X" ]
then
   STATUSPROP=
else
   STATUSPROP="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
fi

if [ ! -n "$WAIT_FOR_STARTED_STATUS" ]
then
    WAIT_FOR_STARTED_STATUS=true
fi

if [ $WAIT_FOR_STARTED_STATUS = true ] ; then
    DETAIL_STATUS=true
fi


# Build the lock file clause.  Only create a lock file if the lock directory exists on this platform.
LOCKPROP=
if [ -d $LOCKDIR ]
then
    if [ -w $LOCKDIR ]
    then
        LOCKPROP=wrapper.lockfile=\"$LOCKFILE\"
    fi
fi

checkUser() {
    # $1 touchLock flag
    # $2 command

    # Check the configured user.  If necessary rerun this script as the desired user.
    if [ "X$RUN_AS_USER" != "X" ]
    then
        # Resolve the location of the 'id' command
        IDEXE="/usr/xpg4/bin/id"
        if [ ! -x "$IDEXE" ]
        then
            IDEXE="/usr/bin/id"
            if [ ! -x "$IDEXE" ]
            then
                eval echo  'Unable to locate "id".'
                eval echo  'Please report this message along with the location of the command on your system.'
                exit 1
            fi
        fi

        if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
        then
            # Already running as the configured user.  Avoid password prompts by not calling su.
            RUN_AS_USER=""
        fi
    fi
    if [ "X$RUN_AS_USER" != "X" ]
    then
        # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
        # able to create the lock file.  The Wrapper will be able to update this file once it
        # is created but will not be able to delete it on shutdown.  If $2 is defined then
        # the lock file should be created for the current command
        if [ "X$LOCKPROP" != "X" ]
        then
            if [ "X$1" != "X" ]
            then
                # Resolve the primary group 
                RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
                if [ "X$RUN_AS_GROUP" = "X" ]
                then
                    RUN_AS_GROUP=$RUN_AS_USER
                fi
                touch $LOCKFILE
                chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
            fi
        fi

        # Still want to change users, recurse.  This means that the user will only be
        #  prompted for a password once. Variables shifted by 1
        # 
        # Use "runuser" if this exists.  runuser should be used on RedHat in preference to su.
        #
        if test -f "/sbin/runuser"
        then
            /sbin/runuser - $RUN_AS_USER -c "\"$REALPATH\" $2"
        else
            su - $RUN_AS_USER -c "\"$REALPATH\" $2"
        fi

        # Now that we are the original user again, we may need to clean up the lock file.
        if [ "X$LOCKPROP" != "X" ]
        then
            getpid
            if [ "X$pid" = "X" ]
            then
                # Wrapper is not running so make sure the lock file is deleted.
                if [ -f "$LOCKFILE" ]
                then
                    rm "$LOCKFILE"
                fi
            fi
        fi

        exit 0
    fi
}

getpid() {
    pid=""
    if [ -f "$PIDFILE" ]
    then
        if [ -r "$PIDFILE" ]
        then
            pid=`cat "$PIDFILE"`
            if [ "X$pid" != "X" ]
            then
                # It is possible that 'a' process with the pid exists but that it is not the
                #  correct process.  This can happen in a number of cases, but the most
                #  common is during system startup after an unclean shutdown.
                # The ps statement below looks for the specific wrapper command running as
                #  the pid.  If it is not found then the pid file is considered to be stale.
                case "$DIST_OS" in
                    'freebsd')
                        pidtest=`$PSEXE -p $pid -o args | tail -1`
                        if [ "X$pidtest" = "XCOMMAND" ]
                        then 
                            pidtest=""
                        fi
                        ;;
                    'macosx')
                        pidtest=`$PSEXE -ww -p $pid -o command | grep "$WRAPPER_CMD" | tail -1`
                        ;;
                    'solaris')
                        if [ -f "/usr/bin/pargs" ]
                        then
                            pidtest=`pargs $pid | grep "$WRAPPER_CMD" | tail -1`
                        else
                            case "$PSEXE" in
                            '/usr/ucb/ps')
                                pidtest=`$PSEXE -auxww  $pid | grep "$WRAPPER_CMD" | tail -1`
                                ;;
                            '/usr/bin/ps')
                                TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
                                COUNT=`echo $TRUNCATED_CMD | wc -m`
                                COUNT=`echo ${COUNT}`
                                COUNT=`expr $COUNT - 1`
                                TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
                                pidtest=`$PSEXE -o comm -p $pid | grep "$TRUNCATED_CMD" | tail -1`
                                ;;
                            '/bin/ps')
                                TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
                                COUNT=`echo $TRUNCATED_CMD | wc -m`
                                COUNT=`echo ${COUNT}`
                                COUNT=`expr $COUNT - 1`
                                TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
                                pidtest=`$PSEXE -o comm -p $pid | grep "$TRUNCATED_CMD" | tail -1`
                                ;;
                            *)
                                echo "Unsupported ps command $PSEXE"
                                exit 1
                                ;;
                            esac
                        fi
                        ;;
                    'hpux')
                        pidtest=`$PSEXE -p $pid -x -o args | grep "$WRAPPER_CMD" | tail -1`
                        ;;
                    *)
                        pidtest=`$PSEXE -p $pid -o args | grep "$WRAPPER_CMD" | tail -1`
                        ;;
                esac

                if [ "X$pidtest" = "X" ]
                then
                    # This is a stale pid file.
                    rm -f "$PIDFILE"
                    eval echo  'Removed stale pid file: $PIDFILE'
                    pid=""
                fi
            fi
        else
            eval echo  'Cannot read $PIDFILE.'
            exit 1
        fi
    fi
}

getstatus() {
    STATUS=
    if [ -f "$STATUSFILE" ]
    then
        if [ -r "$STATUSFILE" ]
        then
            STATUS=`cat "$STATUSFILE"`
        fi
    fi
    if [ "X$STATUS" = "X" ]
    then
        STATUS="Unknown"
    fi
    
    JAVASTATUS=
    if [ -f "$JAVASTATUSFILE" ]
    then
        if [ -r "$JAVASTATUSFILE" ]
        then
            JAVASTATUS=`cat "$JAVASTATUSFILE"`
        fi
    fi
    if [ "X$JAVASTATUS" = "X" ]
    then
        JAVASTATUS="Unknown"
    fi
}

testpid() {
    case "$DIST_OS" in
     'solaris')
        case "$PSEXE" in
        '/usr/ucb/ps')
            pid=`$PSEXE  $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
            ;;
        '/usr/bin/ps')
            pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
            ;;
        '/bin/ps')
            pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
            ;;
        *)
            echo "Unsupported ps command $PSEXE"
            exit 1
            ;;
        esac
        ;;
    *)
        pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 2>/dev/null
        ;;
    esac
    if [ "X$pid" = "X" ]
    then
        # Process is gone so remove the pid file.
        rm -f "$PIDFILE"
        pid=""
    fi
}

launchdtrap() {
    stopit
    exit 
}

waitforwrapperstop() {
    getpid
    while [ "X$pid" != "X" ] ; do
        sleep 1
        getpid
    done
}

launchdinternal() {
    getpid
    trap launchdtrap TERM 
    if [ "X$pid" = "X" ]
    then 
        # The string passed to eval must handles spaces in paths correctly.
        COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $LOCKPROP"
        eval $COMMAND_LINE
    else
        eval echo  '$APP_LONG_NAME is already running.'
        exit 1
    fi
    # launchd expects that this script stay up and running so we need to do our own monitoring of the Wrapper process.
    if [ $WAIT_FOR_STARTED_STATUS = true ]
    then
        waitforwrapperstop
    fi
}

console() {
    eval echo  'Running $APP_LONG_NAME...'
    getpid
    if [ "X$pid" = "X" ]
    then
        trap '' 3
        # The string passed to eval must handles spaces in paths correctly.
        COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" $ANCHORPROP $STATUSPROP $LOCKPROP"
        eval $COMMAND_LINE
    else
        eval echo  '$APP_LONG_NAME is already running.'
        exit 1
    fi
}

waitforjavastartup() {
    getstatus
    eval echo $ECHOOPT `gettext 'Waiting for $APP_LONG_NAME...'`
    
    # Wait until the timeout or we have something besides Unknown.
    counter=15
    while [ "$JAVASTATUS" = "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
        echo $ECHOOPT"."
        sleep 1
        getstatus
        counter=`expr $counter - 1`
    done
    
    if [ -n "$WAIT_FOR_STARTED_TIMEOUT" ] ; then 
        counter=$WAIT_FOR_STARTED_TIMEOUT
    else
        counter=120
    fi
    while [ "$JAVASTATUS" != "STARTED" -a "$JAVASTATUS" != "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
        echo $ECHOOPT"."
        sleep 1
        getstatus
        counter=`expr $counter - 1`
    done
    if [ "X$ECHOOPT" != "X" ] ; then
        echo ""
    fi
}
 
startwait() {
    if [ $WAIT_FOR_STARTED_STATUS = true ]
    then
        waitforjavastartup
    fi
    # Sleep for a few seconds to allow for intialization if required 
    #  then test to make sure we're still running.
    #
    i=0
    while [ $i -lt $WAIT_AFTER_STARTUP ]
    do
        sleep 1
        echo $ECHOOPT"."
        i=`expr $i + 1`
    done
    if [ $WAIT_AFTER_STARTUP -gt 0 -o $WAIT_FOR_STARTED_STATUS = true ]
    then
        getpid
        if [ "X$pid" = "X" ]
        then
            eval echo  ' WARNING: $APP_LONG_NAME may have failed to start.'
            exit 1
        else
            eval echo  ' running: PID:$pid'
        fi
    else 
        echo ""
    fi
}

macosxstart() {
    # The daemon has been installed.
    eval echo  'Starting $APP_LONG_NAME.  Detected Mac OSX and installed launchd daemon.'
    if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then       
        eval echo  'Must be root to perform this action.'
        exit 1
    fi
    
    getpid
    if [ "X$pid" != "X" ] ; then
        eval echo  '$APP_LONG_NAME is already running.'
        exit 1
    fi
    
    # If the daemon was just installed, it may not be loaded.
    LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
    if [ "X${LOADED_PLIST}" = "X" ] ; then
        launchctl load /Library/LaunchDaemons/${APP_PLIST}
    fi
    # If launchd is set to run the daemon already at Load, we don't need to call start
    getpid
    if [ "X$pid" == "X" ] ; then
        launchctl start ${APP_PLIST_BASE}
    fi
    
    startwait
}

start() {
    eval echo  'Starting $APP_LONG_NAME...'
    getpid
    if [ "X$pid" = "X" ]
    then
        # The string passed to eval must handles spaces in paths correctly.
        COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $LOCKPROP"
        eval $COMMAND_LINE
    else
        eval echo  '$APP_LONG_NAME is already running.'
        exit 1
    fi
    
    startwait
}
 
stopit() {
    # $1 exit if down flag
    
    eval echo  'Stopping $APP_LONG_NAME...'
    getpid
    if [ "X$pid" = "X" ]
    then
        eval echo  '$APP_LONG_NAME was not running.'
        if [ "X$1" = "X1" ]
        then
            exit 1
        fi
    else
        if [ "X$IGNORE_SIGNALS" = "X" ]
        then
            # Running so try to stop it.
            kill $pid
            if [ $? -ne 0 ]
            then
                # An explanation for the failure should have been given
                eval echo  'Unable to stop $APP_LONG_NAME.'
                exit 1
            fi
        else
            rm -f "$ANCHORFILE"
            if [ -f "$ANCHORFILE" ]
            then
                # An explanation for the failure should have been given
                eval echo  'Unable to stop $APP_LONG_NAME.'
                exit 1
            fi
        fi

        # We can not predict how long it will take for the wrapper to
        #  actually stop as it depends on settings in wrapper.conf.
        #  Loop until it does.
        savepid=$pid
        CNT=0
        TOTCNT=0
        while [ "X$pid" != "X" ]
        do
            # Show a waiting message every 5 seconds.
            if [ "$CNT" -lt "5" ]
            then
                CNT=`expr $CNT + 1`
            else
                eval echo  'Waiting for $APP_LONG_NAME to exit...'
                CNT=0
            fi
            TOTCNT=`expr $TOTCNT + 1`

            sleep 1

            testpid
        done

        pid=$savepid
        testpid
        if [ "X$pid" != "X" ]
        then
            eval echo  'Failed to stop $APP_LONG_NAME.'
            exit 1
        else
            eval echo  'Stopped $APP_LONG_NAME.'
        fi
    fi
}

status() {
    getpid
    if [ "X$pid" = "X" ]
    then
        eval echo  '$APP_LONG_NAME is not running.'
        exit 1
    else
        if [ "X$DETAIL_STATUS" = "X" ]
        then
            eval echo  '$APP_LONG_NAME is running: PID:$pid'
        else
            getstatus
            eval echo  '$APP_LONG_NAME is running: PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS'
        fi
        exit 0
    fi
}

installdaemon() {
    if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then       
        eval echo  'Must be root to perform this action.'
        exit 1
    else
        APP_NAME_LOWER=`echo "$APP_NAME" | tr [A-Z] [a-z]`
        if [ "$DIST_OS" = "solaris" ] ; then
            eval echo  'Detected Solaris:'
            if [ -f /etc/init.d/$APP_NAME ] ; then
                eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                exit 1
            else
                eval echo  ' Installing the $APP_LONG_NAME daemon..'
                ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
                ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
                ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
            fi
        elif [ "$DIST_OS" = "linux" ] ; then
            if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ]  ; then
                eval echo  'Detected RHEL or Fedora:'                  
                if [ -f "/etc/init.d/$APP_NAME" ] ; then
                    eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                    exit 1
                else
                    eval echo  ' Installing the $APP_LONG_NAME daemon..'
                    ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
                    /sbin/chkconfig --add "$APP_NAME"
                    /sbin/chkconfig "$APP_NAME" on
                fi
            elif [ -f /etc/SuSE-release ] ; then
                eval echo  'Detected SuSE or SLES:'
                if [ -f "/etc/init.d/$APP_NAME" ] ; then
                    eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                    exit 1
                else
                    eval echo  ' Installing the $APP_LONG_NAME daemon..'
                    ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
                    insserv "/etc/init.d/$APP_NAME"
                fi
            elif [ -f /etc/lsb-release ] ; then
                eval echo  'Detected Ubuntu:'
                if [ -f "/etc/init.d/$APP_NAME" ] ; then
                    eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                    exit 1
                else
                    eval echo  ' Installing the $APP_LONG_NAME daemon..'
                    ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
                    update-rc.d "$APP_NAME" defaults
                fi
            else
                eval echo  'Detected Linux:'
                if [ -f "/etc/init.d/$APP_NAME" ] ; then
                    eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                    exit 1
                else
                    eval echo  ' Installing the $APP_LONG_NAME daemon..'
                    ln -s "$REALPATH" /etc/init.d/$APP_NAME
                    ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
                    ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
                    ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
                    ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/K20$APP_NAME_LOWER"
                fi
            fi
        elif [ "$DIST_OS" = "hpux" ] ; then     
            eval echo  'Detected HP-UX:'          
            if [ -f "/sbin/init.d/$APP_NAME" ] ; then
                eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                exit 1
            else
                eval echo  ' Installing the $APP_LONG_NAME daemon..'
                ln -s "$REALPATH" "/sbin/init.d/$APP_NAME"
                ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/K20$APP_NAME_LOWER"
                ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/S20$APP_NAME_LOWER"
            fi
        elif [ "$DIST_OS" = "aix" ] ; then
            eval echo  'Detected AIX:'
            if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
                eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                exit 1
            else 
                eval echo  ' Installing the $APP_LONG_NAME daemon..'
                ln -s "$REALPATH" /etc/rc.d/init.d/$APP_NAME
                ln -s "/etc/rc.d/init.d/$APP_NAME" "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER"
                ln -s "/etc/rc.d/init.d/$APP_NAME" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER"
            fi
        elif [ "$DIST_OS" = "freebsd" ] ; then
            eval echo  'Detected FreeBSD:'                
            if [ -f "/etc/rc.d/$APP_NAME" ] ; then
                eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                exit 1
            else
                eval echo  ' Installing the $APP_LONG_NAME daemon..'
                sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
                if [ -f "${REALDIR}/${APP_NAME}.install" ] ; then
                    ln -s "${REALDIR}/${APP_NAME}.install" "/etc/rc.d/$APP_NAME"
                else
                    echo '#!/bin/sh' > "/etc/rc.d/$APP_NAME"
                    echo "#" >> "/etc/rc.d/$APP_NAME"
                    echo "# PROVIDE: $APP_NAME" >> "/etc/rc.d/$APP_NAME"
                    echo "# REQUIRE: NETWORKING" >> "/etc/rc.d/$APP_NAME"
                    echo "# KEYWORD: shutdown" >> "/etc/rc.d/$APP_NAME"
                    echo ". /etc/rc.subr" >> "/etc/rc.d/$APP_NAME"
                    echo "name=\"$APP_NAME\"" >> "/etc/rc.d/$APP_NAME"
                    echo "rcvar=\`set_rcvar\`" >> "/etc/rc.d/$APP_NAME"
                    echo "command=\"${REALDIR}/${APP_NAME}\"" >> "/etc/rc.d/$APP_NAME"
                    echo 'start_cmd="${name}_start"' >> "/etc/rc.d/$APP_NAME"
                    echo 'load_rc_config $name' >> "/etc/rc.d/$APP_NAME"
                    echo 'status_cmd="${name}_status"' >> "/etc/rc.d/$APP_NAME"
                    echo 'stop_cmd="${name}_stop"' >> "/etc/rc.d/$APP_NAME"
                    echo "${APP_NAME}_status() {" >> "/etc/rc.d/$APP_NAME"
                    echo '${command} status' >> "/etc/rc.d/$APP_NAME"
                    echo '}' >> "/etc/rc.d/$APP_NAME"
                    echo "${APP_NAME}_stop() {" >> "/etc/rc.d/$APP_NAME"
                    echo '${command} stop' >> "/etc/rc.d/$APP_NAME"
                    echo '}' >> "/etc/rc.d/$APP_NAME"
                    echo "${APP_NAME}_start() {" >> "/etc/rc.d/$APP_NAME"
                    echo '${command} start' >> "/etc/rc.d/$APP_NAME"
                    echo '}' >> "/etc/rc.d/$APP_NAME"
                    echo 'run_rc_command "$1"' >> "/etc/rc.d/$APP_NAME"
                fi
                echo "${APP_NAME}_enable=\"YES\"" >> /etc/rc.conf
                chmod 555 "/etc/rc.d/$APP_NAME"
            fi
        elif [ "$DIST_OS" = "macosx" ] ; then
            eval echo  'Detected Mac OSX:'
            if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
                eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                exit 1
            else
                eval echo  ' Installing the $APP_LONG_NAME daemon..'
                if [ -f "${REALDIR}/${APP_PLIST}" ] ; then
                    ln -s "${REALDIR}/${APP_PLIST}" "/Library/LaunchDaemons/${APP_PLIST}"
                else
                    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "<plist version=\"1.0\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "    <dict>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        <key>Label</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        <string>${APP_PLIST_BASE}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        <key>ProgramArguments</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        <array>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "            <string>${REALDIR}/${APP_NAME}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "            <string>launchdinternal</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        </array>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        <key>OnDemand</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        <true/>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        <key>RunAtLoad</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "        <true/>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    if [ "X$RUN_AS_USER" != "X" ] ; then
                        echo "        <key>UserName</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                        echo "        <string>${RUN_AS_USER}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    fi
                    echo "    </dict>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                    echo "</plist>" >> "/Library/LaunchDaemons/${APP_PLIST}"
                fi
                chmod 555 "/Library/LaunchDaemons/${APP_PLIST}"
            fi
        elif [ "$DIST_OS" = "zos" ] ; then
            eval echo  'Detected z/OS:'
            if [ -f /etc/rc.bak ] ; then
                eval echo  ' The $APP_LONG_NAME daemon is already installed.'
                exit 1
            else
                eval echo  ' Installing the $APP_LONG_NAME daemon..'
                cp /etc/rc /etc/rc.bak
                sed  "s:echo /etc/rc script executed, \`date\`::g" /etc/rc.bak > /etc/rc
                echo "_BPX_JOBNAME='${APP_NAME}' \"${REALDIR}/${APP_NAME}\" start" >>/etc/rc
                echo '/etc/rc script executed, `date`' >>/etc/rc
            fi
        else
            eval echo  'Install not currently supported for $DIST_OS'
            exit 1
        fi
    fi
}

removedaemon() {
    if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then       
        eval echo  'Must be root to perform this action.'
        exit 1
    else
        stopit "0"
        APP_NAME_LOWER=`echo "$APP_NAME" | tr [A-Z] [a-z]`
        if [ "$DIST_OS" = "solaris" ] ; then
            eval echo  'Detected Solaris:'
            if [ -f "/etc/init.d/$APP_NAME" ] ; then
                eval echo  ' Removing $APP_LONG_NAME daemon...'
                for i in "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME"
                do
                    rm -f $i
                done
            else
                eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                exit 1
            fi
        elif [ "$DIST_OS" = "linux" ] ; then
            if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then
                eval echo  'Detected RHEL or Fedora:'
                if [ -f "/etc/init.d/$APP_NAME" ] ; then
                    eval echo  ' Removing $APP_LONG_NAME daemon...'
                    /sbin/chkconfig "$APP_NAME" off
                    /sbin/chkconfig --del "$APP_NAME"
                    rm -f "/etc/init.d/$APP_NAME"
                else
                    eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                    exit 1
                fi
            elif [ -f /etc/SuSE-release ] ; then
                eval echo  'Detected SuSE or SLES:'
                if [ -f "/etc/init.d/$APP_NAME" ] ; then
                    eval echo  ' Removing $APP_LONG_NAME daemon...'
                    insserv -r "/etc/init.d/$APP_NAME"
                    rm -f "/etc/init.d/$APP_NAME"
                else
                    eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                    exit 1
                fi
            elif [ -f /etc/lsb-release ] ; then
                eval echo  'Detected Ubuntu:'
                if [ -f "/etc/init.d/$APP_NAME" ] ; then
                    eval echo  ' Removing $APP_LONG_NAME daemon...'
                    update-rc.d -f "$APP_NAME" remove
                    rm -f "/etc/init.d/$APP_NAME"
                else
                    eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                    exit 1
                fi
            else
                eval echo  'Detected Linux:'
                if [ -f "/etc/init.d/$APP_NAME" ] ; then
                    eval echo  ' Removing $APP_LONG_NAME daemon...'
                    for i in "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/rc5.d/K20$APP_NAME_LOWER" "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
                    do
                        rm -f $i
                    done
                else
                    eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                    exit 1
                fi
            fi
        elif [ "$DIST_OS" = "hpux" ] ; then
            eval echo  'Detected HP-UX:'
            if [ -f "/sbin/init.d/$APP_NAME" ] ; then
                eval echo  ' Removing $APP_LONG_NAME daemon...'
                for i in "/sbin/rc3.d/K20$APP_NAME_LOWER" "/sbin/rc3.d/S20$APP_NAME_LOWER" "/sbin/init.d/$APP_NAME"
                do
                    rm -f $i
                done
            else
                eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                exit 1
            fi
        elif [ "$DIST_OS" = "aix" ] ; then
            eval echo  'Detected AIX:'
            if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
                eval echo  ' Removing $APP_LONG_NAME daemon...'
                for i in "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER" "/etc/rc.d/init.d/$APP_NAME"
                do
                    rm -f $i
                done
            else
                eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                exit 1
            fi
        elif [ "$DIST_OS" = "freebsd" ] ; then
            eval echo  'Detected FreeBSD:'
            if [ -f "/etc/rc.d/$APP_NAME" ] ; then
                eval echo  ' Removing $APP_LONG_NAME daemon...'
                for i in "/etc/rc.d/$APP_NAME"
                do
                    rm -f $i
                done
                sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
            else
                eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                exit 1
            fi
        elif [ "$DIST_OS" = "macosx" ] ; then
            eval echo  'Detected Mac OSX:'
            if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
                eval echo  ' Removing $APP_LONG_NAME daemon...'
                # Make sure the plist is installed
                LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
                if [ "X${LOADED_PLIST}" != "X" ] ; then
                    launchctl unload "/Library/LaunchDaemons/${APP_PLIST}"
                fi
                rm -f "/Library/LaunchDaemons/${APP_PLIST}"
            else
                eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                exit 1
            fi
        elif [ "$DIST_OS" = "zos" ] ; then
            eval echo  'Detected z/OS:'
            if [ -f /etc/rc.bak ] ; then
                eval echo  ' Removing $APP_LONG_NAME daemon...'
                cp /etc/rc /etc/rc.bak
                sed  "s/_BPX_JOBNAME=\'APP_NAME\'.*//g" /etc/rc.bak > /etc/rc
                rm /etc/rc.bak
            else
                eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
                exit 1
            fi
        else
            eval echo  'Remove not currently supported for $DIST_OS'
            exit 1
        fi
    fi
}

dump() {
    eval echo  'Dumping $APP_LONG_NAME...'
    getpid
    if [ "X$pid" = "X" ]
    then
        eval echo  '$APP_LONG_NAME was not running.'
    else
        kill -3 $pid

        if [ $? -ne 0 ]
        then
            eval echo  'Failed to dump $APP_LONG_NAME.'
            exit 1
        else
            eval echo  'Dumped $APP_LONG_NAME.'
        fi
    fi
}

# Used by HP-UX init scripts.
startmsg() {
    getpid
    if [ "X$pid" = "X" ]
    then
        eval echo  'Starting $APP_LONG_NAME...  Wrapper:Stopped'
    else
        if [ "X$DETAIL_STATUS" = "X" ]
        then
            eval echo  'Starting $APP_LONG_NAME...  Wrapper:Running'
        else
            getstatus
            eval echo  'Starting $APP_LONG_NAME...  Wrapper:$STATUS, Java:$JAVASTATUS'
        fi
    fi
}

# Used by HP-UX init scripts.
stopmsg() {
    getpid
    if [ "X$pid" = "X" ]
    then
        eval echo  'Stopping $APP_LONG_NAME...  Wrapper:Stopped'
    else
        if [ "X$DETAIL_STATUS" = "X" ]
        then
            eval echo  'Stopping $APP_LONG_NAME...  Wrapper:Running'
        else
            getstatus
            eval echo  'Stopping $APP_LONG_NAME...  Wrapper:$STATUS, Java:$JAVASTATUS'
        fi
    fi
}

case "$1" in

    'console')
        checkUser touchlock $1
        console
        ;;

    'start')
        if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
            macosxstart
        else
            checkUser touchlock $1
            start
        fi
        ;;

    'stop')
        checkUser "" $1
        stopit "0"
        ;;

    'restart')
        checkUser touchlock $1
        stopit "0"
        start
        ;;

    'condrestart')
        checkUser touchlock $1
        stopit "1"
        start
        ;;

    'status')
        checkUser "" $1
        status
        ;;

    'install')
        installdaemon
        ;;

    'remove')
        removedaemon
        ;;

    'dump')
        checkUser "" $1
        dump
        ;;

    'start_msg')
        # Internal command called by launchd on HP-UX.
        checkUser "" $1
        startmsg
        ;;

    'stop_msg')
        # Internal command called by launchd on HP-UX.
        checkUser "" $1
        stopmsg
        ;;

    'launchdinternal')
        # Internal command called by launchd on Max OSX.
        # We do not want to call checkUser here as it is handled in the launchd plist file.  Doing it here would confuse launchd.
        launchdinternal
        ;;

    *)
        eval MSG=`gettext 'Usage: '`
        echo "${MSG} $0 { console | start | stop | restart | condrestart | status | install | remove | dump }"
        exit 1
        ;;
esac

exit 0