forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostinst_node
executable file
·214 lines (176 loc) · 6.18 KB
/
postinst_node
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
# it should be fixed
ENABLE_STDOUT_LOGGING="enableStdOutLogging"
GENERAL_CONFIG_DIR="/etc/indy"
GENERAL_DATA_DIR="/var/lib/indy"
GENERAL_LOG_DIR="/var/log/indy"
CLI_BASE_DIR="/home/indy/.indy-cli"
CLI_NETWORKS_DIR="$CLI_BASE_DIR/networks"
CLI_WALLETS_DIR="$CLI_BASE_DIR/wallets"
INSTALL_DIR='/usr/local/lib/python3.5/dist-packages'
NOFILES_SOFT_LIMIT=65536
NOFILES_HARD_LIMIT=131072
CLIENT_CONNECTIONS_LIMIT=10000
# workaround when .indy become regular file
if [ -f $CLI_BASE_DIR ]; then
rm $CLI_BASE_DIR
fi
# create general indy config folder if does not exist
mkdir -p $GENERAL_CONFIG_DIR
# create general indy data folder if does not exist
mkdir -p $GENERAL_DATA_DIR
# create general indy log folder if does not exist
mkdir -p $GENERAL_LOG_DIR
# create indy node config if does not exist
if [ ! -f $GENERAL_CONFIG_DIR/indy_config.py ]; then
cp $INSTALL_DIR/indy_node/general_config/indy_config.py $GENERAL_CONFIG_DIR
else
if [ -z "$(grep $ENABLE_STDOUT_LOGGING $GENERAL_CONFIG_DIR/indy_config.py)" ]; then
printf "\n%s\n%s\n" "# Disable stdout logging" "$ENABLE_STDOUT_LOGGING = False" >> $GENERAL_CONFIG_DIR/indy_config.py
fi
fi
chmod -R ug+rwx $GENERAL_CONFIG_DIR
chmod -R ug+rwx $GENERAL_DATA_DIR
chmod -R ug+rwx $GENERAL_LOG_DIR
# create indy cli folder if does not exist
mkdir -p $CLI_BASE_DIR
mkdir -p $CLI_NETWORKS_DIR
mkdir -p $CLI_WALLETS_DIR
chown -R indy:indy $CLI_BASE_DIR
chmod -R ug+rwx $CLI_BASE_DIR
# init_indy_node script
cat <<EOF > /usr/local/bin/init_indy_node
#!/bin/bash
if [ \$# -lt 5 ]; then
echo ""
echo "Usage: \$0 name ip port client_ip client_port [seed]";
echo " name - node name";
echo " ip - node IP";
echo " port - node port";
echo " client_ip - node client IP";
echo " client_port - node client port";
echo " seed - node seed";
echo ""
exit 1;
fi
echo "NODE_NAME=\$1" > $GENERAL_CONFIG_DIR/indy.env
echo "NODE_IP=\$2" >> $GENERAL_CONFIG_DIR/indy.env
echo "NODE_PORT=\$3" >> $GENERAL_CONFIG_DIR/indy.env
echo "NODE_CLIENT_IP=\$4" >> $GENERAL_CONFIG_DIR/indy.env
echo "NODE_CLIENT_PORT=\$5" >> $GENERAL_CONFIG_DIR/indy.env
echo "CLIENT_CONNECTIONS_LIMIT=$CLIENT_CONNECTIONS_LIMIT" >> $GENERAL_CONFIG_DIR/indy.env
if [ -z \$6 ]; then
init_indy_keys --name \$1
else
init_indy_keys --name \$1 --seed \$6
fi
EOF
chmod +x /usr/local/bin/init_indy_node
# add systemd script
cat <<EOF > /etc/systemd/system/indy-node.service
[Unit]
Description=Indy Node
Requires=indy-node-control.service
[Service]
EnvironmentFile=$GENERAL_CONFIG_DIR/indy.env
ExecStart=/usr/bin/env python3 -O /usr/local/bin/start_indy_node \${NODE_NAME} \${NODE_IP} \${NODE_PORT} \${NODE_CLIENT_IP} \${NODE_CLIENT_PORT}
User=indy
Group=indy
Restart=on-failure
RestartSec=10
StartLimitBurst=10
StartLimitInterval=200
TimeoutSec=300
LimitNOFILE=$NOFILES_SOFT_LIMIT:$NOFILES_HARD_LIMIT
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF > /etc/systemd/system/indy-node-control.service
[Unit]
Description=Service for upgrade of existing Indy Node and other operations
#Requires=indy.service
#After=indy.service
After=network.target
[Service]
Type=simple
EnvironmentFile=$GENERAL_CONFIG_DIR/node_control.conf
ExecStart=/usr/bin/env python3 -O /usr/local/bin/start_node_control_tool \$TEST_MODE --hold-ext \${HOLD_EXT}
Restart=on-failure
RestartSec=10
StartLimitBurst=10
StartLimitInterval=200
TimeoutSec=300
[Install]
WantedBy=multi-user.target
EOF
# add supervisord script
cat <<EOF > /etc/supervisor/indy-node.conf
[supervisord]
nodaemon=true
logfile=/var/log/indy/supervisord.log
logfile_maxbytes=10MB
loglevel=critical
[supervisorctl]
serverurl=http://127.0.0.1:9001
[inet_http_server]
port = 127.0.0.1:9001
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:indy-node]
command=sh -ac '. $GENERAL_CONFIG_DIR/indy.env;/usr/bin/env python3 -O /usr/local/bin/start_indy_node \${NODE_NAME} \${NODE_IP} \${NODE_PORT} \${NODE_CLIENT_IP} \${NODE_CLIENT_PORT}'
user=indy
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true
startsecs=15
startretries=6
stopasgroup=true
killasgroup=true
[program:indy-node-control]
command=sh -ac '. $GENERAL_CONFIG_DIR/node_control.conf;/usr/bin/env python3 -O /usr/local/bin/start_node_control_tool \${TEST_MODE} --hold-ext "\${HOLD_EXT}"'
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true
startsecs=15
startretries=6
stopasgroup=true
killasgroup=true
EOF
HOLD_EXT_ADDED=$(grep HOLD_EXT /etc/indy/node_control.conf)
if [ ! -f $GENERAL_CONFIG_DIR/node_control.conf ] || [ -z "${HOLD_EXT_ADDED}" ]; then
cat <<EOF > $GENERAL_CONFIG_DIR/node_control.conf
# Uncomment this to run agent in test mode:
#TEST_MODE=--test
TEST_MODE=
HOLD_EXT=
EOF
fi
sed -ie '/HOLD_EXT/{ s/\\//g}' $GENERAL_CONFIG_DIR/node_control.conf
mv /usr/local/bin/upgrade_indy_node_ubuntu1604.sh /usr/local/bin/upgrade_indy_node
mv /usr/local/bin/upgrade_indy_node_ubuntu1604_test.sh /usr/local/bin/upgrade_indy_node_test
mv /usr/local/bin/restart_indy_node_ubuntu1604.sh /usr/local/bin/restart_indy_node
mv /usr/local/bin/restart_sovrin_node_ubuntu1604.sh /usr/local/bin/restart_sovrin_node
mv /usr/local/bin/complete_rebranding_upgrade_ubuntu1604.sh /usr/local/bin/complete_rebranding_upgrade
chmod +x /usr/local/bin/upgrade_indy_node
chmod +x /usr/local/bin/upgrade_indy_node_test
chmod +x /usr/local/bin/restart_indy_node
chmod +x /usr/local/bin/restart_sovrin_node
chmod +x /usr/local/bin/complete_rebranding_upgrade
rm -f /usr/local/bin/delete_indy_node.bat /usr/local/bin/upgrade_indy_node_test.bat \
/usr/local/bin/restart_indy_node.bat /usr/local/bin/install_nssm.bat /usr/local/bin/upgrade_indy_node.bat \
/usr/local/bin/install_indy_node.bat /usr/local/bin/restart_upgrade_agent.bat
chown -R indy:indy $GENERAL_CONFIG_DIR
chown -R indy:indy $GENERAL_DATA_DIR
chown -R indy:indy $GENERAL_LOG_DIR
chmod -R ug+rw $GENERAL_CONFIG_DIR
chmod -R ug+rw $GENERAL_DATA_DIR
chmod -R ug+rw $GENERAL_LOG_DIR
# Automatically added from template:
if which py3compile >/dev/null 2>&1; then
py3compile -O -p indy-node $INSTALL_DIR
fi
# End automatically added section