forked from steemit/steem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startpaassteemd.sh
167 lines (147 loc) · 5.19 KB
/
startpaassteemd.sh
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
#!/bin/bash
VERSION=`cat /etc/steemdversion`
if [[ "$IS_BROADCAST_NODE" ]]; then
STEEMD="/usr/local/steemd-default/bin/steemd"
elif [[ "$IS_AH_NODE" ]]; then
STEEMD="/usr/local/steemd-default/bin/steemd"
else
STEEMD="/usr/local/steemd-full/bin/steemd"
fi
chown -R steemd:steemd $HOME
# clean out data dir since it may be semi-persistent block storage on the ec2 with stale data
rm -rf $HOME/*
ARGS=""
# if user did pass in desired seed nodes, use
# the ones the user specified:
if [[ ! -z "$STEEMD_SEED_NODES" ]]; then
for NODE in $STEEMD_SEED_NODES ; do
ARGS+=" --p2p-seed-node=$NODE"
done
fi
NOW=`date +%s`
STEEMD_FEED_START_TIME=`expr $NOW - 1209600`
ARGS+=" --follow-start-feeds=$STEEMD_FEED_START_TIME"
STEEMD_PROMOTED_START_TIME=`expr $NOW - 604800`
ARGS+=" --tags-start-promoted=$STEEMD_PROMOTED_START_TIME"
if [[ ! "$DISABLE_BLOCK_API" ]]; then
ARGS+=" --plugin=block_api"
fi
# overwrite local config with image one
if [[ "$IS_BROADCAST_NODE" ]]; then
cp /etc/steemd/config-for-broadcaster.ini $HOME/config.ini
elif [[ "$IS_AH_NODE" ]]; then
cp /etc/steemd/config-for-ahnode.ini $HOME/config.ini
elif [[ "$IS_OPSWHITELIST_NODE" ]]; then
cp /etc/steemd/fullnode.opswhitelist.config.ini $HOME/config.ini
else
cp /etc/steemd/fullnode.config.ini $HOME/config.ini
fi
chown steemd:steemd $HOME/config.ini
cd $HOME
mv /etc/nginx/nginx.conf /etc/nginx/nginx.original.conf
cp /etc/nginx/steemd.nginx.conf /etc/nginx/nginx.conf
# get blockchain state from an S3 bucket
echo steemd: beginning download and decompress of s3://$S3_BUCKET/blockchain-$VERSION-latest.tar.lz4
finished=0
count=1
if [[ "$USE_RAMDISK" ]]; then
mkdir -p /mnt/ramdisk
mount -t ramfs -o size=${RAMDISK_SIZE_IN_MB:-51200}m ramfs /mnt/ramdisk
ARGS+=" --shared-file-dir=/mnt/ramdisk/blockchain"
# try five times to pull in shared memory file
while [[ $count -le 5 ]] && [[ $finished == 0 ]]
do
rm -rf $HOME/blockchain/*
rm -rf /mnt/ramdisk/blockchain/*
if [[ "$IS_BROADCAST_NODE" ]]; then
aws s3 cp s3://$S3_BUCKET/broadcast-$VERSION-latest.tar.lz4 - | lz4 -d | tar x --wildcards 'blockchain/block*' -C /mnt/ramdisk 'blockchain/shared*'
elif [[ "$IS_AH_NODE" ]]; then
aws s3 cp s3://$S3_BUCKET/ahnode-$VERSION-latest.tar.lz4 - | lz4 -d | tar x --wildcards 'blockchain/block*' 'blockchain/*rocksdb-storage*' -C /mnt/ramdisk 'blockchain/shared*'
else
aws s3 cp s3://$S3_BUCKET/blockchain-$VERSION-latest.tar.lz4 - | lz4 -d | tar x --wildcards 'blockchain/block*' -C /mnt/ramdisk 'blockchain/shared*'
fi
if [[ $? -ne 0 ]]; then
sleep 1
echo notifyalert steemd: unable to pull blockchain state from S3 - attempt $count
(( count++ ))
else
finished=1
fi
done
chown -R steemd:steemd /mnt/ramdisk/blockchain
else
while [[ $count -le 5 ]] && [[ $finished == 0 ]]
do
rm -rf $HOME/blockchain/*
if [[ "$IS_BROADCAST_NODE" ]]; then
aws s3 cp s3://$S3_BUCKET/broadcast-$VERSION-latest.tar.lz4 - | lz4 -d | tar x
elif [[ "$IS_AH_NODE" ]]; then
aws s3 cp s3://$S3_BUCKET/ahnode-$VERSION-latest.tar.lz4 - | lz4 -d | tar x
else
aws s3 cp s3://$S3_BUCKET/blockchain-$VERSION-latest.tar.lz4 - | lz4 -d | tar x
fi
if [[ $? -ne 0 ]]; then
sleep 1
echo notifyalert steemd: unable to pull blockchain state from S3 - attempt $count
(( count++ ))
else
finished=1
fi
done
fi
if [[ $finished == 0 ]]; then
if [[ ! "$SYNC_TO_S3" ]]; then
echo notifyalert steemd: unable to pull blockchain state from S3 - exiting
exit 1
else
echo notifysteemdsync steemdsync: shared memory file for $VERSION not found, creating a new one by replaying the blockchain
if [[ "$USE_RAMDISK" ]]; then
mkdir -p /mnt/ramdisk/blockchain
chown -R steemd:steemd /mnt/ramdisk/blockchain
else
mkdir blockchain
fi
aws s3 cp s3://$S3_BUCKET/block_log-latest blockchain/block_log
if [[ $? -ne 0 ]]; then
echo notifysteemdsync steemdsync: unable to pull latest block_log from S3, will sync from scratch.
else
ARGS+=" --replay-blockchain --force-validate"
fi
touch /tmp/isnewsync
fi
fi
# for appbase tags plugin loading
ARGS+=" --tags-skip-startup-update"
cd $HOME
if [[ "$SYNC_TO_S3" ]]; then
touch /tmp/issyncnode
chown www-data:www-data /tmp/issyncnode
fi
chown -R steemd:steemd $HOME/*
# let's get going
cp /etc/nginx/healthcheck.conf.template /etc/nginx/healthcheck.conf
echo server 127.0.0.1:8091\; >> /etc/nginx/healthcheck.conf
echo } >> /etc/nginx/healthcheck.conf
rm /etc/nginx/sites-enabled/default
cp /etc/nginx/healthcheck.conf /etc/nginx/sites-enabled/default
/etc/init.d/fcgiwrap restart
service nginx restart
exec chpst -usteemd \
$STEEMD \
--webserver-ws-endpoint=127.0.0.1:8091 \
--webserver-http-endpoint=127.0.0.1:8091 \
--p2p-endpoint=0.0.0.0:2001 \
--data-dir=$HOME \
$ARGS \
$STEEMD_EXTRA_OPTS \
2>&1&
SAVED_PID=`pgrep -f p2p-endpoint`
echo $SAVED_PID >> /tmp/steemdpid
mkdir -p /etc/service/steemd
if [[ ! "$SYNC_TO_S3" ]]; then
cp /usr/local/bin/paas-sv-run.sh /etc/service/steemd/run
else
cp /usr/local/bin/sync-sv-run.sh /etc/service/steemd/run
fi
chmod +x /etc/service/steemd/run
runsv /etc/service/steemd