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
  
1342
  
1343
  
1344
  
1345
  
1346
  
1347
  
1348
  
1349
  
1350
  
1351
  
1352
  
1353
  
1354
  
1355
  
1356
  
1357
  
1358
  
1359
  
1360
  
1361
  
1362
  
1363
  
1364
  
1365
  
1366
  
1367
  
1368
  
1369
  
1370
  
1371
  
1372
  
1373
  
1374
  
1375
  
1376
  
1377
  
1378
  
1379
  
1380
  
1381
  
1382
  
1383
  
1384
  
1385
  
1386
  
1387
  
1388
  
1389
  
1390
  
1391
  
1392
  
1393
  
1394
  
1395
  
1396
  
1397
  
1398
  
1399
  
1400
  
1401
  
1402
  
1403
  
1404
  
1405
  
1406
  
1407
  
1408
  
1409
  
1410
  
1411
  
1412
  
1413
  
1414
  
1415
  
1416
  
1417
  
#!/bin/sh 
# 
# $Id$ 
 
### If --silent-start is given as the first argument, 
### nothing will be printed to stdout by the script. 
 
if [ "x$1" = "x--silent-start" ] ; then 
 SILENT_START="y" 
 shift 
fi 
 
check_owner() { 
   gargs='' 
 
   if [ -w / ] ; then 
     # Shall we change uid/gid? 
     num=`grep --help 2>&1|grep gnu|wc -l` 
     num=`echo $num` 
     if [ x"$num" = x1 ] ; then 
       gargs='-a' 
     fi 
     ugid=`grep $gargs "='User'>" $DIR/Global_Variables 2>/dev/null\ 
           | sed -e 's/.*<str>//' -e 's,</str>.*,,'` 
     if [ ! "x$ugid" = x ] ; then 
        dp "Doing uid change to $ugid" 
        oifs="$IFS";IFS=':';set $ugid;IFS="$oifs" 
        if [ ! "x$2" = x ]; then 
          ok=`ls -lgd . 2>/dev/null | grep "$2" |wc -l` 
          ok=`echo $ok` 
          if [ "x$ok" = x1 ] ; then 
            dp "The server directory is already readable by group $2" 
          else 
            ok=`ls -ngd . 2>/dev/null | grep "$2" |wc -l` 
            ok=`echo $ok` 
            if [ "x$ok" = x1 ] ; then 
              dp "The server directory is already readable by group $2" 
            else 
              chgrp -R "$2" . 
              chmod -R g+r  . 
            fi 
          fi 
        fi 
        change_owner "$1" "$2" "$DIR" "$VARDIR" "$LOGDIR" 
     fi 
   fi 
} 
 
 
# Breaks on linux when using symlinks. 
dn="`dirname "$0"`" 
case "$dn" in  
 ""|".") 
  ;; 
 *) 
  # dp is not used here since we cannot source bin/functions before we 
  # are in the correct directory, for quite obvious reasons... 
  if [ ! "$dn" = "`pwd`" ] 
  then 
    echo "                    : Changing current directory to '$dn' (now `pwd`)" >&2 
    cd "$dn" 
    echo "                    : Got new directory as `pwd`" >&2 
  fi 
  ;; 
esac 
 
. bin/functions 
 
# Can be set with '--config-dir=DIR' 
DIR=../configurations 
if [ ! "x$ROXEN_CONFIGDIR" = "x" ] 
then 
    DIR="$ROXEN_CONFIGDIR" 
fi 
LOGDIR=../logs 
if [ ! "x$ROXEN_LOGDIR" = "x" ] 
then 
    LOGDIR="$ROXEN_LOGDIR" 
fi 
FILES="default" 
program=base_server/roxenloader.pike 
VARDIR=../var 
LOCALDIR=../local 
if [ ! "x$ROXEN_DATADIR" = "x" ] 
then 
    VARDIR="$ROXEN_DATADIR"/var 
    LOCALDIR="$ROXEN_DATADIR"/local 
 
    if [ -d "$ROXEN_DATADIR"/license ] 
    then 
        ROXEN_LICENSEDIR="$ROXEN_DATADIR"/license 
    else 
        ROXEN_LICENSEDIR="$DIR"/_license 
    fi 
    export ROXEN_DATADIR ROXEN_LICENSEDIR 
fi 
export LOCALDIR LOGDIR VARDIR 
SELF_TEST_DIR=etc/test 
 
# Make LOCALDIR an absolute path 
if test -d $LOCALDIR/.; then 
  LOCALDIR="`cd $LOCALDIR; pwd`" 
else :; fi 
 
if test -d $VARDIR/.; then :; else 
  dp "Creating directory $VARDIR" 
  ./mkdir -p $VARDIR/ || exit 1 
fi 
 
 
pcdir="$VARDIR/`roxen_version`/precompiled/`uname -m | tr ' ' '_' `.`uname -r`" 
old_roxen_defines="$pcdir/old_roxen_defines" 
./mkdir -p "$pcdir" || exit 1 
chmod 1777 "$pcdir" 
 
# Default verbosity level. 
verbose=1 
 
# Do not default to using a relative path. 
roxendir="`pwd`" 
 
# No debug by default. 
debug=-1 
 
# Don't attempt to stop a running server by default. 
stop="" 
 
# Attempt to start the server by default. 
start=1 
 
# Locate Pike binary. 
find_pike 
 
# Source environment 
setup_environment 
 
####### BEGIN ARGUMENT PARSING 
 
 
DEFINES="$DEFINES -DRAM_CACHE -DHTTP_COMPRESSION" 
 
gdb=no 
valgrind= 
truss= 
 
daemonize=yes 
 
remove_dumped_passed=no 
 
module_hot_reload= 
module_hot_reload_conf= 
 
remove_old_dot_o_files () { 
  dp "Removing old precompiled files ($1)" 
  # This really cannot be done from here anymore -- pass on an option 
  # to roxenloader instead. 
 
  # Make sure that the argument isn't duplicated for every restart... 
  if [ "x$remove_dumped_passed" = "xyes" ]; then :; else 
    pass="$pass --remove-dumped" 
    remove_dumped_passed=yes 
  fi 
} 
 
## Parse all arguments. 
## GNU-style, long options only, except for -D, simply passed on. 
ARGS="" 
 
# 
# Descriptions of some of the state variables set during argument processing. 
# 
#   Variable        Default 
#   Value   Description 
#   ----------------------------------------------------------------- 
#   debug   -1 
#   -1      No debug. 
#   0       Module debug (Pike warnings + -DMODULE_DEBUG). 
#   1       Full debug (Pike warnings + -DDEBUG -DMODULE_DEBUG). 
#   keep_mysql      "" 
#   ""      Shut down mysqld between restarts. 
#   1       Do not touch mysqld on restart. 
#   2       --mysql-only mode. 
#   once    "" 
#   ""      Loop the program until it exits with success (0). 
#   1       Verbose --once mode. 
#   2       Quiet --once mode. 
#   pass    "" 
#   -       Arguments to pass to the Pike program. 
#   passhelp        "" 
#   ""      Roxen is being started. 
#   1       A custom program has been specified with --program. 
#   pidfile "$DIR/_roxen_pid"/"" 
#           Defaults to "" if Roxen is not being started. 
#   ""      Do not generate a pid file or associated lock files. 
#   other   Create a pid file and associated lock files. 
#   program "base_server/roxen_loader.pike" 
#   -       The Pike program to start. 
#   start   1 
#   ""      Do not attempt to start the server. 
#   1       Attempt to start or restart the server. 
#   stop    "" 
#   ""      --stop or --restart not specified. 
#   1       --stop or --restart specified. 
#   verbose 1 
#   0       Quiet mode. 
#   1       Default verbosity. 
#   2       Verbose mode. 
# 
 
stop_mysql() { 
  # Kill roxen mysql if it's running... 
  if [ -f "$DIR/_mysql/mysql_pid" ] ; then 
    if kill -0 `cat "$DIR/_mysql/mysql_pid"` >/dev/null 2>&1; then 
      dp "Stopping MySQL/MariaDB..." 
      if kill `cat "$DIR/_mysql/mysql_pid"`; then 
        dp "Ok." 
      else 
        dp "Failed to stop MySQL/MariaDB." 
      fi 
    else 
      dp "MySQL/MariaDB does not appear to be running." 
    fi 
  fi 
} 
 
setup_for_tests() { 
    # Kill roxen mysql if it's running... 
    if [ -f "$VARDIR/test_config/_mysql/mysql_pid" ] ; then 
      kill `cat "$VARDIR/test_config/_mysql/mysql_pid"` 
    fi 
    self_test=y 
    DEFINES="-DRUN_SELF_TEST -DSELF_TEST_DIR=\"$SELF_TEST_DIR\" $DEFINES" 
    DEFINES="$DEFINES \"-M$SELF_TEST_DIR/modules\"" 
    DEFINES="$DEFINES \"-Metc/test/modules\"" 
    rm -rf "$VARDIR/test_config"* 
    DIR="$VARDIR/test_config" 
    if [ -f "$SELF_TEST_DIR/scripts/setup.pike" ] ; then 
      eval "\"$pike\" $PIKEARGS $DEFINES \"$SELF_TEST_DIR/scripts/setup.pike\" \"$SELF_TEST_DIR\" \"$VARDIR\"" 
    fi 
    once=${once:-1} 
    debug=1 
    #remove_dumped=1 
} 
 
parse_args() { 
 while [ ! c"$1" = "c" ] ; do 
  case "$1" in 
  -D*) 
   DEFINES="$DEFINES $1" 
  ;; 
  -l*) 
   ARGS="$ARGS $1" 
  ;; 
  --truss) 
     truss="truss" 
   ;; 
  --truss-c) 
     truss="truss -c" 
   ;; 
  --strace) 
     truss="strace" 
   ;; 
  --log-dir=*) 
   LOGDIR=`echo $1 | sed -e 's/--log-dir=//'` 
   export LOGDIR 
  ;; 
  --debug-log=*) 
   DEBUGLOG=`echo $1 | sed -e's/--debug-log=//'` 
  ;; 
  --config-dir=*) 
   DIR=`echo $1 | sed -e 's/--config-dir=//'` 
   FILES=`echo $1 | sed -e's/--config-dir=//' -e's/\.//g' -e's./..g' -e 's.-..g'` 
  ;; 
  --pid-file=*) 
   pidfile=`echo $1 | sed -e 's/--pid-file=//'` 
  ;; 
  '--with-security'|'--enable-security') 
    DEFINES="$DEFINES -DSECURITY" 
  ;; 
  '--with-snmp-agent'|'--enable-snmp-agent') 
    DEFINES="$DEFINES -DSNMP_AGENT" 
  ;; 
 
  '--debug'|'--with-debug'|'--enable-debug') 
    debug=1 
  ;; 
  '--without-debug') 
    debug=-1 
  ;; 
  '--module-debug'|'--with-module-debug'|'--enable-module-debug') 
    debug=0 
  ;; 
  '--fd-debug'|'--with-fd-debug'|'--enable-fd-debug') 
    DEFINES="-DFD_DEBUG $DEFINES" 
  ;; 
  '--strip-backslash'|'--without-backslash'|'--strip-back-slash') 
    DEFINES="-DSTRIP_BSLASH $DEFINES" 
  ;; 
  '--offline') 
    DEFINES="-DNO_DNS -DOFFLINE $DEFINES" 
  ;; 
  '--without-ram-cache'|'--disable-ram-cache') 
    DEFINES="`echo $DEFINES | sed -e 's/-DRAM_CACHE//g'`" 
  ;; 
  '--without-http-compression'|'--disable-http-compression') 
    DEFINES="`echo $DEFINES | sed -e 's/-DHTTP_COMPRESSION//g'`" 
  ;; 
  '--without-ram-cache-stat'|'--disable-ram-cache-stat') 
    DEFINES="`-DRAM_CACHE_ASUME_STATIC_CONTENT`" 
  ;; 
  '--dump-debug'|'--with-dump-debug'|'--enable-dump-debug') 
    DEFINES="-DDUMP_DEBUG $DEFINES" 
  ;; 
  '--threads'|'--with-threads'|'--enable-threads') 
    DEFINES="-DENABLE_THREADS $DEFINES" 
  ;; 
  '--no-threads'|'--without-threads'|'--disable-threads') 
    echo "Thread support not optional -- ignoring $1" >&2 
  ;; 
  '--with-profile'|'--profile') 
    DEFINES="-DPROFILE $DEFINES" 
  ;; 
  '--with-file-profile'|'--file-profile') 
    DEFINES="-DPROFILE -DFILE_PROFILE $DEFINES" 
  ;; 
  '--without-daemon'|'--without-deamonize') 
    daemonize=no 
  ;; 
  '--generations='*) 
    GENERATIONS=`echo $1 | sed -e 's/--generations=//'` 
    if test "$GENERATIONS" -gt 1; then :; else 
      echo "Invalid number of log generations: $GENERATIONS" >&2 
      echo "Using default: 5" >&2 
      GENERATIONS=5 
    fi 
  ;; 
  '--generations') 
    GENERATIONS="$2" 
    shift 
    if test "$GENERATIONS" -gt 1; then :; else 
      echo "Invalid number of log generations: $GENERATIONS" >&2 
      echo "Using default: 5" >&2 
      GENERATIONS=5 
    fi 
  ;; 
  --module-hot-reload=*) 
    if test "x$module_hot_reload" = "x"; then 
      DEFINES="-DMODULE_HOT_RELOAD $DEFINES" 
    fi 
    mod=`echo $1 | sed -e 's/--module-hot-reload=//'` 
    module_hot_reload="$mod $module_hot_reload" 
  ;; 
  --module-hot-reload-conf=*) 
    mod=`echo $1 | sed -e 's/--module-hot-reload-conf=//'` 
    module_hot_reload_conf="$mod $module_hot_reload_conf" 
  ;; 
  '--quiet'|'-q') 
    verbose=0 
  ;; 
  '--verbose'|'-v') 
    verbose=2 
    debug=1 
  ;; 
  '--remove-dumped') 
     remove_dumped=1; 
  ;; 
  '--stop') 
     stop="TERM"; 
     start=""; 
  ;; 
  '--restart') 
     stop="TERM"; 
     start=1; 
  ;; 
  '--signal') 
     stop="$2" 
     shift 
     start=""; 
  ;; 
 
  '--once') 
    once=${once:-1} 
    debug=0 
  ;; 
# Misspelling --once might give undesirable results, so let's accept 
# some "creative" spellings...  :-) 
  '--onve'|'--onec'|'--onev'|'--ocne') 
    once=${once:-1} 
    debug=0 
  ;; 
  '--keep-mysql') 
    keep_mysql=1 
  ;; 
  '--mysql-only') 
    keep_mysql=2 
    once=1 
    pass="$pass --mysql-only" 
    ;; 
  '--gdb') 
    gdb=gdb 
    once=2 
    debug=0 
  ;; 
  --valgrind|--valgrind=*) 
    valgrind="$1" 
    once=2 
    debug=0 
  ;; 
  '--program') 
    program="$2" 
    once=2 
    passhelp=1 
    keep_mysql=1 
    shift 
    shift 
    # Pass any remaining arguments along to the program. 
    while [ ! c"$1" = "c" ] ; do 
      pass="$pass '`echo \"$1\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'" 
      shift 
    done 
    break 
  ;; 
  '--cd') 
    cd_to="$2" 
    # Use the absolute path... 
    roxendir="`pwd`" 
    once=${once:-1} 
    shift 
  ;; 
  --debug-without=*|-r*|-d*|-t*|-l*|-w*|-a*|-p*|--*-debug*) 
    # Argument passed along to Pike. 
    ARGS="$ARGS $1" 
  ;; 
  -D*|-M*|-I*|-P*) 
    # Argument passed along to Pike. 
    DEFINES="$DEFINES \"$1\"" 
  ;; 
  --pikeargs=*) 
    PIKEARGS="$PIKEARGS "`expr "$1" : '--pikeargs=\(.*\)'` 
  ;; 
  '--version') 
   if [ "x$passhelp" = "x1" ] ; then 
     pass="$pass --version" 
   else 
    if [ -f base_server/roxen.pike ]; then 
      echo "Roxen WebServer `roxen_version`" 
      exit 0 
    else 
      echo 'base_server/roxen.pike not found!' 
      exit 1 
    fi 
   fi 
  ;; 
  --self-test-dir=*) 
    SELF_TEST_DIR=`echo $1 | sed -e's/^--self-test-dir=//'` 
  ;; 
  '--self-test') 
    do_setup_for_tests=1 
  ;; 
  '--self-test-quiet') 
    SILENT_START=y 
    do_pipe="| grep '  |'" 
    do_setup_for_tests=1 
    debug=-1 
  ;; 
  '--self-test-verbose') 
    pass="$pass --tests-verbose=1" 
    do_setup_for_tests=1 
  ;; 
  '--help'|'-?') 
   if [ "x$passhelp" = "x1" ] ; then 
     pass="$pass --help" 
   else 
  sed -e "s/\\.B/`tput 'bold' 2>/dev/null`/g" -e "s/B\\./`tput 'sgr0' 2>/dev/null`/g" << EOF 
.BThis command will start the Roxen WebServerB.. 
 
The environment variable .BROXEN_ARGSB. can be used to specify 
the default arguments. 
 
   .BArguments:B. 
 
      .B--versionB.:                  Output version information. 
 
      .B--help -?B.:                  This information. 
 
      .B--offlineB.:                  Indicate that there is no network  
                                  connection available. Disables DNS and some 
                                  other similar things. 
 
      .B--remove-dumpedB.:            Remove all dumped code, thus forcing 
                                  a recompile. 
 
      .B--verbose -vB.:               Enable more verbose messages. 
 
      .B--quiet -qB.:                 Disable most of the messages. 
 
      .B--log-dir=DIRB.:              Set the log directory. Defaults to .B../logsB.. 
 
      .B--config-dir=DIRB.:           Use an alternate configuration directory. 
                                  Defaults to .B../configurationsB.. 
 
      .B--debug-log=FILEB.:           Use an alternate debuglog file. 
                                  Defaults to .B../logs/debug/B.configdirname.B.1B.. 
 
      .B--pid-file=FILEB.:            Store the Roxen and start script pids in this 
                                  file. Defaults to .B../configurations/_roxen_pidB.. 
 
      .B--silent-startB.:             Inhibits output to stdout. If used, 
                                  this argument must be the first one. 
 
      .B--strip-backslashB.:          Replace all \\ characters in URIs with / 
 
      .B--without-daemonB.:           Do not detach from the started server. 
                                  This is typically used with launchd. 
 
      .B--without-ram-cacheB.:        Do not use a protocol level RAM cache to speed 
                                  things up. Saves RAM at the cost of speed. 
 
      .B--without-ram-cache-statB.:   Disable the stat that is usually done 
                                  for files in the protocol cache to ensure that 
                                  they are not changed before they are sent. 
                                  Improves performance at the cost of constant 
                                  aggravation if the site is edited. Useful for 
                                  truly static sites. 
 
      .B--without-http-compressionB.: Disable gzip compression for HTTP requests. 
 
      .B--with-threadsB.:             If threads are available, use them. 
 
      .B--without-threadsB.:          Even if threads are enabled by default, 
                                  disable them. 
 
      .B--with-profileB.:             Store runtime profiling information on 
                                  a directory basis. This information is 
                                  not saved on permanent storage, it is only 
                                  available until the next server restart 
                                  This will enable a new 'action' in the 
                                  administration interface 
 
      .B--with-file-profileB.:        Like .B--with-profileB., but save information 
                                  for each and every file. 
 
      .B--generations=NUMBERB.:       Specify the number of generations for the 
                                  log rotation. Default: 5. 
 
      .B--self-testB.:                Runs a testsuite. 
      .B--self-test-verboseB.:        Runs a testsuite, report all tests. 
      .B--self-test-quietB.:          Runs a testsuite, only report errors. 
      .B--self-test-dir=DIRB.:        Use this self test directory instead of 
                                  the default .Betc/testB. directory. 
 
      .B--onceB.:                     Run the server only once, in the foreground. 
                                  This is very useful when debugging. Implies 
                                  --module-debug. 
 
      .B--stopB.:                     Stop the server. 
 
      .B--restartB.:                  Stop the server, and then restart it. 
 
      .B--signalB.:                   Send the specified signal to the running 
                                  Roxen process. 
 
      .B--keep-mysqlB.:               Do not shut down MySQL process when exiting 
                                  the start script. Useful during development 
                                  or any other scenario where the start script 
                                  is frequently terminated. 
 
      .B--mysql-onlyB.:               Start the embedded MySQL process, but 
                                  do not start the rest of Roxen. May be 
                                  combined with --stop. 
 
      .B--gdbB.:                      Run the server in gdb. Implies .B--onceB.. 
 
      .B--valgrind[=valgrind args]B.: Run the server in valgrind. Implies .B--onceB.. 
 
      .B--programB.:                  Start a different program with the Roxen 
                                  Pike. As an example, 
                                  .B./start --program bin/install.pikeB. will 
                                  start the installation program normally 
                                  started with .B./installB. 
 
      .B--with-debugB.:               Enable debug 
 
      .B--without-debugB.:            Disable all debug. This is the default. 
 
      .B--module-debugB.:             Enable more internal debug checks to 
                                  simplify debugging of Roxen modules. 
 
      .B--module-hot-reload=<module-name>B. 
                                  Enable hot reload of .B<module-name>B.. The module 
                                  will be reloaded whenever the file is saved. 
                                  NOTE! This should ONLY be used in a development 
                                  environment. This flag can appear more than once. 
                                  .B<module-name>B. is the filename minus the extension 
                                  of the module. 
 
      .B--module-hot-reload-conf=<conf>B. 
                                  Set for which configuration .B--module-hot-reloadB. 
                                  should be applied. By default all module instances 
                                  in all configurations will be hot-reloaded. 
 
      .B--mysql-log-queriesB.:        Instruct the MySQL server to log all 
                                  queries so that they end up in the Roxen 
                                  debug log. 
 
      .B--fd-debugB.:                 Enable FD debug. 
 
      .B--dump-debugB.:               Enable dump debug. 
 
      .B--trussB.:                    (Solaris only). Run the server under 
                                  truss, shows .BallB. system calls. This is 
                                  extremely noisy, and is not intented for 
                                  anything but debug. 
 
      .B--truss-cB.:                  (Solaris only). Run the server under 
                                  truss -c, shows times for all system calls 
                                  on exit. This is not intented for anything 
                                  but debug. Slows the server down. 
 
      .B--with-snmp-agentB.:          Enable internal SNMP agent code. 
 
  .BArguments passed to Pike:B. 
 
       .B-DDEFINEB.:                  Define the symbol .BDEFINEB.. 
 
       .B-d<level>B.:                 Set the runtime Pike debug to level. 
                                  This only works if Pike is compiled 
                                  with debug (i.e. with --rtl-debug to 
                                  configure). 
 
       .B-rtB.:                       Enable runtime typechecking. 
                                  Things will run more slowly, but it is very 
                                  useful while developing code. 
 
                                  Enabled when starting Roxen with --debug 
 
       .B-rTB.:                       Enable strict types. 
                                  Same as adding #pragma strict-types 
                                to all files. 
 
                                  This enables more strict 
                                  type-checking, things that are 
                                  normally permitted (such as calling 
                                  a mixed value, or assigning a typed 
                                  object variable with an untyped 
                                  object) will generate warnings. 
 
                                  Useful for module and Roxen core 
                                  developers, but not so useful for 
                                  the occasional pike-script-writer. 
 
                                  Enabled when starting Roxen with --debug 
 
       .B-s<size>B.:                  Set the stack size. 
 
       .B-M<path>B.:                  Add the path to the Pike module path. 
 
       .B-I<path>B.:                  Add the path to the Pike include path. 
 
       .B-P<path>B.:                  Add the path to the Pike program path. 
 
       .B-dtB.:                       Turn off tail recursion optimization. 
 
       .B-tB.:                        Turn on Pike level tracing. 
 
       .B-pB.:                        Turn on Pike profiling. 
 
       .B-t<level>B.:                 Turn on more Pike tracing. This only 
                                  works if Pike is compiled with debug 
                                  (i.e. with --rtl-debug to configure). 
 
       .B-a<level>B.:                 Turn on Pike assembler debug. This only 
                                  works if Pike is compiled with debug 
                                  (i.e. with --rtl-debug to configure). 
 
       .B-wB.:                        Turn on Pike warnings. 
 
       .B--pikeargs=<args>B.:         Pass arbitrary arguments to Pike. 
 
  .BEnvironment variables:B. 
 
     .BLANGB.:                        Used to determine the default locale 
                                  in the administration interface and logs. 
     .BROXEN_CONFIGDIRB.:             Same as .B--config-dir=... B. 
     .BROXEN_PID_FILEB.:              Same as .B--pid-file=... B. 
     .BROXEN_LANGB.:                  The default language for all language 
                                  related tags. Defaults to 'en' for english. 
 
EOF 
    tput 'rmso' 2>/dev/null 
    exit 0 
    fi 
   ;; 
  *) 
    pass="$pass '`echo \"$1\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'" 
   ;; 
  esac 
  shift 
 done 
 
 if [ "x$do_setup_for_tests" = x1 ]; then 
   setup_for_tests 
 fi 
} 
 
if [ ! "X$ROXEN_ARGS" = "X" ]; then 
  parse_args $ROXEN_ARGS 
fi 
 
parse_args "$@" 
 
if [ "$once" = "" ]; then :; else 
  # Once-mode. 
  if [ "x$passhelp" = "x1" ]; then :; else 
    # We're not using --program. 
    # Pass --once along to roxenloader. 
    pass="$pass --once=$once" 
  fi 
fi 
 
# The work has already been done above, but the debug printout is better 
# to have _after_ parse_args (consider --help and --version) 
 
if [ ! "X$ROXEN_ARGS" = "X" ]; then 
  if [ $verbose -gt 0 ]; then 
    dp "Used $ROXEN_ARGS from ROXEN_ARGS." 
  else :; fi 
fi 
 
if [ ! "X$pass" = "X" ] ; then set -- $pass ;fi 
 
 
####### END ARGUMENT PARSING 
 
 
####### BEGIN PIKE OPTIONS 
 
# Roxen WebServer will create files as the initial user, 
# which it expects to be able to read as the run-time user. 
umask 022 
 
if [ "x$PIKE_NO_DEFAULT_PATHS" = "x" ]; then 
  # Pike default Master-program 
  if [ "x$PIKE_MASTER" = "x" ]; then 
    if [ -f lib/master.pike ]; then 
      DEFINES="$DEFINES \"-m$roxendir/lib/master.pike\"" 
    elif [ -f lib/pike/master.pike ]; then 
      DEFINES="$DEFINES \"-m$roxendir/lib/pike/master.pike\"" 
    fi 
  else 
    # This is useful when using several different Pikes. 
    # Specify include and module paths with 
    # PIKE_INCLUDE_PATH and PIKE_MODULE_PATH 
    # they are handled automatically by the master, 
    # so no need to do it here. 
    DEFINES="$DEFINES \"-m$PIKE_MASTER\"" 
  fi 
 
  # Kludge to add pike modules required by base_server to the 
  # module path. Remove when the package system comes in use. 
  for d in modules/feedimport; do 
    for pm in pike_modules pike-modules; do 
      if [ -d "$roxendir/$d/$pm/." ]; then 
        DEFINES="$DEFINES \"-M$roxendir/$d/$pm\"" 
      fi 
    done 
  done 
fi 
 
# Extra module-path 
#if [ -d etc/modules ]; then 
  DEFINES="$DEFINES \"-M$roxendir/etc/modules\"" 
#fi 
 
if [ -d "$LOCALDIR/pike_modules/." ]; then 
  DEFINES="$DEFINES \"-M$LOCALDIR/pike_modules\"" 
fi 
 
# Extra include-path 
#if [ -d etc/include ]; then 
  DEFINES="$DEFINES \"-I$roxendir/etc/include\"" 
#fi 
 
if [ -d "$LOCALDIR/include/." ]; then 
  DEFINES="$DEFINES \"-I$LOCALDIR/include\"" 
fi 
 
# Extra include-path (2) 
#if [ -d base_server ]; then 
  DEFINES="$DEFINES \"-I$roxendir/base_server\" \"-P$roxendir/base_server\"" 
#fi 
 
if [ -d "$LOCALDIR/base_server/." ]; then 
  DEFINES="$DEFINES \"-I$LOCALDIR/base_server\" \"-P$LOCALDIR/base_server\"" 
fi 
 
# Extra program-path 
DEFINES="$DEFINES \"-P`pwd`\"" 
 
# Support for adding local pike-modules 
if [ -d "$LOCALDIR/etc/." ]; then 
  # Extra module-path 
  if [ -d "$LOCALDIR/etc/modules/." ]; then 
    DEFINES="$DEFINES \"-M$LOCALDIR/etc/modules\"" 
  fi 
 
  # Extra include-path 
  if [ -d "$LOCALDIR/etc/include/." ]; then 
    DEFINES="$DEFINES \"-I$LOCALDIR/etc/include\"" 
  fi 
 
  # Extra program-path 
  DEFINES="$DEFINES \"-P$LOCALDIR/etc\"" 
fi 
 
# Extra kludge for HPUX 
# HPUX doesn't like group 60001(nobody) 
if uname | grep 'HP-UX' >/dev/null 2>&1; then 
  if [ $verbose -gt 0 ]; then 
    dp "WARNING: Applying kludge for HPUX. (see base_server/roxen.pike)" 
  else :; fi 
  DEFINES="$DEFINES -DHPUX_KLUDGE" 
fi 
 
 
case "x$debug" in 
  "x"|"x0") 
    DEBUG="-DMODULE_DEBUG " 
    ARGS="$ARGS -w" 
    ;; 
  "x-1") 
    DEBUG="" 
    ;; 
  "x1") 
    DEBUG="-DDEBUG -DMODULE_DEBUG" 
    ARGS="$ARGS -w" 
    ;; 
esac 
 
DEFINES="$DEBUG $DEFINES" 
 
####### END PIKE OPTIONS 
 
####### START MySQL 
 
if [ -f "mysql-location.txt" ]; then :; else 
  if [ "x$passhelp" = "x1" ]; then :; else 
    dp "Warning: No mysql-location.txt" 
  fi 
fi 
 
####### END MySQL 
 
# Canonical configuration directory identifier (the inode number). 
canonicalconf=`ls -Lid "$DIR/." | awk '{ print $1; }'` 
 
if [ $verbose -gt 1 -a "$passhelp" = "" ]; then 
  dp "Canonical Roxen configuration identifier: $canonicalconf." 
fi 
 
start_pid="$$" 
 
# 
# Some useful functions 
# 
 
# Check whether there's a valid pid lock on pid $1 
# of process type $2 for configuration $3. 
check_pid_file_lock() { 
  # Check that there's a lock-file. 
  # 
  # Primary check is in /var/run/ which often is restricted to root. 
  # Secondary check is in /tmp/ to allow for normal users running 
  # the script unmodified. 
  if [ "$verbose" -gt 1 ]; then 
    dp "Checking pid-file lock roxen-$2.$1.pid for configuration $3." 
  fi 
  if [ -f "/var/run/roxen-$2.$1.pid" -o -f "/tmp/roxen-$2.$1.pid" ]; then 
    # Check that the pid file belongs to our configuration. 
    if [ "x$3" = "x" -o "x`cat /var/run/roxen-$2.$1.pid 2>/dev/null || cat /tmp/roxen-$2.$1.pid 2>/dev/null`" = "x$3" ]; then 
      return 0 
    fi 
  fi 
  return 1 
} 
 
# Remove the lock on pid $1 of process type $2 for configuration $3 
# (if any). 
cleanup_pid_file_lock() { 
  if [ -z "$pidfile" ]; then return 0; fi 
  if check_pid_file_lock "$1" "$2" "$3"; then 
    if [ $verbose -gt 1 ]; then 
      dp "Releasing pid-file lock roxen-$2.$1.pid." 
    fi 
    rm -f "/tmp/roxen-$2.$1.pid" 2>/dev/null 
    rm -f "/var/run/roxen-$2.$1.pid" 2>/dev/null 
  fi 
} 
 
# Cleanup after the start-script. 
cleanup_start_pid_file() { 
  cleanup_pid_file_lock "$start_pid" "start" "$canonicalconf" 
  [ -z "$pidfile" ] || rm -f $pidfile 
} 
 
# Cleanup after Roxen. 
cleanup_roxen_pid_file() { 
  if [ -z "$pidfile" ]; then return 0; fi 
  read roxenpid <"$pidfile" 
  if [ "x$roxenpid" = "xx" ]; then :; else 
    if check_pid_file_lock "$roxenpid" "server" "$canonicalconf"; then 
      # There's a valid pid file lock for the server for this configuration. 
      # Delete it. 
      cleanup_pid_file_lock "$roxenpid" "server" "$canonicalconf" 
    fi 
    # Remove the stale pid from the pid-file. 
    if [ $verbose -gt 1 ]; then 
      dp "Removing stale pids from $pidfile." 
    fi 
    { echo "x"; echo "$start_pid"; } >"$pidfile" 
  fi 
} 
 
# Check if the PID in $1 is an active process. 
processp() { 
  if kill -0 "$1"; then return 0; fi; 
 
  # Check that the cause for the failure is that the process doesn't exist. 
  eval "\"$pike\" $PIKEARGS $DEFINES -e 'return !kill('\"$1\"', 0) && (errno() == System.ESRCH);'"; 
  return; 
} 
 
# Check if the PID in $1 is an active process and has 
# a $2 {start,server} lock-file associated with the 
# configuration $3. 
roxenp() { 
  if check_pid_file_lock "$1" "$2" "$3"; then 
    # Check that the process exists as well. 
    if processp "$1"; then return 0; fi 
    # Cleanup the lock, since it is stale. 
    cleanup_pid_file_lock "$1" "$2" "" 
  fi 
  return 1; 
} 
 
# Create a roxen lock-file for PID $1 of type $2 
# associated with configuration $3. 
lock_pid_file() { 
  if [ -z "$pidfile" ]; then return 0; fi 
  # Create a lock-file. 
  if [ $verbose -gt 1 ]; then 
    dp "Creating lockfile roxen-$2.$1.pid for configuration $3." 
  fi 
  # NB: The subshell is needed to avoid script termination on 
  #     permission error (this occurs with /bin/sh on Solaris). 
  ( echo "$3" >"/var/run/roxen-$2.$1.pid"; ) 2>/dev/null || \ 
      echo "$3" >"/tmp/roxen-$2.$1.pid" 2>/dev/null 
} 
 
# NOTE: The following function needs to be reentrant. 
signal_exit() { 
  test "x$once" != x2 && dp "Start script terminating." 
  trap "" 2 15 
  if [ "x$ROXEN_PID" != "x" ]; then 
    if processp $ROXEN_PID 2>/dev/null; then 
      kill $ROXEN_PID 2>/dev/null && wait $ROXEN_PID 2>/dev/null 
    fi 
    # Zap the pid lock file if it is still around. 
    # NB: We don't need to clean the pid-file, since 
    #     we will zap it later. 
    cleanup_pid_file_lock "$ROXEN_PID" "server" "" 
    ROXEN_PID="" 
    dp "Roxen WebServer shutdown." 
    # FIXME: Consider exiting here. 
  fi 
  if [ "x$keep_mysql" = "x" ] ; then 
    if [ -f "$DIR/_mysql/mysql_pid" ] ; then 
        mysql_pidfile="$DIR/_mysql/mysql_pid" 
    elif [ -f "$ROXEN_DATADIR/mysql/mysql_pid" ] ; then 
        mysql_pidfile="$ROXEN_DATADIR/mysql/mysql_pid" 
    fi 
    if [ "x$mysql_pidfile" != "x" ] ; then 
      mysql_pid="`cat $mysql_pidfile 2>/dev/null`" 
      dp_no_nl "Shutting down MySQL." 
      kill "$mysql_pid" 2>/dev/null 
      # Give mysql 5 minutes to shut down. 
      timer="" 
      while [ -f "$mysql_pidfile" -a \ 
              "$timer" != "mmmmm" ] && \ 
            processp "$mysql_pid" 2>/dev/null; do 
        sleep 2 
        timer=`echo "x$timer" | sed -e 's/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/m/'` 
        if [ "x$SILENT_START" != "xy" ]; then 
          # Progress indicator. 
        echo "." | tr -d ' 
' >&2 
        fi 
      done 
      if [ "x$SILENT_START" != "xy" ]; then 
        echo >&2 
      fi 
      if processp "$mysql_pid" 2>/dev/null; then 
        dp "Shutting down MySQL the hard way." 
        kill -9 "$mysql_pid" 2>/dev/null 
      fi 
      if [ -f "$mysql_pidfile" ] && \ 
         [ "$mysql_pid" = "`cat $mysql_pidfile`" ]; then 
        rm -f "$mysql_pidfile" 2>/dev/null 
      fi 
    fi 
  fi 
  cleanup_start_pid_file 
  test "x$once" != x2 && dp "Start script terminated." 
  exit 0 
} 
 
exit_fail() { 
  exitcode=1 
} 
 
# This is a trick to get $ROXEN_PID and arguments containing spaces 
# correct at the same time. 
fork_roxen() { 
  if [ $verbose -gt 0 ]; then 
    dp "Server start command:" 
    for arg 
    do 
      dp "    $arg" 
    done 
  fi 
  "$@" & 
  ROXEN_PID=$! 
} 
 
# Start Roxen 
# 
# Entry/exit invariants: 
# 
#   The pid-file does not contain an entry for the roxen process. 
# 
#   The server pid lock file is nonexistant. 
# 
# During running (NB: updated by the Roxen process): 
# 
#   The pid-file contains the Roxen server process pid as the first entry. 
# 
#   The corresponding server pid lock file exists. 
start_roxen() { 
  check_owner 
  raise_limit 
 
  if [ x$remove_dumped = x1 ] ; then 
    remove_old_dot_o_files "user request" 
  fi 
  if [ "x$DIR" != "x../configurations" ] ; then 
    args="$PIKEARGS $DEFINES $ARGS $program --config-dir='`echo \"$DIR\" | sed -e \"s/'/'\\\"'\\\"'/g\"`' $pass" 
  else 
    args="$PIKEARGS $DEFINES $ARGS $program $pass" 
  fi 
  if [ x"$cd_to" != x ] ; then 
    cd "$cd_to" 
  fi 
  exitcode="0" 
  if [ "x$gdb" = "xno" -a "x$valgrind" = "x" ]; then 
    if [ "x$once" = "x" ]; then 
      if [ $verbose -gt 0 ]; then 
        dp "Executing $pike $args"|sed -e "s!`pwd`!.!g" 
      fi 
      eval "fork_roxen \"$pike\" $args 2>>\"${DEBUGLOG}.1\" 1>&2" 
      dp "Roxen WebServer server pid $ROXEN_PID." 
      lock_pid_file "$ROXEN_PID" "server" "$canonicalconf" 
      wait $ROXEN_PID 2>/dev/null 1>&2 
      exitcode="$?" 
      ROXEN_PID="" 
    else 
      if [ "x$do_pipe" = "x" ] ; then 
        if [ "x$once" = "x1" ]; then 
          eval "fork_roxen $truss \"$pike\" $args 2>&1" 
          wait $ROXEN_PID 2>/dev/null 1>&2 
          exitcode="$?" 
          ROXEN_PID="" 
        else 
          eval "$truss \"$pike\" $args" 2>&1 
          exitcode="$?" 
        fi 
      else 
        trap exit_fail 1 
        eval "(eval \"$truss \\\"$pike\\\" $args\" || kill -1 $$) 2>&1  $do_pipe" 
        cleanup_roxen_pid_file 
        exit $exitcode 
      fi 
    fi 
  elif [ "x$gdb" != "xno" ]; then 
    echo >.gdbinit handle SIGPIPE nostop noprint pass 
    echo >>.gdbinit handle SIGUSR1 nostop noprint pass 
    echo >>.gdbinit handle SIGUSR2 nostop noprint pass 
    echo >>.gdbinit handle SIGLWP nostop noprint pass 
    if uname | grep 'Linux' >/dev/null 2>&1; then 
      echo >>.gdbinit handle SIG38 nostop noprint pass 
      echo >>.gdbinit handle SIG39 nostop noprint pass 
    fi 
    echo >>.gdbinit break debug_fatal 
    echo >>.gdbinit break pike_gdb_breakpoint 
    firstline=`head -1 "$pike" 2>/dev/null` 
    if expr "x$firstline" : 'x#! */.*' >/dev/null; then 
      # Looks like a script. gdb will not grok it, so we try passing 
      # --gdb to it instead (which works in the special case of the 
      # bin/pike script that is built by the top level Makefile in the 
      # Pike source tree). 
      dp "Executing $pike --gdb $args" 
      eval "\"$pike\" --gdb $args" 
    else 
      dp "Executing gdb $pike $args" 
      echo >>.gdbinit "run $args" 
      gdb "$pike" 
    fi 
    rm .gdbinit 
  else 
    firstline=`head -1 "$pike" 2>/dev/null` 
    if expr "x$firstline" : 'x#! */.*' >/dev/null; then 
      dp "Executing $pike $valgrind $args" 
      eval "\"$pike\" \"$valgrind\" $args" 
    else 
      dp "Executing valgrind $pike $args" 
      valgrind `expr "$valgrind" : '--valgrind=\(.*\)'` "$pike" 
    fi 
  fi 
  cleanup_roxen_pid_file 
} 
 
# <pid> <signal> <type> <canonicalconf> <description> 
stop_roxen() 
{ 
  if roxenp "$1" "$3" "$4"; then 
    if [ "$2" = "TERM" ]; then 
      dp "Shutting down the $5..." 
      kill "$1" || exit 1 
      while processp "$1" 2>/dev/null; do 
        echo "Waiting for $5 $1 to die." >&2 
        sleep 1 
      done 
    else 
      kill "-$2" "$1" || exit 1 
    fi 
    return 0 
  fi 
  return 1 
} 
 
# 
# Now do the stuff 
# 
 
trap signal_exit 2 15 
trap "" 1 
 
if [ "$program" = "base_server/roxenloader.pike" ] ; then 
  # Starting a Roxen server. Fix the pid file. 
  [ -z "$pidfile" ] && pidfile="${ROXEN_PID_FILE:-$DIR/_roxen_pid}" 
  pass="$pass --pid-file='`echo \"$pidfile\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'" 
  if [ "x$module_hot_reload" != "x" ]; then 
    pass="$pass --module-hot-reload=\"$module_hot_reload\"" 
  fi 
  if [ "x$module_hot_reload_conf" != "x" ]; then 
    pass="$pass --module-hot-reload-conf=\"$module_hot_reload_conf\"" 
  fi 
  # Check for stop. 
  if [ "$stop"x != x ] 
  then 
    if [ -f "$pidfile" ]; then 
      if read roxenpid && read scriptpid; then 
        problems="" 
        # NB: No need to shut down the start-script 
        #     if we're going to do a restart. 
      if [ "$start"x = x -a "$stop" = "TERM" ]; then 
          if stop_roxen "$scriptpid" "TERM" "start" "$canonicalconf" "start script"; then 
            : 
          else 
            problems="nostart" 
          fi 
        fi 
        # NB: At this point the original start script has 
      #     often already shut down the server, but... 
      if stop_roxen "$roxenpid" "$stop" "server" "$canonicalconf" "Roxen server"; then 
          : 
        else 
          problems="$problems:noserver" 
        fi 
        if [ "$problems" = "nostart:noserver" ]; then 
          dp "There is a pid file $pidfile," 
          dp "but the corresponding processes do not exist," 
          dp "or are not associated with this configuration." 
          dp "Stale pid file? Deleting the pid file." 
          rm "$pidfile" 
          : 
        fi 
        if [ "$problems:$start" = "nostart:1" ]; then 
          dp "The listed start script was dead. Starting a new one." 
          : 
        fi 
      else 
        dp "There is a pid file $pidfile," 
        dp "but it seems to be truncated." 
        exit 1 
      fi < "$pidfile" 
 
      if [ "x$keep_mysql" = "x2" ]; then 
        stop_mysql; 
      fi 
    elif [ "x$keep_mysql" = "x2" ]; then 
      stop_mysql; 
    else 
      dp "The pid file $pidfile does not exist." 
      dp "The server is probably not running." 
      if [ "$stop" != "TERM" ]; then 
        exit 1 
      fi 
    fi 
    if [ "$start"x = x ]; then 
      exit 0 
    fi 
  fi 
  # Avoid duplicate start scripts if we got a pid file. 
  if [ -f "$pidfile" ]; then 
    ( 
      if read roxenpid && read scriptpid; then 
        if roxenp "$scriptpid" "start" "$canonicalconf" 2>/dev/null ; then 
          if [ "$stop"x = x ]; then 
            dp "According to the pid file $pidfile," 
            dp "there is already a start script running with pid $scriptpid. Specify " 
            dp "another pid file with --pid-file if this is a different server." 
            dp "Server not started." 
            exit 1 
          fi 
          dp "The old start script (pid $scriptpid) should now restart the server." 
          exit 2 
        elif roxenp "$roxenpid" "server" "$canonicalconf" 2>/dev/null ; then 
          dp "According to the pid file $pidfile," 
          dp "there is already a server running with pid $roxenpid, but its start " 
          dp "script seems to have died. You should shut it down and restart " 
          dp "it, since it won't restart automatically. Server not started." 
          exit 1 
        fi 
      fi 
    ) < "$pidfile" || { 
      # NB: The exits above just exit the subshell used for the 
      #     redirect. Adjust the exit codes and exit for real. 
      [ "$?" = "2" ]; 
      exit; 
    } 
  fi 
  # Minor race here. 
  lock_pid_file $start_pid "start" "$canonicalconf" 
  { echo "x" && echo $start_pid; } > "$pidfile" 
  trap cleanup_start_pid_file 0 
fi 
 
PIKEVERSION="`\"$pike\" --version 2>&1|head -1`" 
LS="`ls -lL \"$pike\" 2>/dev/null`" 
LS="$LS `find etc/modules -ls 2>/dev/null`" 
LS="$LS `find base_server -ls 2>/dev/null`" 
 
VERSION_DATA="$PIKEVERSION   $DEFINES   $LS" 
 
if [ "$program" = "base_server/roxenloader.pike" ] ; then 
  if [ "`cat \"$old_roxen_defines\" 2>/dev/null`" != "$VERSION_DATA" ] ; then 
    remove_old_dot_o_files "defines or Pike version changed" 
  fi 
  echo "$VERSION_DATA" > "$old_roxen_defines" 
fi 
 
if [ -z "$once" ] ; then 
  if [ $verbose -gt 0 ]; then 
    dp "Starting the Roxen WebServer." 
  else :; fi 
  if [ "x$DEBUGLOG" = "x" ] ; then 
    DEBUGDIR="$LOGDIR/debug" 
    DEBUGLOG="$DEBUGDIR/$FILES" 
  else 
    DEBUGDIR="`dirname "$DEBUGLOG"`" 
  fi 
  LOGFILE="${DEBUGLOG}.1" 
  export LOGFILE 
 
  # This duplicate of the logdir creation code is needed, check the  
  # redirect below 
  if [ ! -d "$DEBUGDIR" ] ; then 
    if ./mkdir -p "$DEBUGDIR" 2>/dev/null; then :; else 
      dp "Failed to create log directory $DEBUGDIR." 
      cleanup_start_pid_file 
      exit 1 
    fi 
  fi 
  if [ -f "bin/setup_nsr.pike" ]; then 
    # Setup .nsr (Networker) files for the logfile directories. 
    eval "\"$pike\" $PIKEARGS $DEFINES bin/setup_nsr.pike --logdir=\"$LOGDIR\" --debugdir=\"$DEBUGDIR\"" 
  fi 
  if [ $verbose -gt 0 ]; then 
    dp "Using configuration from $DIR" 
    dp "Storing the debug log in ${DEBUGLOG}.1" 
    dp "You can use the administration interface in the server to see debug info." 
  else :; fi 
 
  if ( 
    ( 
      # Minor race here wrt pid file cleanup. 
 
      # Note: We can't use $$ here since it is the pid of the master shell. 
      #       We can't use $(exec sh -c 'echo $PPID') (the POSIX way), for 
      #       multiple reasons, most of them pertaining to /bin/sh on 
      #       Solaris which supports neither $PPID nor $(). 
      old_start_pid="$start_pid" 
      start_pid="`\"$pike\" $PIKEARGS -e 'return (string)getppid();'`" 
      lock_pid_file "$start_pid" "start" "$canonicalconf" 
      [ -z "$pidfile" ] || { echo "x" && echo $start_pid; } > "$pidfile" 
      if [ "x$old_start_pid" = "x$start_pid" ]; then :; else 
        # Get rid of the tentative pid file lock. 
      cleanup_pid_file_lock "$old_start_pid" "start" "$canonicalconf" 
      fi 
 
      exec 3>&- 
      trap signal_exit 2 15 
      trap "" 1 
      trap cleanup_start_pid_file 0 
 
      while : ; do 
        if test -d "$DEBUGDIR/."; then :; else 
          # Avoid infinite loop if the debug directory is deleted. 
        # Thanks to Emils Klotins <emils@dot.lv> for reporting it. 
        if ./mkdir -p "$DEBUGDIR" 2>/dev/null; then :; else 
            dp "Failed to create log directory $DEBUGDIR." 
            cleanup_start_pid_file 
            exit 1 
          fi 
        fi 
 
        dp "Server start at `date`" 
        dp "Debug log in ${DEBUGLOG}.1" 
        rotate "$DEBUGLOG" 
        start_roxen 
 
        if [ "$exitcode" -eq "0" ] ; then 
          # Clean shutdown. 
        dp "Roxen WebServer shutdown." 
          signal_exit 
          # Not reached, but... 
        exit 0 
        fi 
        if [ "$exitcode" -lt "0" ] ; then 
          # Signal death. 
        dp "Roxen WebServer died of signal $exitcode." 
        else 
         case "$exitcode" in 
         100) 
           dp "Changing Roxen WebServer version. Restarting." 
           # We need to clean up the pid file, since we're mentioned in it... 
         cleanup_start_pid_file 
           cd .. && exec ./start "$@" 
           dp 'Failed to spawn start script. -- Permission problem?' 
           exit 1 
           ;; 
         50) 
           dp "Failed to open any port. Shutdown." 
           keep_mysql=1 
           signal_exit 
           # Not reached, but... 
         exit 50 
           ;; 
         *) 
           dp "Roxen WebServer down with code $exitcode." 
           ;; 
         esac 
        fi 
        if [ -f "$LOCALDIR/restart_rc" ]; then 
          dp "Running $LOCALDIR/restart_rc..." 
          if /bin/sh "$LOCALDIR/restart_rc"; then :; else 
            dp "$LOCALDIR/restart_rc failed with code $?." 
          fi 
        fi 
        dp "Restarting..." 
      done 
    ) & 
    # Minor race here wrt pid file contents. 
    start_pid=$! 
    trap "" 0 
    dp "Forked start script, pid $start_pid." 2>&3 
    dp "Start script pid $start_pid." 
 
    if test "x$daemonize" = "xyes"; then :; else 
      trap "stop_roxen $start_pid TERM start \"$canonicalconf\" \"start script\"" 2 15 
      wait; 
      signal_exit 
    fi 
  ) 3>&2 </dev/null >"$DEBUGDIR/start_$FILES.output" 2>&1; then 
    trap "" 0 
    : 
  else 
    dp 'Failed to spawn subshell. -- Permission problem?' 
    cleanup_start_pid_file 
    exit 1 
  fi 
 
  # Try to get rid of some fd's. 
  # Some /bin/sh's have problems detaching otherwise. 
 
  exec >/dev/null 
  exec </dev/null 
else 
  start_roxen 
  if [ "$once" = "1" -a "$exitcode" = "50" ]; then 
    dp "Failed to open any port. Shutdown." 
    keep_mysql=1 
  fi 
  signal_exit 
fi