This commit is contained in:
irungentoo 2014-08-17 19:14:56 -04:00
commit 6ca7d86c50
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
5 changed files with 105 additions and 89 deletions

View File

@ -1,17 +1,17 @@
if BUILD_DHT_BOOTSTRAP_DAEMON
bin_PROGRAMS += tox_bootstrap_daemon
bin_PROGRAMS += tox-bootstrapd
tox_bootstrap_daemon_SOURCES = \
../other/bootstrap_daemon/tox_bootstrap_daemon.c
tox_bootstrapd_SOURCES = \
../other/bootstrap_daemon/tox-bootstrapd.c
tox_bootstrap_daemon_CFLAGS = \
tox_bootstrapd_CFLAGS = \
-I$(top_srcdir)/other/bootstrap_daemon \
$(LIBSODIUM_CFLAGS) \
$(NACL_CFLAGS) \
$(LIBCONFIG_CFLAGS)
tox_bootstrap_daemon_LDADD = \
tox_bootstrapd_LDADD = \
$(LIBSODIUM_LDFLAGS) \
$(NACL_LDFLAGS) \
libtoxcore.la \
@ -22,6 +22,6 @@ tox_bootstrap_daemon_LDADD = \
endif
EXTRA_DIST += \
$(top_srcdir)/other/bootstrap_daemon/conf \
$(top_srcdir)/other/bootstrap_daemon/tox_bootstrap_daemon.sh
$(top_srcdir)/other/bootstrap_daemon/tox-bootstrapd.conf \
$(top_srcdir)/other/bootstrap_daemon/tox-bootstrapd

View File

@ -1,62 +1,72 @@
##Instructions for Debian
The following commands are to be executed as root:
1. In `tox_bootstrap_daemon.sh` file change:
- `CFG` to where your config file (`conf`) will be; read rights required
- `DAEMON` to point to the executable
- `PIDFILE` to point to a pid file daemon would have rights to create
2. Go over everything in `conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox_bootstrap_daemon.sh`
3. Execute:
```
mv tox_bootstrap_daemon.sh /etc/init.d/tox_bootstrap_daemon
```
*(note that we removed `.sh` ending)*
4. Give the right permissions to this file:
```
chmod 755 /etc/init.d/tox_bootstrap_daemon
For security reasons we run the daemon under its own user.
Create a new user by executing the following:
```sh
sudo useradd --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
```
5. Execute:
```
update-rc.d tox_bootstrap_daemon defaults
Create a directory where the daemon will store its keys:
```sh
sudo mkdir /var/lib/tox-bootstrapd/
```
6. Start the service:
```
service tox_bootstrap_daemon start
Restrain other users from accessing the directory:
```sh
sudo chown tox-bootstrapd:tox-bootstrapd /var/lib/tox-bootstrapd/
sudo chmod 700 /var/lib/tox-bootstrapd/
```
7. Verify that the service is running:
```
service tox_bootstrap_daemon status
Look at the variable declarations in the beginning of `tox-bootstrapd` init script to see if you need to change anything for it to work for you. The default values must be fine for most users and we assume that you use those next.
Go over everything in `tox-bootstrapd.conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox-bootstrapd`.
Place `tox-bootstrapd.conf` file to where `CFGFILE` variable from `tox-bootstrapd` tells. By default it's `/etc/tox-bootstrapd.conf`.
Place `tox-bootstrapd` init file at `/etc/init.d/tox-bootstrapd`.
Set permissions for the init system to run the script:
```sh
sudo chmod 755 /etc/init.d/tox-bootstrapd
```
--
You can see daemon's log with
```
grep "tox_bootstrap_daemon" /var/log/syslog
Make the init system aware of the script:
```sh
sudo update-rc.d tox-bootstrapd defaults
```
**Note that system log is where you find your public key**
Start the daemon:
```sh
sudo service tox-bootstrapd start
```
Verify it's running:
```sh
sudo service tox-bootstrapd status
```
Get your public key and check that the daemon initialized correctly:
```sh
sudo grep "tox-bootstrapd" /var/log/syslog
```
--
###Troubleshooting:
1. Check the log for errors with
```
grep "tox_bootstrap_daemon" /var/log/syslog
- Check daemon's status:
```sh
sudo service tox-bootstrapd status
```
2. Check that paths in the beginning of `/etc/init.d/tox_bootstrap_daemon` are valid
- Check the log for errors:
```sh
sudo grep "tox-bootstrapd" /var/log/syslog
```
3. Make sure that `PIDFILE` from `/etc/init.d/tox_bootstrap_daemon` matches with the `pid_file_path` from `conf`
- Check that variables in the beginning of `/etc/init.d/tox-bootstrapd` are valid.
4. Make sure you have write permission to keys and pid files
- Make sure `pid_file_path` in `/etc/tox-bootstrapd.conf` matches `PIDFILE` from `/etc/init.d/tox-bootstrapd`.
5. Make sure you have read permission for config file
- Make sure you have write permission for keys and pid files.
- Make sure you have read permission for the config file.

View File

@ -1,6 +1,6 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: tox_bootstrap_daemon
# Provides: tox-bootstrapd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
@ -12,20 +12,18 @@
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Tox DHT bootstrap daemon"
NAME=tox_bootstrap_daemon
# You may want to change USER if you are using it anywhere else
USER=tom
CFG=/home/$USER/.$NAME/conf
DAEMON=/home/$USER/.$NAME/$NAME
DAEMON_ARGS="$CFG"
PIDFILE=/home/$USER/.$NAME/."$NAME".pid
NAME=tox-bootstrapd
DAEMON=/usr/local/bin/$NAME
CFGFILE=/etc/$NAME.conf
DAEMON_ARGS="$CFGFILE"
PIDDIR=/var/run/$NAME
PIDFILE=$PIDDIR/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
USER=tox-bootstrapd
GROUP=tox-bootstrapd
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
#[ -r /etc/default/$NAME ] && . /etc/default/$NAME
[ -x "$DAEMON" ] || exit 5
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
@ -40,12 +38,17 @@ SCRIPTNAME=/etc/init.d/$NAME
#
do_start()
{
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
sleep 1
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
if [ ! -d $PIDDIR ]
then
mkdir $PIDDIR
fi
chown $USER:$GROUP $PIDDIR
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test --chuid $USER > /dev/null || return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER -- $DAEMON_ARGS || return 2
}
#
@ -53,12 +56,14 @@ do_start()
#
do_stop()
{
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE --name $NAME --chuid $USER
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
@ -85,7 +90,7 @@ case "$1" in
status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart) #|force-reload)
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
@ -108,3 +113,4 @@ case "$1" in
exit 3
;;
esac
exit 0

View File

@ -1,6 +1,6 @@
/* tox_bootstrap_daemon.c
/* tox-bootstrapd.c
*
* Tox DHT bootstrap node daemon.
* Tox DHT bootstrap daemon.
*
* Copyright (C) 2014 Tox project All Rights Reserved.
*
@ -52,14 +52,14 @@
#include "../../testing/misc_tools.c"
#define DAEMON_NAME "tox_bootstrap_daemon"
#define DAEMON_VERSION_NUMBER 2014051800UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day
#define DAEMON_NAME "tox-bootstrapd"
#define DAEMON_VERSION_NUMBER 2014081600UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day
#define SLEEP_TIME_MILLISECONDS 30
#define sleep usleep(1000*SLEEP_TIME_MILLISECONDS)
#define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid"
#define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys"
#define DEFAULT_PID_FILE_PATH "tox-bootstrapd.pid"
#define DEFAULT_KEYS_FILE_PATH "tox-bootstrapd.keys"
#define DEFAULT_PORT 33445
#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false
#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
@ -480,7 +480,7 @@ void print_public_key(uint8_t *public_key)
char buffer[2 * crypto_box_PUBLICKEYBYTES + 1];
int index = 0;
int i;
size_t i;
for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) {
index += sprintf(buffer + index, "%02hhX", public_key[i]);
@ -529,7 +529,7 @@ int main(int argc, char *argv[])
// Check if the PID file exists
FILE *pid_file;
if (pid_file = fopen(pid_file_path, "r")) {
if ((pid_file = fopen(pid_file_path, "r"))) {
syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path);
fclose(pid_file);
}

View File

@ -1,18 +1,17 @@
// ProjectTox dht bootstrap node daemon configuration file.
// Tox DHT bootstrap daemon configuration file.
// Listening port.
port = 33445
// A key file is like a password, so keep it where no one can read it.
// If there is no key file, a new one will be generated.
// The daemon should have permission to read/write to it.
// Remember to replace the provided example with your own path.
keys_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.keys"
keys_file_path = "/var/lib/tox-bootstrapd/keys"
// The PID file written to by daemon.
// Make sure that the user who runs the daemon has permissions to write to the
// PID file.
// Remember to replace the provided example with your own path.
pid_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.pid"
pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"
// Enable IPv6.
enable_ipv6 = false
@ -30,18 +29,19 @@ tcp_relay_ports = [443, 3389, 33445]
// whether a node is up or not, though there are other methods of doing that.
enable_motd = true
motd = "tox_bootstrap_daemon"
motd = "tox-bootstrapd"
// Any number of nodes the daemon will bootstrap itself from.
// Any number of nodes the daemon will bootstrap itself off.
// Remember to replace the provided example with your own node list.
// There is a maintained list of bootstrap nodes on Tox's wiki, if you need it.
// There is a maintained list of bootstrap nodes on Tox's wiki, if you need it
// (http://wiki.tox.im/Nodes).
// You may leave the list empty or remove "bootstrap_nodes" complitely,
// in both cases this will be interpreted as if you don't want to bootstrap
// from anyone.
bootstrap_nodes = (
{ // Node 1
// Any ipv4 or ipv6, depending on whether `enable_ipv6` is set or not, and
// also any US-ASCII domain name.
// Any ipv4 or ipv6, depending on whether `enable_ipv6` is set or not,
// and also any US-ASCII domain name.
address = "198.46.136.167"
port = 33445
public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854"