wakame 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +20 -0
- data/README.rdoc +63 -0
- data/Rakefile +86 -0
- data/VERSION +1 -0
- data/app_generators/wakame/templates/README +0 -0
- data/app_generators/wakame/templates/Rakefile +18 -0
- data/app_generators/wakame/templates/bin/wakame-agent +9 -0
- data/app_generators/wakame/templates/bin/wakame-master +9 -0
- data/app_generators/wakame/templates/bin/wakameadm +9 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/apache_app.rb +54 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/apache2.conf +46 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/envvars-app +7 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/sites-app.conf +23 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/system-app.conf +67 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/init.d/apache2-app +192 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/apache_lb.rb +56 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/apache2.conf +46 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/envvars-lb +6 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/sites-lb.conf +54 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/system-lb.conf +75 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/init.d/apache2-lb +192 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/apache_www.rb +50 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/apache2.conf +47 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/envvars-www +7 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/sites-www.conf +23 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/system-www.conf +63 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/init.d/apache2-www +192 -0
- data/app_generators/wakame/templates/cluster/resources/ec2_elastic_ip/ec2_elastic_ip.rb +39 -0
- data/app_generators/wakame/templates/cluster/resources/mysql_master/conf/my.cnf +154 -0
- data/app_generators/wakame/templates/cluster/resources/mysql_master/init.d/mysql +185 -0
- data/app_generators/wakame/templates/cluster/resources/mysql_master/mysql_master.rb +174 -0
- data/app_generators/wakame/templates/config/boot.rb +85 -0
- data/app_generators/wakame/templates/config/cluster.rb +64 -0
- data/app_generators/wakame/templates/config/environments/common.rb +0 -0
- data/app_generators/wakame/templates/config/environments/ec2.rb +3 -0
- data/app_generators/wakame/templates/config/environments/stand_alone.rb +0 -0
- data/app_generators/wakame/templates/config/init.d/wakame-agent +72 -0
- data/app_generators/wakame/templates/config/init.d/wakame-master +73 -0
- data/app_generators/wakame/wakame_generator.rb +124 -0
- data/bin/wakame +18 -0
- data/contrib/imagesetup.sh +77 -0
- data/lib/ext/eventmachine.rb +86 -0
- data/lib/ext/shellwords.rb +172 -0
- data/lib/ext/uri.rb +15 -0
- data/lib/wakame/action.rb +156 -0
- data/lib/wakame/actions/destroy_instances.rb +39 -0
- data/lib/wakame/actions/launch_cluster.rb +31 -0
- data/lib/wakame/actions/migrate_service.rb +65 -0
- data/lib/wakame/actions/propagate_instances.rb +95 -0
- data/lib/wakame/actions/reload_service.rb +21 -0
- data/lib/wakame/actions/scaleout_when_high_load.rb +44 -0
- data/lib/wakame/actions/shutdown_cluster.rb +22 -0
- data/lib/wakame/actions/shutdown_vm.rb +19 -0
- data/lib/wakame/actions/start_service.rb +64 -0
- data/lib/wakame/actions/stop_service.rb +49 -0
- data/lib/wakame/actions/util.rb +71 -0
- data/lib/wakame/actor/daemon.rb +37 -0
- data/lib/wakame/actor/service_monitor.rb +21 -0
- data/lib/wakame/actor/system.rb +46 -0
- data/lib/wakame/actor.rb +33 -0
- data/lib/wakame/agent.rb +226 -0
- data/lib/wakame/amqp_client.rb +219 -0
- data/lib/wakame/command/action_status.rb +62 -0
- data/lib/wakame/command/actor.rb +23 -0
- data/lib/wakame/command/clone_service.rb +12 -0
- data/lib/wakame/command/launch_cluster.rb +15 -0
- data/lib/wakame/command/migrate_service.rb +21 -0
- data/lib/wakame/command/propagate_service.rb +24 -0
- data/lib/wakame/command/shutdown_cluster.rb +15 -0
- data/lib/wakame/command/status.rb +81 -0
- data/lib/wakame/command.rb +31 -0
- data/lib/wakame/command_queue.rb +44 -0
- data/lib/wakame/configuration.rb +93 -0
- data/lib/wakame/daemonize.rb +96 -0
- data/lib/wakame/event.rb +232 -0
- data/lib/wakame/event_dispatcher.rb +154 -0
- data/lib/wakame/graph.rb +79 -0
- data/lib/wakame/initializer.rb +162 -0
- data/lib/wakame/instance_counter.rb +78 -0
- data/lib/wakame/logger.rb +12 -0
- data/lib/wakame/manager/commands.rb +134 -0
- data/lib/wakame/master.rb +369 -0
- data/lib/wakame/monitor/agent.rb +50 -0
- data/lib/wakame/monitor/service.rb +183 -0
- data/lib/wakame/monitor.rb +69 -0
- data/lib/wakame/packets.rb +160 -0
- data/lib/wakame/queue_declare.rb +14 -0
- data/lib/wakame/rule.rb +116 -0
- data/lib/wakame/rule_engine.rb +202 -0
- data/lib/wakame/runner/administrator_command.rb +112 -0
- data/lib/wakame/runner/agent.rb +81 -0
- data/lib/wakame/runner/master.rb +93 -0
- data/lib/wakame/scheduler.rb +251 -0
- data/lib/wakame/service.rb +914 -0
- data/lib/wakame/template.rb +189 -0
- data/lib/wakame/trigger.rb +66 -0
- data/lib/wakame/triggers/instance_count_update.rb +45 -0
- data/lib/wakame/triggers/load_history.rb +107 -0
- data/lib/wakame/triggers/maintain_ssh_known_hosts.rb +43 -0
- data/lib/wakame/triggers/process_command.rb +34 -0
- data/lib/wakame/triggers/shutdown_unused_vm.rb +16 -0
- data/lib/wakame/util.rb +569 -0
- data/lib/wakame/vm_manipulator.rb +186 -0
- data/lib/wakame.rb +59 -0
- data/tasks/ec2.rake +127 -0
- data/tests/cluster.json +3 -0
- data/tests/conf/a +1 -0
- data/tests/conf/b +1 -0
- data/tests/conf/c +1 -0
- data/tests/setup_agent.rb +39 -0
- data/tests/setup_master.rb +28 -0
- data/tests/test_actor.rb +54 -0
- data/tests/test_agent.rb +218 -0
- data/tests/test_amqp_client.rb +94 -0
- data/tests/test_graph.rb +36 -0
- data/tests/test_master.rb +167 -0
- data/tests/test_monitor.rb +47 -0
- data/tests/test_rule_engine.rb +127 -0
- data/tests/test_scheduler.rb +123 -0
- data/tests/test_service.rb +60 -0
- data/tests/test_template.rb +67 -0
- data/tests/test_uri_amqp.rb +19 -0
- data/tests/test_util.rb +71 -0
- data/wakame_generators/resource/resource_generator.rb +54 -0
- data/wakame_generators/resource/templates/apache_app/apache_app.rb +60 -0
- data/wakame_generators/resource/templates/apache_app/conf/apache2.conf +46 -0
- data/wakame_generators/resource/templates/apache_app/conf/envvars-app +7 -0
- data/wakame_generators/resource/templates/apache_app/conf/sites-app.conf +23 -0
- data/wakame_generators/resource/templates/apache_app/conf/system-app.conf +67 -0
- data/wakame_generators/resource/templates/apache_app/init.d/apache2-app +192 -0
- data/wakame_generators/resource/templates/apache_lb/apache_lb.rb +67 -0
- data/wakame_generators/resource/templates/apache_lb/conf/apache2.conf +46 -0
- data/wakame_generators/resource/templates/apache_lb/conf/envvars-lb +6 -0
- data/wakame_generators/resource/templates/apache_lb/conf/sites-lb.conf +54 -0
- data/wakame_generators/resource/templates/apache_lb/conf/system-lb.conf +75 -0
- data/wakame_generators/resource/templates/apache_lb/init.d/apache2-lb +192 -0
- data/wakame_generators/resource/templates/apache_www/apache_www.rb +56 -0
- data/wakame_generators/resource/templates/apache_www/conf/apache2.conf +47 -0
- data/wakame_generators/resource/templates/apache_www/conf/envvars-www +7 -0
- data/wakame_generators/resource/templates/apache_www/conf/sites-www.conf +23 -0
- data/wakame_generators/resource/templates/apache_www/conf/system-www.conf +63 -0
- data/wakame_generators/resource/templates/apache_www/init.d/apache2-www +192 -0
- data/wakame_generators/resource/templates/ec2_elastic_ip/ec2_elastic_ip.rb +39 -0
- data/wakame_generators/resource/templates/mysql_master/conf/my.cnf +154 -0
- data/wakame_generators/resource/templates/mysql_master/init.d/mysql +185 -0
- data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +119 -0
- metadata +289 -0
@@ -0,0 +1,192 @@
|
|
1
|
+
#!/bin/sh -e
|
2
|
+
|
3
|
+
[ -n $WAKAME_ROOT ] || { echo "WAKAME_ROOT env was not set" >&2; exit 1; }
|
4
|
+
|
5
|
+
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
|
6
|
+
|
7
|
+
SERVER_ROOT="$WAKAME_ROOT/tmp/config/apache_app/conf"
|
8
|
+
INITSCRIPT=`basename $0`
|
9
|
+
DEF=`echo ${INITSCRIPT#apache2-} | tr '[:lower:]' '[:upper:]'`
|
10
|
+
APACHE_ENVVARS="$SERVER_ROOT/envvars-`echo $DEF | tr '[:upper:]' '[:lower:]'`"
|
11
|
+
APACHE_ARGS="-D$DEF -f $SERVER_ROOT/apache2.conf"
|
12
|
+
|
13
|
+
[ $DEF = "APACHE2" ] && { echo "Apache server type is undefined" >&2; exit 1; }
|
14
|
+
|
15
|
+
#[ `ls -1 /etc/apache2/sites-enabled/ | wc -l | sed -e 's/ *//;'` -eq 0 ] && \
|
16
|
+
#echo "You haven't enabled any sites yet, so I'm not starting apache2." && \
|
17
|
+
#echo "To add and enable a host, use addhost and enhost." && exit 0
|
18
|
+
|
19
|
+
#edit /etc/default/apache2 to change this.
|
20
|
+
HTCACHECLEAN_RUN=auto
|
21
|
+
HTCACHECLEAN_MODE=daemon
|
22
|
+
HTCACHECLEAN_SIZE=300M
|
23
|
+
HTCACHECLEAN_DAEMON_INTERVAL=120
|
24
|
+
HTCACHECLEAN_PATH=/var/cache/apache2/mod_disk_cache
|
25
|
+
HTCACHECLEAN_OPTIONS=""
|
26
|
+
|
27
|
+
set -e
|
28
|
+
if [ -x /usr/sbin/apache2 ] ; then
|
29
|
+
HAVE_APACHE2=1
|
30
|
+
else
|
31
|
+
echo "No apache MPM package installed"
|
32
|
+
exit 0
|
33
|
+
fi
|
34
|
+
|
35
|
+
. /lib/lsb/init-functions
|
36
|
+
|
37
|
+
test -f /etc/default/rcS && . /etc/default/rcS
|
38
|
+
#test -f /etc/default/apache2 && . /etc/default/apache2
|
39
|
+
|
40
|
+
APACHE2CTL="$ENV APACHE_ENVVARS=$APACHE_ENVVARS /usr/sbin/apache2ctl $APACHE_ARGS"
|
41
|
+
CONFIG_TEST="$APACHE2CTL -t"
|
42
|
+
HTCACHECLEAN="$ENV /usr/sbin/htcacheclean"
|
43
|
+
|
44
|
+
check_htcacheclean() {
|
45
|
+
[ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1
|
46
|
+
|
47
|
+
[ "$HTCACHECLEAN_RUN" = "yes" ] && return 0
|
48
|
+
|
49
|
+
[ "$HTCACHECLEAN_RUN" = "auto" \
|
50
|
+
-a -e /etc/apache2/mods-enabled/disk_cache.load ] && return 0
|
51
|
+
|
52
|
+
return 1
|
53
|
+
}
|
54
|
+
|
55
|
+
start_htcacheclean() {
|
56
|
+
$HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \
|
57
|
+
-i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
stop_htcacheclean() {
|
62
|
+
killall htcacheclean 2> /dev/null || echo ...not running
|
63
|
+
}
|
64
|
+
|
65
|
+
pidof_apache() {
|
66
|
+
# if pidof is null for some reasons the script exits automagically
|
67
|
+
# classified as good/unknown feature
|
68
|
+
PIDS=`pidof apache2` || true
|
69
|
+
|
70
|
+
PFILE=`. $APACHE_ENVVARS ; echo $APACHE_PID_FILE`
|
71
|
+
if [ -z "$PFILE" ] ; then
|
72
|
+
echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2
|
73
|
+
exit 2
|
74
|
+
fi
|
75
|
+
|
76
|
+
[ -e $PFILE ] && PIDS2=`cat $PFILE`
|
77
|
+
|
78
|
+
# if there is a pid we need to verify that belongs to apache2
|
79
|
+
# for real
|
80
|
+
for i in $PIDS; do
|
81
|
+
if [ "$i" = "$PIDS2" ]; then
|
82
|
+
# in this case the pid stored in the
|
83
|
+
# pidfile matches one of the pidof apache
|
84
|
+
# so a simple kill will make it
|
85
|
+
echo $i
|
86
|
+
return 0
|
87
|
+
fi
|
88
|
+
done
|
89
|
+
return 1
|
90
|
+
}
|
91
|
+
|
92
|
+
apache_stop() {
|
93
|
+
if `$APACHE2CTL -t > /dev/null 2>&1`; then
|
94
|
+
# if the config is ok than we just stop normaly
|
95
|
+
$APACHE2CTL -k graceful-stop
|
96
|
+
else
|
97
|
+
# if we are here something is broken and we need to try
|
98
|
+
# to exit as nice and clean as possible
|
99
|
+
PID=$(pidof_apache)
|
100
|
+
|
101
|
+
if [ "${PID}" ]; then
|
102
|
+
# in this case it is everything nice and dandy
|
103
|
+
# and we kill apache2
|
104
|
+
log_warning_msg "We failed to correctly shutdown apache, so we're now killing all running apache processes. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!"
|
105
|
+
kill $PID
|
106
|
+
elif [ "$(pidof apache2)" ]; then
|
107
|
+
if [ "$VERBOSE" != no ]; then
|
108
|
+
echo " ... failed!"
|
109
|
+
echo "You may still have some apache2 processes running. There are"
|
110
|
+
echo "processes named 'apache2' which do not match your pid file,"
|
111
|
+
echo "and in the name of safety, we've left them alone. Please review"
|
112
|
+
echo "the situation by hand."
|
113
|
+
fi
|
114
|
+
return 1
|
115
|
+
fi
|
116
|
+
fi
|
117
|
+
}
|
118
|
+
|
119
|
+
# Stupid hack to keep lintian happy. (Warrk! Stupidhack!).
|
120
|
+
case $1 in
|
121
|
+
start)
|
122
|
+
log_daemon_msg "Starting web server" "apache2"
|
123
|
+
if $APACHE2CTL -k start; then
|
124
|
+
#if check_htcacheclean ; then
|
125
|
+
# log_progress_msg htcacheclean
|
126
|
+
# start_htcacheclean || log_end_msg 1
|
127
|
+
#fi
|
128
|
+
log_end_msg 0
|
129
|
+
else
|
130
|
+
log_end_msg 1
|
131
|
+
fi
|
132
|
+
;;
|
133
|
+
stop)
|
134
|
+
#if check_htcacheclean ; then
|
135
|
+
# log_daemon_msg "Stopping web server" "htcacheclean"
|
136
|
+
# stop_htcacheclean
|
137
|
+
# log_progress_msg "apache2"
|
138
|
+
#else
|
139
|
+
log_daemon_msg "Stopping web server" "apache2"
|
140
|
+
#fi
|
141
|
+
if apache_stop; then
|
142
|
+
log_end_msg 0
|
143
|
+
else
|
144
|
+
log_end_msg 1
|
145
|
+
fi
|
146
|
+
;;
|
147
|
+
reload | force-reload)
|
148
|
+
if ! $APACHE2CTL -t > /dev/null 2>&1; then
|
149
|
+
$APACHE2CTL -t || true
|
150
|
+
log_end_msg 1
|
151
|
+
exit 1
|
152
|
+
fi
|
153
|
+
log_daemon_msg "Reloading web server config" "apache2"
|
154
|
+
if pidof_apache > /dev/null ; then
|
155
|
+
if $APACHE2CTL -k graceful $2 ; then
|
156
|
+
log_end_msg 0
|
157
|
+
else
|
158
|
+
log_end_msg 1
|
159
|
+
fi
|
160
|
+
fi
|
161
|
+
;;
|
162
|
+
restart)
|
163
|
+
#if check_htcacheclean ; then
|
164
|
+
# log_daemon_msg "Restarting web server" "htcacheclean"
|
165
|
+
# stop_htcacheclean
|
166
|
+
# log_progress_msg apache2
|
167
|
+
#else
|
168
|
+
log_daemon_msg "Restarting web server" "apache2"
|
169
|
+
#fi
|
170
|
+
if ! apache_stop; then
|
171
|
+
log_end_msg 1 || true
|
172
|
+
fi
|
173
|
+
sleep 5
|
174
|
+
if $APACHE2CTL -k start; then
|
175
|
+
#if check_htcacheclean ; then
|
176
|
+
# start_htcacheclean || log_end_msg 1
|
177
|
+
#fi
|
178
|
+
log_end_msg 0
|
179
|
+
else
|
180
|
+
log_end_msg 1
|
181
|
+
fi
|
182
|
+
;;
|
183
|
+
configtest)
|
184
|
+
echo $APACHE2CTL -t -DDUMP_MODULES -DDUMP_VHOSTS
|
185
|
+
$APACHE2CTL -t -DDUMP_MODULES -DDUMP_VHOSTS
|
186
|
+
$APACHE2CTL -l
|
187
|
+
;;
|
188
|
+
*)
|
189
|
+
log_success_msg "Usage: /etc/init.d/$INITSCRIPT {start|stop|restart|reload|force-reload|configtest}"
|
190
|
+
exit 1
|
191
|
+
;;
|
192
|
+
esac
|
@@ -0,0 +1,67 @@
|
|
1
|
+
|
2
|
+
require 'wakame/rule'
|
3
|
+
|
4
|
+
class Apache_LB < Wakame::Service::Resource
|
5
|
+
include WebCluster::HttpLoadBalanceServer
|
6
|
+
include Wakame::Service::ApacheBasicProps
|
7
|
+
|
8
|
+
def_attribute :listen_port, {:default=>80}
|
9
|
+
def_attribute :listen_port_https, {:default=>443}
|
10
|
+
|
11
|
+
def render_config(template)
|
12
|
+
template.cp(%w(conf/envvars-lb init.d/apache2-lb))
|
13
|
+
template.render(%w(conf/system-lb.conf conf/apache2.conf conf/sites-lb.conf))
|
14
|
+
template.chmod("init.d/apache2-lb", 0755)
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_parent_changed(svc, action)
|
18
|
+
Wakame::Rule::BasicActionSet.deploy_configuration(svc)
|
19
|
+
reload(svc, action)
|
20
|
+
end
|
21
|
+
|
22
|
+
def start(svc, action)
|
23
|
+
cond = ConditionalWait.new { |cond|
|
24
|
+
cond.wait_event(Wakame::Event::ServiceOnline) { |event|
|
25
|
+
event.instance_id == svc.instance_id
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
request = action.actor_request(svc.agent.agent_id,
|
30
|
+
'/service_monitor/register', svc.instance_id, :pidfile, '/var/run/apache2-lb.pid').request
|
31
|
+
action.actor_request(svc.agent.agent_id,
|
32
|
+
'/daemon/start', "apache_lb", 'init.d/apache2-lb'){ |req|
|
33
|
+
req.wait
|
34
|
+
Wakame.log.debug("#{self.class} process started")
|
35
|
+
}
|
36
|
+
|
37
|
+
cond.wait
|
38
|
+
end
|
39
|
+
|
40
|
+
def stop(svc, action)
|
41
|
+
cond = ConditionalWait.new { |cond|
|
42
|
+
cond.wait_event(Wakame::Event::ServiceOffline) { |event|
|
43
|
+
event.instance_id == svc.instance_id
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
action.actor_request(svc.agent.agent_id,
|
48
|
+
'/daemon/stop', 'apache_lb', 'init.d/apache2-lb'){ |req|
|
49
|
+
req.wait
|
50
|
+
Wakame.log.debug("#{self.class} process stopped")
|
51
|
+
}
|
52
|
+
|
53
|
+
cond.wait
|
54
|
+
|
55
|
+
request = action.actor_request(svc.agent.agent_id,
|
56
|
+
'/service_monitor/unregister', svc.instance_id ).request
|
57
|
+
end
|
58
|
+
|
59
|
+
def reload(svc, action)
|
60
|
+
action.actor_request(svc.agent.agent_id,
|
61
|
+
'/daemon/reload', "apache_lb", 'init.d/apache2-lb'){ |req|
|
62
|
+
req.wait
|
63
|
+
Wakame.log.debug("#{self.class} process stopped")
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#ServerRoot "/etc/apache2"
|
2
|
+
#ServerRoot "/home/wakame/config/apache2"
|
3
|
+
ServerRoot "<%= agent.root_path %>/tmp/config/apache_lb/conf"
|
4
|
+
|
5
|
+
LockFile /var/lock/apache2/accept.lock
|
6
|
+
PidFile ${APACHE_PID_FILE}
|
7
|
+
|
8
|
+
User ${APACHE_RUN_USER}
|
9
|
+
Group ${APACHE_RUN_GROUP}
|
10
|
+
|
11
|
+
Include ${SYSTEM_INCLUDE_FILE}
|
12
|
+
|
13
|
+
LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
|
14
|
+
<IfModule mod_mime.c>
|
15
|
+
TypesConfig /etc/mime.types
|
16
|
+
|
17
|
+
AddType application/x-compress .Z
|
18
|
+
AddType application/x-gzip .gz .tgz
|
19
|
+
AddType application/x-bzip2 .bz2
|
20
|
+
</IfModule>
|
21
|
+
|
22
|
+
AccessFileName .htaccess
|
23
|
+
<Files ~ "^\.ht">
|
24
|
+
Order allow,deny
|
25
|
+
Deny from all
|
26
|
+
</Files>
|
27
|
+
|
28
|
+
ErrorLog ${APACHE_ERROR_LOG_FILE}
|
29
|
+
|
30
|
+
ServerTokens Full
|
31
|
+
ServerSignature On
|
32
|
+
|
33
|
+
#
|
34
|
+
# The following directives define some format nicknames for use with
|
35
|
+
# a CustomLog directive (see below).
|
36
|
+
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
|
37
|
+
#
|
38
|
+
<IfModule mod_log_config.c>
|
39
|
+
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
|
40
|
+
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined_proxy
|
41
|
+
LogFormat "%h %l %u %t \"%r\" %>s %b" common
|
42
|
+
LogFormat "%{Referer}i -> %U" referer
|
43
|
+
LogFormat "%{User-agent}i" agent
|
44
|
+
</IfModule>
|
45
|
+
|
46
|
+
Include ${SITES_INCLUDE_FILE}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
NameVirtualHost *:<%= property.listen_port %>
|
2
|
+
|
3
|
+
# Wild Card Virtual Host
|
4
|
+
#<VirtualHost *:<%= property.listen_port %>>
|
5
|
+
#DocumentRoot /var/www/
|
6
|
+
#
|
7
|
+
#LogLevel warn
|
8
|
+
#CustomLog /var/log/apache2/access-lb.log combined
|
9
|
+
#ErrorLog /var/log/apache2/error-lb.log
|
10
|
+
#
|
11
|
+
#</VirtualHost>
|
12
|
+
|
13
|
+
<%- service_cluster.virtual_hosts.each { |vh| -%>
|
14
|
+
<VirtualHost *:<%= property.listen_port %>>
|
15
|
+
ServerName <%= vh.server_name %>
|
16
|
+
DocumentRoot /var/www/
|
17
|
+
|
18
|
+
LogLevel warn
|
19
|
+
CustomLog /var/log/apache2/<%= vh.server_name %>-access.log combined
|
20
|
+
ErrorLog /var/log/apache2/<%= vh.server_name %>-error.log
|
21
|
+
|
22
|
+
<Location /balancer-manager>
|
23
|
+
SetHandler balancer-manager
|
24
|
+
# Order deny,allow
|
25
|
+
# Deny from all
|
26
|
+
# Allow from 127.0.0.1 localhost.localdomain localhost ip6-localhost
|
27
|
+
</Location>
|
28
|
+
|
29
|
+
<Proxy balancer://cluster-www>
|
30
|
+
<%- service_cluster.each_www { |n|
|
31
|
+
next if n.status != STATUS_ONLINE
|
32
|
+
-%>
|
33
|
+
BalancerMember http://<%= n.agent.agent_ip %>:<%= n.property.listen_port %> loadfactor=10
|
34
|
+
<%- } -%>
|
35
|
+
</Proxy>
|
36
|
+
<Proxy balancer://cluster-app>
|
37
|
+
<%- service_cluster.each_app { |n|
|
38
|
+
next if n.status != STATUS_ONLINE
|
39
|
+
-%>
|
40
|
+
BalancerMember http://<%= n.agent.agent_ip %>:<%= n.property.listen_port %> loadfactor=10
|
41
|
+
<%- } -%>
|
42
|
+
</Proxy>
|
43
|
+
ProxyRequests Off
|
44
|
+
ProxyPreserveHost On
|
45
|
+
ProxyPassReverse / balancer://cluster-www/
|
46
|
+
ProxyPassReverse / balancer://cluster-app/
|
47
|
+
|
48
|
+
ProxyPassMatch ^(/(images|image|imgs|img|javascripts|javascript|js|stylesheets|css)/.*)$ balancer://cluster-www$1 lbmethod=byrequests timeout=10
|
49
|
+
ProxyPassMatch ^(/.*\.(htm|html|ico|jpg|jpeg|png|gif|swf|txt))$ balancer://cluster-www$1 lbmethod=byrequests timeout=10
|
50
|
+
ProxyPassMatch ^/balancer-manager.* !
|
51
|
+
ProxyPass / balancer://cluster-app/ lbmethod=byrequests timeout=10
|
52
|
+
|
53
|
+
</VirtualHost>
|
54
|
+
<%- } -%>
|
@@ -0,0 +1,75 @@
|
|
1
|
+
Timeout 300
|
2
|
+
KeepAlive On
|
3
|
+
MaxKeepAliveRequests 100
|
4
|
+
KeepAliveTimeout 15
|
5
|
+
|
6
|
+
<IfModule mpm_prefork_module>
|
7
|
+
StartServers 5
|
8
|
+
MinSpareServers 5
|
9
|
+
MaxSpareServers 10
|
10
|
+
MaxClients 150
|
11
|
+
MaxRequestsPerChild 0
|
12
|
+
</IfModule>
|
13
|
+
|
14
|
+
<IfModule mpm_worker_module>
|
15
|
+
StartServers 2
|
16
|
+
MaxClients 150
|
17
|
+
MinSpareThreads 25
|
18
|
+
MaxSpareThreads 75
|
19
|
+
ThreadsPerChild 25
|
20
|
+
MaxRequestsPerChild 0
|
21
|
+
</IfModule>
|
22
|
+
|
23
|
+
|
24
|
+
LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
|
25
|
+
LoadModule auth_basic_module /usr/lib/apache2/modules/mod_auth_basic.so
|
26
|
+
LoadModule authn_file_module /usr/lib/apache2/modules/mod_authn_file.so
|
27
|
+
LoadModule authz_default_module /usr/lib/apache2/modules/mod_authz_default.so
|
28
|
+
LoadModule authz_groupfile_module /usr/lib/apache2/modules/mod_authz_groupfile.so
|
29
|
+
LoadModule authz_host_module /usr/lib/apache2/modules/mod_authz_host.so
|
30
|
+
LoadModule authz_user_module /usr/lib/apache2/modules/mod_authz_user.so
|
31
|
+
LoadModule env_module /usr/lib/apache2/modules/mod_env.so
|
32
|
+
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
|
33
|
+
LoadModule setenvif_module /usr/lib/apache2/modules/mod_setenvif.so
|
34
|
+
LoadModule status_module /usr/lib/apache2/modules/mod_status.so
|
35
|
+
LoadModule info_module /usr/lib/apache2/modules/mod_info.so
|
36
|
+
|
37
|
+
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
|
38
|
+
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
|
39
|
+
LoadModule proxy_balancer_module /usr/lib/apache2/modules/mod_proxy_balancer.so
|
40
|
+
|
41
|
+
|
42
|
+
### Port configuration
|
43
|
+
Listen <%= property.listen_port %>
|
44
|
+
|
45
|
+
<IfModule mod_ssl.c>
|
46
|
+
Listen <%= property.listen_port_https %>
|
47
|
+
</IfModule>
|
48
|
+
|
49
|
+
|
50
|
+
<IfModule mod_status.c>
|
51
|
+
<Location /server-status>
|
52
|
+
SetHandler server-status
|
53
|
+
# Order deny,allow
|
54
|
+
# Deny from all
|
55
|
+
# Allow from 127.0.0.1 localhost.localdomain localhost ip6-localhost
|
56
|
+
</Location>
|
57
|
+
</IfModule>
|
58
|
+
|
59
|
+
<IfModule mod_info.c>
|
60
|
+
<Location /server-info>
|
61
|
+
SetHandler server-info
|
62
|
+
# Order deny,allow
|
63
|
+
# Deny from all
|
64
|
+
# Allow from 127.0.0.1 localhost.localdomain localhost ip6-localhost
|
65
|
+
</Location>
|
66
|
+
</IfModule>
|
67
|
+
|
68
|
+
#<IfModule mod_proxy_balancer.c>
|
69
|
+
#<Location /balancer-manager>
|
70
|
+
# SetHandler balancer-manager
|
71
|
+
# Order deny,allow
|
72
|
+
# Deny from all
|
73
|
+
# Allow from 127.0.0.1 localhost.localdomain localhost ip6-localhost
|
74
|
+
#</Location>
|
75
|
+
#</IfModule>
|
@@ -0,0 +1,192 @@
|
|
1
|
+
#!/bin/sh -e
|
2
|
+
|
3
|
+
[ -n $WAKAME_ROOT ] || { echo "WAKAME_ROOT env was not set" >&2; exit 1; }
|
4
|
+
|
5
|
+
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
|
6
|
+
|
7
|
+
SERVER_ROOT="$WAKAME_ROOT/tmp/config/apache_lb/conf"
|
8
|
+
INITSCRIPT=`basename $0`
|
9
|
+
DEF=`echo ${INITSCRIPT#apache2-} | tr '[:lower:]' '[:upper:]'`
|
10
|
+
APACHE_ENVVARS="$SERVER_ROOT/envvars-`echo $DEF | tr '[:upper:]' '[:lower:]'`"
|
11
|
+
APACHE_ARGS="-D$DEF -f $SERVER_ROOT/apache2.conf"
|
12
|
+
|
13
|
+
[ $DEF = "APACHE2" ] && { echo "Apache server type is undefined" >&2; exit 1; }
|
14
|
+
|
15
|
+
#[ `ls -1 /etc/apache2/sites-enabled/ | wc -l | sed -e 's/ *//;'` -eq 0 ] && \
|
16
|
+
#echo "You haven't enabled any sites yet, so I'm not starting apache2." && \
|
17
|
+
#echo "To add and enable a host, use addhost and enhost." && exit 0
|
18
|
+
|
19
|
+
#edit /etc/default/apache2 to change this.
|
20
|
+
HTCACHECLEAN_RUN=auto
|
21
|
+
HTCACHECLEAN_MODE=daemon
|
22
|
+
HTCACHECLEAN_SIZE=300M
|
23
|
+
HTCACHECLEAN_DAEMON_INTERVAL=120
|
24
|
+
HTCACHECLEAN_PATH=/var/cache/apache2/mod_disk_cache
|
25
|
+
HTCACHECLEAN_OPTIONS=""
|
26
|
+
|
27
|
+
set -e
|
28
|
+
if [ -x /usr/sbin/apache2 ] ; then
|
29
|
+
HAVE_APACHE2=1
|
30
|
+
else
|
31
|
+
echo "No apache MPM package installed"
|
32
|
+
exit 0
|
33
|
+
fi
|
34
|
+
|
35
|
+
. /lib/lsb/init-functions
|
36
|
+
|
37
|
+
test -f /etc/default/rcS && . /etc/default/rcS
|
38
|
+
#test -f /etc/default/apache2 && . /etc/default/apache2
|
39
|
+
|
40
|
+
APACHE2CTL="$ENV APACHE_ENVVARS=$APACHE_ENVVARS /usr/sbin/apache2ctl $APACHE_ARGS"
|
41
|
+
CONFIG_TEST="$APACHE2CTL -t"
|
42
|
+
HTCACHECLEAN="$ENV /usr/sbin/htcacheclean"
|
43
|
+
|
44
|
+
check_htcacheclean() {
|
45
|
+
[ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1
|
46
|
+
|
47
|
+
[ "$HTCACHECLEAN_RUN" = "yes" ] && return 0
|
48
|
+
|
49
|
+
[ "$HTCACHECLEAN_RUN" = "auto" \
|
50
|
+
-a -e /etc/apache2/mods-enabled/disk_cache.load ] && return 0
|
51
|
+
|
52
|
+
return 1
|
53
|
+
}
|
54
|
+
|
55
|
+
start_htcacheclean() {
|
56
|
+
$HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \
|
57
|
+
-i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
stop_htcacheclean() {
|
62
|
+
killall htcacheclean 2> /dev/null || echo ...not running
|
63
|
+
}
|
64
|
+
|
65
|
+
pidof_apache() {
|
66
|
+
# if pidof is null for some reasons the script exits automagically
|
67
|
+
# classified as good/unknown feature
|
68
|
+
PIDS=`pidof apache2` || true
|
69
|
+
|
70
|
+
PFILE=`. $APACHE_ENVVARS ; echo $APACHE_PID_FILE`
|
71
|
+
if [ -z "$PFILE" ] ; then
|
72
|
+
echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2
|
73
|
+
exit 2
|
74
|
+
fi
|
75
|
+
|
76
|
+
[ -e $PFILE ] && PIDS2=`cat $PFILE`
|
77
|
+
|
78
|
+
# if there is a pid we need to verify that belongs to apache2
|
79
|
+
# for real
|
80
|
+
for i in $PIDS; do
|
81
|
+
if [ "$i" = "$PIDS2" ]; then
|
82
|
+
# in this case the pid stored in the
|
83
|
+
# pidfile matches one of the pidof apache
|
84
|
+
# so a simple kill will make it
|
85
|
+
echo $i
|
86
|
+
return 0
|
87
|
+
fi
|
88
|
+
done
|
89
|
+
return 1
|
90
|
+
}
|
91
|
+
|
92
|
+
apache_stop() {
|
93
|
+
if `$APACHE2CTL -t > /dev/null 2>&1`; then
|
94
|
+
# if the config is ok than we just stop normaly
|
95
|
+
$APACHE2CTL -k graceful-stop
|
96
|
+
else
|
97
|
+
# if we are here something is broken and we need to try
|
98
|
+
# to exit as nice and clean as possible
|
99
|
+
PID=$(pidof_apache)
|
100
|
+
|
101
|
+
if [ "${PID}" ]; then
|
102
|
+
# in this case it is everything nice and dandy
|
103
|
+
# and we kill apache2
|
104
|
+
log_warning_msg "We failed to correctly shutdown apache, so we're now killing all running apache processes. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!"
|
105
|
+
kill $PID
|
106
|
+
elif [ "$(pidof apache2)" ]; then
|
107
|
+
if [ "$VERBOSE" != no ]; then
|
108
|
+
echo " ... failed!"
|
109
|
+
echo "You may still have some apache2 processes running. There are"
|
110
|
+
echo "processes named 'apache2' which do not match your pid file,"
|
111
|
+
echo "and in the name of safety, we've left them alone. Please review"
|
112
|
+
echo "the situation by hand."
|
113
|
+
fi
|
114
|
+
return 1
|
115
|
+
fi
|
116
|
+
fi
|
117
|
+
}
|
118
|
+
|
119
|
+
# Stupid hack to keep lintian happy. (Warrk! Stupidhack!).
|
120
|
+
case $1 in
|
121
|
+
start)
|
122
|
+
log_daemon_msg "Starting web server" "apache2"
|
123
|
+
if $APACHE2CTL -k start; then
|
124
|
+
#if check_htcacheclean ; then
|
125
|
+
# log_progress_msg htcacheclean
|
126
|
+
# start_htcacheclean || log_end_msg 1
|
127
|
+
#fi
|
128
|
+
log_end_msg 0
|
129
|
+
else
|
130
|
+
log_end_msg 1
|
131
|
+
fi
|
132
|
+
;;
|
133
|
+
stop)
|
134
|
+
#if check_htcacheclean ; then
|
135
|
+
# log_daemon_msg "Stopping web server" "htcacheclean"
|
136
|
+
# stop_htcacheclean
|
137
|
+
# log_progress_msg "apache2"
|
138
|
+
#else
|
139
|
+
log_daemon_msg "Stopping web server" "apache2"
|
140
|
+
#fi
|
141
|
+
if apache_stop; then
|
142
|
+
log_end_msg 0
|
143
|
+
else
|
144
|
+
log_end_msg 1
|
145
|
+
fi
|
146
|
+
;;
|
147
|
+
reload | force-reload)
|
148
|
+
if ! $APACHE2CTL -t > /dev/null 2>&1; then
|
149
|
+
$APACHE2CTL -t || true
|
150
|
+
log_end_msg 1
|
151
|
+
exit 1
|
152
|
+
fi
|
153
|
+
log_daemon_msg "Reloading web server config" "apache2"
|
154
|
+
if pidof_apache > /dev/null ; then
|
155
|
+
if $APACHE2CTL -k graceful $2 ; then
|
156
|
+
log_end_msg 0
|
157
|
+
else
|
158
|
+
log_end_msg 1
|
159
|
+
fi
|
160
|
+
fi
|
161
|
+
;;
|
162
|
+
restart)
|
163
|
+
#if check_htcacheclean ; then
|
164
|
+
# log_daemon_msg "Restarting web server" "htcacheclean"
|
165
|
+
# stop_htcacheclean
|
166
|
+
# log_progress_msg apache2
|
167
|
+
#else
|
168
|
+
log_daemon_msg "Restarting web server" "apache2"
|
169
|
+
#fi
|
170
|
+
if ! apache_stop; then
|
171
|
+
log_end_msg 1 || true
|
172
|
+
fi
|
173
|
+
sleep 5
|
174
|
+
if $APACHE2CTL -k start; then
|
175
|
+
#if check_htcacheclean ; then
|
176
|
+
# start_htcacheclean || log_end_msg 1
|
177
|
+
#fi
|
178
|
+
log_end_msg 0
|
179
|
+
else
|
180
|
+
log_end_msg 1
|
181
|
+
fi
|
182
|
+
;;
|
183
|
+
configtest)
|
184
|
+
echo $APACHE2CTL -t -DDUMP_MODULES -DDUMP_VHOSTS
|
185
|
+
$APACHE2CTL -t -DDUMP_MODULES -DDUMP_VHOSTS
|
186
|
+
$APACHE2CTL -l
|
187
|
+
;;
|
188
|
+
*)
|
189
|
+
log_success_msg "Usage: /etc/init.d/$INITSCRIPT {start|stop|restart|reload|force-reload|configtest}"
|
190
|
+
exit 1
|
191
|
+
;;
|
192
|
+
esac
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Apache_WWW < Wakame::Service::Resource
|
2
|
+
include Wakame::Service::ApacheBasicProps
|
3
|
+
include WebCluster::HttpAssetServer
|
4
|
+
|
5
|
+
def_attribute :listen_port, {:default=>8000}
|
6
|
+
def_attribute :max_instances, {:default=>5}
|
7
|
+
|
8
|
+
def render_config(template)
|
9
|
+
template.cp(%w(conf/envvars-www init.d/apache2-www))
|
10
|
+
template.render(%w(conf/system-www.conf conf/sites-www.conf conf/apache2.conf))
|
11
|
+
template.chmod("init.d/apache2-www", 0755)
|
12
|
+
end
|
13
|
+
|
14
|
+
def start(svc, action)
|
15
|
+
cond = ConditionalWait.new { |cond|
|
16
|
+
cond.wait_event(Wakame::Event::ServiceOnline) { |event|
|
17
|
+
event.instance_id == svc.instance_id
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
request = action.actor_request(svc.agent.agent_id,
|
22
|
+
'/service_monitor/register', svc.instance_id, :pidfile, '/var/run/apache2-www.pid').request
|
23
|
+
request = action.actor_request(svc.agent.agent_id,
|
24
|
+
'/daemon/start', "apache_www", 'init.d/apache2-www'){ |req|
|
25
|
+
req.wait
|
26
|
+
Wakame.log.debug("#{self.class} process started")
|
27
|
+
}
|
28
|
+
cond.wait
|
29
|
+
end
|
30
|
+
|
31
|
+
def stop(svc, action)
|
32
|
+
cond = ConditionalWait.new { |cond|
|
33
|
+
cond.wait_event(Wakame::Event::ServiceOffline) { |event|
|
34
|
+
event.instance_id == svc.instance_id
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
request = action.actor_request(svc.agent.agent_id,
|
39
|
+
'/daemon/stop', 'apache_www', 'init.d/apache2-www'){ |req|
|
40
|
+
req.wait
|
41
|
+
Wakame.log.debug("#{self.class} process stooped")
|
42
|
+
}
|
43
|
+
cond.wait
|
44
|
+
|
45
|
+
request = action.actor_request(svc.agent.agent_id,
|
46
|
+
'/service_monitor/unregister', svc.instance_id ).request
|
47
|
+
end
|
48
|
+
|
49
|
+
def reload(svc, action)
|
50
|
+
action.actor_request('/daemon/reload', 'apache_www', 'init.d/apache2-www') { |req|
|
51
|
+
req.wait
|
52
|
+
Wakame.log.debug("#{self.class} process reloaded")
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|