production
2.09 KB
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
#!/bin/sh
set -e
if [ -e /etc/default/noosfero ]; then
. /etc/default/noosfero
fi
export RAILS_ENV=production
ACTION="$1"
if [ -z "$ACTION" ]; then
echo "usage: $0 start|stop|restart|run"
exit 1
fi
clear_cache() {
if test -w ./public; then
echo "Cleaning cache files"
rm -rf ./public/javascripts/cache*
rm -rf ./public/stylesheets/cache*
elif [ ! -z "$NOOSFERO_DATA_DIR" ] && [ -w "$NOOSFERO_DATA_DIR" ]; then
echo "Cleaning cache files"
rm -rf "$NOOSFERO_DATA_DIR"/cache/*
fi
}
do_start() {
rake db:migrate SCHEMA=/dev/null
clear_cache
environments_loop start
ruby -S thin -C config/thin.yml start
}
do_stop() {
# During Debian upgrades, it is possible that rails is not available (e.g.
# Lenny -> Squeeze), so the programs below might fail. If they do, we fall
# back to stopping the daemons by manually reading their PID files, killing
# them and wiping the PID files.
ruby -S thin -C config/thin.yml stop ||
stop_via_pid_file tmp/pids/thin.*.pid
environments_loop stop ||
stop_via_pid_file tmp/pids/delayed_job.pid tmp/pids/delayed_job.*.pid tmp/pids/feed-updater.*.pid
}
stop_via_pid_file() {
for pidfile in $@; do
if [ -e "$pidfile" ]; then
pid=$(cat $pidfile)
echo "Sentign TERM signal to stop $pid ..."
kill -TERM "$pid"
rm -f $pidfile
fi
done
}
environments_loop() {
action="$1"
environments=$(find ./config/environments -name *_$RAILS_ENV.rb)
if [ "$environments" ]; then
for environment in $environments; do
env=$(basename $environment | cut -d. -f1)
RAILS_ENV=$env ./script/delayed_job -i $env "$action"
RAILS_ENV=$env ./script/feed-updater "$action" -i $env
done
else
./script/delayed_job "$action"
./script/feed-updater "$action"
fi
}
case "$ACTION" in
start|stop)
do_$ACTION
;;
run)
do_start
echo "=> Running in production mode. Hit ctrl-C to stop."
trap do_stop INT TERM
tail -n 0 -f log/production.log || true
;;
restart)
do_stop
sleep 1
do_start
;;
*)
echo "usage: $0 start|stop|restart|run"
exit 1
;;
esac