-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
184 lines (125 loc) · 7.32 KB
/
entrypoint.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
chmod 600 -R /etc/ssh/
export CARDANO_NODE_SOCKET_PATH='/cardano/ipc/node.socket'
touch /var/log/cron.log
touch /var/log/sshd.log
touch /var/log/socat.log
echo "$ROOT_SSH_KEY" >> /root/.ssh/authorized_keys
echo "$ROOT_SSH_KEY" >> /home/admin/.ssh/authorized_keys
echo "$ADMIN_SSH_KEY" >> /home/admin/.ssh/authorized_keys
cat /home/admin/.ssh/authorized_keys
cat /root/.ssh/authorized_keys
echo "*/5 * * * * source /root/.bash_profile && chmod 777 $CARDANO_NODE_SOCKET_PATH &>>/var/log/cron.log" > /var/spool/cron/root
if [[ $AWS_SYNC_ENABLED == 'true' ]]; then
echo "export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> /root/.bash_profile
echo "export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> /root/.bash_profile
echo "export AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION" >> /root/.bash_profile
echo "export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> /home/admin/.bash_profile
echo "export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> /home/admin/.bash_profile
echo "export AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION" >> /home/admin/.bash_profile
if [[ ! $ONLY_DB_SYNC == 'true' ]]; then
if [[ $EFS_ENABLED == 'true' ]]; then
if [[ $TESTNET_ENABLED == 'true' ]]; then
mkdir /cardano/db/$HOSTNAME/
cp -R /cardano/db/testnet/* /cardano/db/$HOSTNAME/
sed -i "s^/cardano/db^/cardano/db/$HOSTNAME^g" /cardano/scripts/.env
echo "export TESTNET_ENABLED=true" >> /root/.bash_profile
echo "export TESTNET_ENABLED=true" >> /home/admin/.bash_profile
else
mkdir /cardano/db/$HOSTNAME/
cp -R /cardano/db/source/* /cardano/db/$HOSTNAME/
sed -i "s^/cardano/db^/cardano/db/$HOSTNAME^g" /cardano/scripts/.env
fi
else
if [[ ! $REMOTE_URL_SYNC == 'true' ]]; then
if [[ $TESTNET_ENABLED == 'true' ]]; then
aws s3 sync s3://$DB_BUCKET_NAME/testnet/ /cardano/db/
else
aws s3 sync s3://$DB_BUCKET_NAME/ /cardano/db/
fi
fi
fi
fi
echo "#0 */1 * * * source /root/.bash_profile && aws s3 sync s3://$WALLET_BUCKET_NAME/$HOSTNAME/ /home/admin/.cardobot/wallets/ &>>/var/log/cron.log" >> /var/spool/cron/root
echo "15 */1 * * * source /root/.bash_profile && aws s3 sync /home/admin/.cardobot/wallets/ s3://$WALLET_BUCKET_NAME/$HOSTNAME/ &>>/var/log/cron.log" >> /var/spool/cron/root
if [[ ! $ONLY_DB_SYNC == 'true' ]]; then
if [[ $MASTER_NODE == 'true' ]]; then
if [[ $EFS_ENABLED == 'true' ]]; then
if [[ $TESTNET_ENABLED == 'true' ]]; then
echo "0 0 * * * source /root/.bash_profile && aws s3 sync /cardano/db/$HOSTNAME/ s3://$DB_BUCKET_NAME/testnet/ --delete &>>/var/log/cron.log" >> /var/spool/cron/root
echo "0 15 * * * source /root/.bash_profile && rm -rf /cardano/db/testnet/ && mkdir /cardano/db/testnet/ && cp -R /cardano/db/$HOSTNAME/* /cardano/db/testnet/ &>>/var/log/cron.log" >> /var/spool/cron/root
else
echo "0 0 * * * source /root/.bash_profile && aws s3 sync /cardano/db/$HOSTNAME/ s3://$DB_BUCKET_NAME/ --delete &>>/var/log/cron.log" >> /var/spool/cron/root
echo "0 15 * * * source /root/.bash_profile && rm -rf /cardano/db/source/ && mkdir /cardano/db/source/ && cp -R /cardano/db/$HOSTNAME/* /cardano/db/source/ &>>/var/log/cron.log" >> /var/spool/cron/root
fi
else
if [[ $TESTNET_ENABLED == 'true' ]]; then
echo "0 0 * * * source /root/.bash_profile && aws s3 sync /cardano/db/ s3://$DB_BUCKET_NAME/testnet/ --delete &>>/var/log/cron.log" >> /var/spool/cron/root
else
echo "0 0 * * * source /root/.bash_profile && aws s3 sync /cardano/db/ s3://$DB_BUCKET_NAME/ --delete &>>/var/log/cron.log" >> /var/spool/cron/root
fi
fi
fi
fi
fi
if [[ ! $ONLY_DB_SYNC == 'true' ]]; then
if [[ $REMOTE_URL_SYNC == 'true' ]]; then
curl -L -o ./db_archive.tar.gz $REMOTE_DB_URL
tar -xvf ./db_archive.tar.gz --directory ${NODE_HOME}/db/
rm -rf ./db_archive.tar.gz
fi
fi
nohup /usr/sbin/sshd -D -o ListenAddress=0.0.0.0 -p 22 >>/var/log/sshd.log 2>&1 &
if [[ ! $ONLY_DB_SYNC == 'true' ]]; then
nohup crond >>/var/log/cron.log 2>&1 &
nohup socat TCP-LISTEN:3333,fork,reuseaddr, UNIX-CONNECT:$CARDANO_NODE_SOCKET_PATH >>/var/log/socat.log 2>&1 &
nohup cardano-submit-api --mainnet --socket-path $CARDANO_NODE_SOCKET_PATH --config /cardano/config/tx-submit-mainnet-config.yaml --port 8090 --listen-address 0.0.0.0 &
elif [[ $ONLY_DB_SYNC == 'true' ]]; then
nohup crond >>/var/log/cron.log 2>&1 &
nohup socat UNIX-LISTEN:$CARDANO_NODE_SOCKET_PATH,fork,reuseaddr,unlink-early, TCP:$REMOTE_NODE_SERVER:$REMOTE_NODE_PORT >>/var/log/socat.log 2>&1 &
nohup cardano-submit-api --mainnet --socket-path $CARDANO_NODE_SOCKET_PATH --config /cardano/config/tx-submit-mainnet-config.yaml --port 8090 --listen-address 0.0.0.0 &
fi
if [[ $DB_SYNC_ENABLED == 'true' ]]; then
echo -e "\n-= Updating Postgres DB Files =-"
sed -i "s^hostname^${POSTGRES_HOST}^g" /cardano/config/pgpass-mainnet
sed -i "s^port^${POSTGRES_PORT}^g" /cardano/config/pgpass-mainnet
sed -i "s^database^${POSTGRES_DB}^g" /cardano/config/pgpass-mainnet
sed -i "s^username^${POSTGRES_USER}^g" /cardano/config/pgpass-mainnet
sed -i "s^password^${POSTGRES_PASS}^g" /cardano/config/pgpass-mainnet
cp /cardano/config/pgpass-mainnet /home/admin/.pgpass
chown admin /home/admin/.pgpass
chmod 600 /home/admin/.pgpass
cp /cardano/config/pgpass-mainnet /root/.pgpass
chown root /root/.pgpass
chmod 600 /root/.pgpass
if [[ ! $SEPARATE_DB_SYNC == 'true' ]]; then
if [[ $MASTER_NODE == 'true' ]]; then
if [[ $RESTORE_DB_SYNC_SNAPSHOT == 'true' ]]; then
echo -e "\n-= Download most recent cardano-db-sync snapshot"
curl -L -o cardano-snapshot.tgz https://update-cardano-mainnet.iohk.io/cardano-db-sync/12/db-sync-snapshot-schema-12-block-6850499-x86_64.tgz
tar -xvf cardano-snapshot.tgz --directory /cardano/snapshots --exclude configuration
rm -rf cardano-snapshot.tgz
db_snap_name=$(ls /cardano/snapshots/db*)
mkdir -p /cardano/sync/ledger-state/mainnet
PGPASSFILE=/cardano/config/pgpass-mainnet /cardano/scripts/postgresql-setup.sh --restore-snapshot ${db_snap_name} /cardano/sync/ledger-state/mainnet
rm -rf ${db_snap_name}
fi
fi
fi
if [[ $MASTER_NODE == 'true' ]]; then
if [[ ! $SEPARATE_DB_SYNC == 'true' ]]; then
if [[ ! $ONLY_DB_SYNC == 'true' ]]; then
nohup bash -c '/cardano/scripts/start-db-sync.sh' >>/var/log/dbsync.log 2>&1 &
fi
fi
fi
echo "export DB_SYNC_ENABLED=true" >> /root/.bash_profile
echo "export DB_SYNC_ENABLED=true" >> /home/admin/.bash_profile
fi
cd /home/admin/cardobot && git pull && ./INSTALL && cd ~/
chown admin -R /home/admin/.cardobot/wallets/
if [[ $ONLY_DB_SYNC == 'true' ]]; then
bash -c '/cardano/scripts/start-db-sync.sh'
else
bash -c '/cardano/scripts/start-relay.sh'
fi