Skip to content

Commit

Permalink
Add Snap fullnode daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Jun 25, 2018
1 parent c9a38d8 commit 1782df6
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,62 @@ $ snap info solana
$ sudo snap refresh solana --devmode
```

### Daemon support
The snap supports running a leader or validator node as a system daemon.

Run `sudo snap get solana` to view the current daemon configuration, and
`sudo snap logs -f solana` to view the daemon logs.

Disable the daemon at any time by running:
```bash
$ sudo snap set solana daemon=
```

Runtime configuration files for the daemon can be found in
`/var/snap/solana/current`.

#### Leader daemon
```bash
$ sudo snap set solana daemon=leader
```

If CUDA is available:
```bash
$ sudo snap set solana daemon=leader-cuda
```

`rsync` must be configured and running on the leader.

1. Ensure rsync is installed with `sudo apt-get -y install rsync`
2. Edit `/etc/rsyncd.conf` to include the following
```
[solana]
path = /var/snap/solana/current
hosts allow = *
read only = true
```
3. Run `sudo systemctl start rsync`
4. Test by running `rsync -ravv rsync://<address-of-leader>/solana
solana-config` from another machine. If the leader is running on a cloud
provider it may be necessary to configure the Firewall rules to permit ingress
to port tcp:873


#### Validator daemon
```bash
$ sudo snap set solana daemon=validator
```
If CUDA is available:
```bash
$ sudo snap set solana daemon=validator-cuda
```

By default the validator will connect to **testnet.solana.com**, override
the leader address by running:
```bash
$ sudo snap set solana daemon=validator leader-address=127.0.0.1 #<-- change IP address
```

Developing
===

Expand Down
63 changes: 63 additions & 0 deletions multinode-demo/fullnode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
#
# Simplified interface to starting a full node
#

usage() {
cat <<EOF
Usage: $0 [mode] [leader_address]"
mode Select operation mode:
leader - Run a leader
leader-cuda - Run a leader with CUDA
validator - Run a validator
validator-cuda - Run a validator with CUDA
leader_address Address of the leader node to connect with.
Only required when mode=validator or mode=validator-cuda
EOF
exit 1
}

here="$(dirname "$0")"


MODE=
if [[ -n "$1" ]]; then
MODE="$1"
elif [[ -d $SNAP ]]; then # Running as a Linux Snap?
MODE="$(snapctl get daemon)"
fi
[[ -n "$MODE" ]] || usage

case $MODE in
leader-cuda|leader)
echo "Starting $MODE"
# TODO: Run setup.sh here if necessary
# TODO: Consider CUDA
exec "$here"/leader.sh
;;

validator-cuda|validator)
LEADER_ADDRESS=testnet.solana.com
if [[ -n "$2" ]]; then
LEADER_ADDRESS="$2"
elif [[ -d $SNAP ]]; then # Running as a Linux Snap?
LEADER_ADDRESS="$(snapctl get leader-address)"
fi
[[ -n "$LEADER_ADDRESS" ]] || usage

# TODO: Run setup.sh here if necessary
# TODO: Consider CUDA
echo "Starting $MODE with leader address: $LEADER_ADDRESS"
exec "$here"/validator.sh "$LEADER_ADDRESS"
;;

*)
echo "Error: Unknown mode: $MODE"
exit 1
;;
esac

exit 1
4 changes: 4 additions & 0 deletions multinode-demo/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ myip=$(myip) || exit $?

num_tokens=${1:-1000000000}

#
# TODO: Merge this file with ../snap/hooks/configure
#

cargo run --release --bin solana-mint-demo <<<"${num_tokens}" > mint-demo.json
cargo run --release --bin solana-genesis-demo < mint-demo.json > genesis.log

Expand Down
40 changes: 40 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash -e

MODE="$(snapctl get daemon)"

# Setup aliases to the normal solana command to make the reset of configure more
# readable.
shopt -s expand_aliases
export SNAP SNAP_LIBRARY_PATH
alias solana-mint-demo=$SNAP/command-mint-demo.wrapper
alias solana-genesis-demo=$SNAP/command-genesis-demo.wrapper
alias solana-fullnode-config=$SNAP/command-fullnode-config.wrapper

echo Stopping daemon
snapctl stop --disable solana.daemon
if [[ -n "$MODE" ]]; then

#
# TODO: Merge this file with ../../../multinode-demo/setup.sh
#

NUM_TOKENS=1000000000

echo Cleaning $SNAP_DATA
rm -rvf $SNAP_DATA/*

echo Creating $SNAP_DATA/mint-demo.json
solana-mint-demo <<<"$NUM_TOKENS" > $SNAP_DATA/mint-demo.json

echo Creating $SNAP_DATA/genesis.log
solana-genesis-demo < $SNAP_DATA/mint-demo.json > $SNAP_DATA/genesis.log

echo Creating $SNAP_DATA/leader.json
solana-fullnode-config -d > $SNAP_DATA/leader.json

echo Creating $SNAP_DATA/validator.json
solana-fullnode-config -d -b 9000 > $SNAP_DATA/validator.json

echo Starting daemon as $MODE
snapctl start --enable solana.daemon
fi
15 changes: 15 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ grade: devel
# CUDA dependency, so use 'devmode' confinement for now
confinement: devmode

hooks:
configure:
plugs: []

apps:
drone:
command: solana-drone
Expand Down Expand Up @@ -44,7 +48,18 @@ apps:
client-demo:
command: solana-client-demo

daemon:
daemon: simple
command: fullnode.sh

parts:
solana-scripts:
plugin: nil
override-build: |
set -x
mkdir -p $SNAPCRAFT_PART_INSTALL/bin
cp -av multinode-demo/* $SNAPCRAFT_PART_INSTALL/bin/
solana-cuda:
plugin: rust
rust-channel: stable
Expand Down

0 comments on commit 1782df6

Please sign in to comment.