-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2-initialize.txt
89 lines (66 loc) · 1.57 KB
/
ec2-initialize.txt
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
#!/bin/sh
%DO_NOT_EDIT_WARNING%
# must.have.root!
if test $(id -u) != 0 ; then
exec sudo /bin/sh $0
fi
PACKAGES=$(tr '\n' ' ' <<EOS)
%PACKAGES%
EOS
apt-get -y update
apt-get -y upgrade
apt-get install -y $PACKAGES
# work around somebody's idea of a bad joke.
rm -f /etc/parallel/config
HOME=/home/ubuntu
USER=ubuntu
cd $HOME
git clone https://github.com/gyepisam/fcc-textify
#Worker key
install -D -m 0600 /dev/stdin fcc-textify/auth <<EOS
%AUTH%
EOS
mode=%MODE%
install -D -m 0600 /dev/stdin fcc-textify/config/${mode}.ini <<EOS
[default]
injector-queue = extraction-job-$mode
collector-queue = extraction-data-$mode
text-bucket = ppi-extraction-text-$mode
image-bucket = ppi-extraction-image-$mode
[aws]
region = us-east-1
EOS
cat > /etc/rsyslog.d/60-udp-logging.conf <<'EOS'
$ModLoad imudp
$UDPServerAddress 127.0.0.1
$UDPServerRun 514
EOS
reload rsyslog
# run N sets of processors
for j in %CONCURRENCY%; do
runitdir=textify-${j}
install -D -m 0755 /dev/stdin $runitdir/run <<EOS
#!/bin/sh
authfile=$HOME/fcc-textify/auth
exec 2>&1
exec chpst env \
RAILS_ENV=production \
SHELL=/bin/sh \
HOME=$HOME \
AWS_ACCESS_KEY_ID="\$(sed -n 1p \$authfile)" \
AWS_SECRET_ACCESS_KEY="\$(sed -n 2p \$authfile)" \
python $HOME/fcc-textify/task.py extract_batch
EOS
#consolidate logs to syslog
logdir=$HOME/logs-$j
SPACE=' '
install -D -m 0755 /dev/stdin $logdir/config <<EOS
ptextify-${j}:$SPACE
U127.0.0.1
EOS
install -D -m 0755 /dev/stdin $runitdir/log/run <<EOS
#!/bin/sh
exec svlogd $logdir
EOS
ln -s $PWD/$runitdir /etc/service/textify-$j
done