summaryrefslogtreecommitdiff
path: root/other/bootstrap_daemon/README.md
blob: e108b4154bcc9281971db9b61cbe15cc91e49a47 (plain)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Instructions

- [For `systemd` users](#for-systemd-users)
  - [Setting up](#setting-up)
  - [Updating](#updating)
  - [Troubleshooting](#troubleshooting)
- [For `SysVinit` users](#for-sysvinit-users)
  - [Setting up](#setting-up-1)
  - [Updating](#updating-1)
  - [Troubleshooting](#troubleshooting-1)
- [For `Docker` users](#for-docker-users)
  - [Setting up](#setting-up-2)
  - [Updating](#updating-2)
  - [Troubleshooting](#troubleshooting-2)


These instructions are primarily tested on Debian Linux, Wheezy for SysVinit and Jessie for systemd, but they should work on other POSIX-compliant systems too.


## For `systemd` users

### Setting up

For security reasons we run the daemon under its own user.

Create a new user by executing the following:
```sh
sudo useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
```

Restrict access to home directory:
```sh
sudo chmod 700 /var/lib/tox-bootstrapd
```

Copy `tox-bootstrapd.conf` file to where `ExecStart=` from `tox-bootstrapd.service` points to. By default it's `/etc/tox-bootstrapd.conf`.
```sh
sudo cp tox-bootstrapd.conf /etc/tox-bootstrapd.conf
```

Go over everything in the copied `tox-bootstrapd.conf` file. Set options you want and add actual working nodes to the `bootstrap_nodes` list, instead of the example ones, if you want your node to connect to the Tox network. Make sure `pid_file_path` matches `PIDFile=` from `tox-bootstrapd.service`.

Copy `tox-bootstrapd.service` to `/etc/systemd/system/`:
```sh
sudo cp tox-bootstrapd.service /etc/systemd/system/
```

You must uncomment the next line in tox-bootstrapd.service, if you want to use port number < 1024:

```
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
```

and, possibly, install `libcap2-bin` or `libcap2` package, depending of your distribution.

Reload systemd units definitions, enable service for automatic start (if needed), start it and verify it's running: 
```sh
sudo systemctl daemon-reload
sudo systemctl enable tox-bootstrapd.service
sudo systemctl start tox-bootstrapd.service
sudo systemctl status tox-bootstrapd.service
```

Get your public key and check that the daemon initialized correctly:
```sh
sudo grep "tox-bootstrapd" /var/log/syslog
```

### Updating

You want to make sure that the daemon uses the newest toxcore, as there might have been some changes done to the DHT, so it's advised to update the daemon at least once every month.

To update the daemon first stop it:

```sh
sudo systemctl stop tox-bootstrapd.service
```

Then update your toxcore git repository, rebuild the toxcore and the daemon and make sure to install them.

Check if `tox-bootstrapd.service` in toxcore git repository was modified since the last time you copied it, as you might need to update it too.

Reload `tox-bootstrapd.service` if you have updated modified it:

```sh
sudo systemctl daemon-reload
```

After all of this is done, simply start the daemon back again:

```sh
sudo systemctl start tox-bootstrapd.service
```

### Troubleshooting

- Check daemon's status:
```sh
sudo systemctl status tox-bootstrapd.service
```

- Check the log for errors:
```sh
sudo grep "tox-bootstrapd" /var/log/syslog
# or
sudo journalctl --pager-end
# or
sudo journalctl -f _SYSTEMD_UNIT=tox-bootstrapd.service
```

- Make sure tox-bootstrapd user has write permission for keys and pid files.

- Make sure tox-bootstrapd has read permission for the config file.

- Make sure tox-bootstrapd location matches its path in tox-bootstrapd.service file.



## For `SysVinit` users


### Setting up

For security reasons we run the daemon under its own user.

Create a new user by executing the following:
```sh
sudo useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
```

Restrict access to home directory:
```sh
sudo chmod 700 /var/lib/tox-bootstrapd
```

Copy `tox-bootstrapd.conf` file to where `CFGFILE` variable from `tox-bootstrapd.sh` points to. By default it's `/etc/tox-bootstrapd.conf`.
```sh
sudo cp tox-bootstrapd.conf /etc/tox-bootstrapd.conf
```

Go over everything in the copied `tox-bootstrapd.conf` file. Set options you want and add actual working nodes to the `bootstrap_nodes` list, instead of the example ones, if you want your node to connect to the Tox network. Make sure `pid_file_path` matches `PIDFILE` from `tox-bootstrapd.sh`.

Look at the variable declarations in the beginning of `tox-bootstrapd.sh` init script to see if you need to change anything for it to work on your system. The default values must be fine for most users and we assume that you use those next.

If you have configured the daemon to use any port numbers that are lower than 1024, you need to execute the command below, as by default non-privileged users cannot open ports <1024. The change persists through reboot:

```sh
sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/tox-bootstrapd
```

Copy `tox-bootstrapd.sh` init script to `/etc/init.d/tox-bootstrapd` (note the disappearance of ".sh" ending):
```sh
sudo cp tox-bootstrapd.sh /etc/init.d/tox-bootstrapd
```

Set permissions for the init system to run the script:
```sh
sudo chmod 755 /etc/init.d/tox-bootstrapd
```

Make the init system aware of the script, start the daemon and verify it's running:
```sh
sudo update-rc.d tox-bootstrapd defaults
sudo service tox-bootstrapd start
sudo service tox-bootstrapd status
```

Get your public key and check that the daemon initialized correctly:
```sh
sudo grep "tox-bootstrapd" /var/log/syslog
```


### Updating

You want to make sure that the daemon uses the newest toxcore, as there might have been some changes done to the DHT, so it's advised to update the daemon at least once every month.

To update the daemon first stop it:

```sh
sudo service tox-bootstrapd stop
```

Then update your toxcore git repository, rebuild the toxcore and the daemon and make sure to install them.

Check if `tox-bootstrapd.sh` in toxcore git repository was modified since the last time you copied it, as you might need to update it too.

After all of this is done, simply start the daemon back again:

```sh
sudo service tox-bootstrapd start
```

### Troubleshooting

- Check daemon's status:
```sh
sudo service tox-bootstrapd status
```

- Check the log for errors: 
```sh
sudo grep "tox-bootstrapd" /var/log/syslog
```

- Check that variables in the beginning of `/etc/init.d/tox-bootstrapd` are valid.

- Make sure tox-bootstrapd user has write permission for keys and pid files.

- Make sure tox-bootstrapd has read permission for the config file.

- Make sure tox-bootstrapd location matches its path in the `/etc/init.d/tox-bootstrapd` init script.


## For `Docker` users:

### Setting up

If you are familiar with Docker and would rather run the daemon in a Docker container, you may download the latest official docker image. Check the GitHub [releases](https://github.com/TokTok/c-toxcore/releases) page for the latest version (e.g. v0.2.11), and run:

```sh
docker pull toxchat/bootstrap-node:0.2.11
docker run --rm -it --entrypoint=sha256sum toxchat/bootstrap-node:latest /usr/local/bin/tox-bootstrapd
```

This will print the SHA256 checksum of the latest binary, which should agree with the SHA256 checksum in the Dockerfile.

If you want to build the bootstrap node from source, check out the latest release:

```sh
git checkout $(git tag --list | grep -P '^v(\d+).(\d+).(\d+)$' | \
  sed 's/v/v /g' | sed 's/\./ /g' | \
  sort -snk4,4 | sort -snk3,3 | sort -snk2,2 | tail -n 1 | \
  sed 's/v /v/g' | sed 's/ /\./g')
```

and run the following from the top level c-toxcore directory:

```sh
tar c $(git ls-files) | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node -

sudo useradd \
  --home-dir /var/lib/tox-bootstrapd \
  --create-home \
  --system \
  --shell /sbin/nologin \
  --comment "Account to run Tox's DHT bootstrap daemon" \
  --user-group tox-bootstrapd
sudo chmod 700 /var/lib/tox-bootstrapd

docker run -d --name tox-bootstrapd --restart always \
  -v /var/lib/tox-bootstrapd/:/var/lib/tox-bootstrapd/ \
  --ulimit nofile=32768:32768 \
  -p 443:443 \
  -p 3389:3389 \
  -p 33445:33445 \
  -p 33445:33445/udp \
  toxchat/bootstrap-node
```

We create a new user and protect its home directory in order to mount it in the Docker image, so that the kyepair the daemon uses would be stored on the host system, which makes it less likely that you would loose the keypair while playing with or updating the Docker container.

You can check logs for your public key or any errors:
```sh
docker logs tox-bootstrapd
```

Note that the Docker container runs a script which pulls a list of bootstrap nodes off https://nodes.tox.chat/ and adds them in the config file.

### Updating

You want to make sure that the daemon uses the newest toxcore, as there might have been some changes done to the DHT, so it's advised to update the daemon at least once every month.

To update the daemon, all you need is to erase current container with its image:

```sh
docker stop tox-bootstrapd
docker rm tox-bootstrapd
docker rmi toxchat/bootstrap-node
```

Then rebuild and run the image again:

```sh
tar c $(git ls-files) | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node -
docker run -d --name tox-bootstrapd --restart always \
  -v /var/lib/tox-bootstrapd/:/var/lib/tox-bootstrapd/ \
  -p 443:443 \
  -p 3389:3389 \
  -p 33445:33445 \
  -p 33445:33445/udp \
  toxchat/bootstrap-node
```

### Troubleshooting

- Check if the container is running:
```sh
docker ps -a
```

- Check the log for errors:
```sh
docker logs tox-bootstrapd
```