-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoxen-multi-sn-upgrade
executable file
·154 lines (131 loc) · 4.41 KB
/
oxen-multi-sn-upgrade
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
#!/bin/bash
set -e
if [ "$#" -ne 0 ]; then
echo "Usage: oxen-multi-sn-upgrade"
exit 1
fi
if [ "$UID" -ne 0 ]; then
echo "This script must be run as root (e.g. via sudo)."
exit 1
fi
oxend_upgrade=()
ss_upgrade=()
lokinet_upgrade=()
ss210_upgrade=()
shopt -s nullglob
echo "Finding lokid->oxend configs that need migration:"
for x in /etc/loki/node-[0-9][0-9].conf; do
ox="${x/loki/oxen}"
if [ -e "$ox" ]; then
echo "Error: $ox already exists, aborting migration to avoid potentially overwriting things" >&2
exit 1
fi
oxend_upgrade+=("$x")
echo " - $x"
done
echo "Finding storage server configs that need migration:"
for x in /etc/loki/storage-[0-9][0-9].conf; do
ox="${x/loki/oxen}"
if [ -e "$ox" ]; then
echo "Error: $ox already exists, aborting migration to avoid potentially overwriting things" >&2
exit 1
fi
ss_upgrade+=("$x")
echo " - $x"
done
for x in /etc/oxen/storage-[0-9][0-9].conf; do
if ! grep -q oxend-rpc= $x; then
ss210_upgrade+=("$x")
echo " - $x"
fi
done
echo "Finding lokinet configs that need upgrading:"
for x in /etc/loki/lokinet-router-[0-9][0-9].ini; do
if grep -q ^jsonrpc $x; then
lokinet_upgrade+=("$x")
echo " - $x"
fi
done
if [ "${#oxend_upgrade[@]}${#ss_upgrade[@]}${#lokinet_upgrade[@]}${#ss210_upgrade[@]}" == "0000" ]; then
echo "Nothing to upgrade"
exit 0
fi
restarts=()
if [ "${#oxend_upgrade[@]}" -gt 0 ]; then
echo -e "\n"
read -p "Press enter to move /etc/loki/node-*.conf files to /etc/oxen and switch the active services to [email protected], Ctrl-C to abort."
echo
stops=()
starts=()
for ox in "${oxend_upgrade[@]}"; do
NN=${ox/*node-/}
NN=${NN/.conf/}
mv -v "${ox}" "${ox/loki/oxen}"
if systemctl -q is-enabled loki-node@$NN; then
stops+=("loki-node@$NN")
starts+=("oxen-node@$NN")
fi
done
if [ "${#stops[@]}" -gt 0 ]; then
echo "Switching active services from loki-node@XX to oxen-node@XX"
systemctl disable "${stops[@]}"
systemctl enable "${starts[@]}"
echo "Stopping ${stops[*]}"
systemctl stop "${stops[@]}"
echo "Starting ${starts[*]}"
systemctl start "${starts[@]}"
fi
fi
if [ "${#ss_upgrade[@]}" -gt 0 ]; then
echo -e "\n"
read -p "Press enter to move /etc/loki/storage-*.conf files to /etc/oxen and switch the active services to [email protected], Ctrl-C to abort."
echo
stops=()
starts=()
for ox in "${ss_upgrade[@]}"; do
NN=${ox/*storage-/}
NN=${NN/.conf/}
mv -v "${ox}" "${ox/loki/oxen}"
if systemctl -q is-enabled loki-storage-server@$NN; then
stops+=("loki-storage-server@$NN")
starts+=("oxen-storage-server@$NN")
fi
done
if [ "${#stops[@]}" -gt 0 ]; then
echo "Switching active services from loki-storage-server@XX to oxen-storage-server@XX"
systemctl disable "${stops[@]}"
systemctl enable "${starts[@]}"
echo "Stopping ${stops[*]}"
systemctl stop "${stops[@]}"
echo "Starting ${starts[*]}"
systemctl start "${starts[@]}"
fi
echo -e "\e[33;1mNOTE: you need to run this script once more to fully migrate storage server!\e[1m"
fi
if [ "${#lokinet_upgrade[@]}" -gt 0 ]; then
echo -e "\n"
read -p "Press enter to change the old jsonrpc= option to rpc=... in the above lokinet configs, Ctrl-C to abort."
for ln in "${lokinet_upgrade[@]}"; do
num=${ln/*-/}
num=${num/.ini/}
perl -pi -e "s{^jsonrpc=.*}{rpc=ipc:///var/lib/oxen/node-$num/oxend.sock}" $ln
echo "Updated RPC setting in $ln"
done
restarts+=("lokinet-routers.target")
fi
if [ "${#ss210_upgrade[@]}" -gt 0 ]; then
echo -e "\n"
echo -e "About to change the old lokid-rpc-port=PORT option to oxend-rpc=ipc:///var/lib/oxen/node-XX/oxend.sock"
read -p "Press enter to continue, Ctrl-C to abort."
for ss in "${ss210_upgrade[@]}"; do
num=${ss/*storage-/}
num=${num/.conf/}
perl -pi -e "s{lokid-rpc-port=.*}{oxend-rpc=ipc:///var/lib/oxen/node-$num/oxend.sock}" $ss
echo "Updated RPC setting in $ss"
done
restarts+=("oxen-storage-servers.target")
fi
echo -e "\nAll done."
if [ "${#restarts[*]}" -gt 0 ]; then
echo -e "You probably want to run this now:\n\nsystemctl restart ${restarts[*]}\n"
fi