-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdaemontools_setup
executable file
·134 lines (119 loc) · 4.22 KB
/
daemontools_setup
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
#!/bin/bash
if [ $UID -ne 0 ]; then
echo "You must be root to run this!"
exit
fi
### Warning!!! Don't use leading spaces rather than leading tabs in "Here Documents" ###
# Find out where files are located
source config
if [ "${GEMSTONE_CONFIG}x" = "x" ] ; then
source $GS_HOME/gemstone/stones/$GS_STONE/defStone.env $GS_STONE
else
source $GEMSTONE_CONFIG
fi
echo "`basename $0` creates GemStone templates in $TEMPLATE_DIR for daemontools to run"
echo "Seaside gems, a maintenance gem, and statmons. It does not create links in $SERVICE_DIR."
echo "Shall I continue? (Y/N)"
read cont
case "$cont" in
y|Y|yes)
;;
*)
echo "Not continuing"
exit
;;
esac
case "$SEASIDE_VERSION" in
3.0)
case "$GEMSTONE_VERSION" in
2.4) MAINT_SCRIPT="maintenanceGemSea30_oodb24";;
3.1) MAINT_SCRIPT="maintenanceGemSea30_oodb31";;
*)
echo "GEMSTONE_VERSION in the config file is $GEMSTONE_VERSION"
echo "it must be either 2.4 or 3.1"
exit 1
;;
esac
GEM_SCRIPT="seasideGem30"
# We only need PARAMS because the PORT moved from $1 to $2 in 30
PARAMS='daemon $GEM_PORT'
;;
2.8)
MAINT_SCRIPT="maintenanceGem"
GEM_SCRIPT="seasideGem_FastCGI"
# We only need PARAMS because the PORT moved from $1 to $2 in 30
PARAMS='$GEM_PORT'
;;
*)
echo "SEASIDE_VERSION in the config file is $SEASIDE_VERSION"
echo "it must be either 3.0 or 2.8"
;;
esac
# Create directories expected by daemontools (http://cr.yp.to/daemontools.html)
mkdir -p $TEMPLATE_DIR/gs_maintenance $TEMPLATE_DIR/gstemplate_seaside
# Create template for running maintenance gem
cat > $TEMPLATE_DIR/gs_maintenance/run <<-EOF
#!/bin/bash
source /etc/default/gemstone
if [ "\${GEMSTONE_CONFIG}x" = "x" ] ; then
source \$GS_HOME/gemstone/stones/\$GS_STONE/defStone.env \$GS_STONE
else
source \$GEMSTONE_CONFIG
fi
\$GEMSTONE/bin/waitstone $GEMSTONE_NAME 2
exec setuidgid $GEMSTONE_USER \$GEMSTONE/seaside/bin/$MAINT_SCRIPT
EOF
chmod 755 $TEMPLATE_DIR/gs_maintenance/run
# Create master template for running Seaside gems
cat > $TEMPLATE_DIR/gstemplate_seaside/run <<-EOF
#!/bin/bash
source /etc/default/gemstone
if [ "\${GEMSTONE_CONFIG}x" = "x" ] ; then
source \$GS_HOME/gemstone/stones/\$GS_STONE/defStone.env \$GS_STONE
else
source \$GEMSTONE_CONFIG
fi
scriptpath=\$(dirname \$0)
[ -r \$scriptpath/config.local ] && source \$scriptpath/config.local
\$GEMSTONE/bin/waitstone $GEMSTONE_NAME 2
exec setuidgid $GEMSTONE_USER \$GEMSTONE/seaside/bin/$GEM_SCRIPT $PARAMS
EOF
chmod 755 $TEMPLATE_DIR/gstemplate_seaside/run
# Create templates to run Seaside gems
for i in `seq $STARTING_PORT $ENDING_PORT` ; do
# echo "Creating template in $TEMPLATE_DIR/gs_seaside-${i}"
mkdir -p $TEMPLATE_DIR/gs_seaside-${i}
ln -s /etc/sv/gstemplate_seaside/run $TEMPLATE_DIR/gs_seaside-${i}
echo "export GEM_PORT=${i}" > $TEMPLATE_DIR/gs_seaside-${i}/config.local
chmod 644 $TEMPLATE_DIR/gs_seaside-${i}/config.local
done
# Create templates to run a '1-second' and a '60-second' statmon
GS_OWNER="`ls -ld /home/$GEMSTONE_USER | awk '{ print $3 ":" $4 }'`"
for i in 1 60 ; do
# Rotate '1-second' logs hourly
HRS="1"
# Rotate '60-second' logs daily
[ $i = "60" ] && HRS="24"
# echo "Creating template in $TEMPLATE_DIR/gs_statmon-${i}"
mkdir -p $TEMPLATE_DIR/gs_statmon-${i}
cat > $TEMPLATE_DIR/gs_statmon-${i}/run <<-EOF
#!/bin/bash
source /etc/default/gemstone
if [ "\${GEMSTONE_CONFIG}x" = "x" ] ; then
source \$GS_HOME/gemstone/stones/\$GS_STONE/defStone.env \$GS_STONE
else
source \$GEMSTONE_CONFIG
fi
\$GEMSTONE/bin/waitstone $GEMSTONE_NAME 2
# Create the stats directory if it's not there
mkdir -p /home/$GEMSTONE_USER/stats/${i}-second
chown -R $GS_OWNER /home/$GEMSTONE_USER/stats
cd /home/$GEMSTONE_USER/stats/${i}-second
setuidgid $GEMSTONE_USER \$GEMSTONE/bin/statmonitor $GEMSTONE_NAME -rAzq -h $HRS -i ${i}
EOF
chmod 755 $TEMPLATE_DIR/gs_statmon-${i}/run
done
echo "Created daemontools templates:"
ls -d $TEMPLATE_DIR/gs_* $TEMPLATE_DIR/gstemplate_*
# Success
exit 0