From 1e72f2ade025a1558e889ca461f311b8e810b1bd Mon Sep 17 00:00:00 2001 From: Marcin Jachymiak Date: Tue, 25 Feb 2020 12:52:04 -0500 Subject: [PATCH 1/3] Add systemd service conf. Update setup script --- setup-scripts/bashrc | 3 +++ setup-scripts/setup.sh | 11 +++++++++-- setup-scripts/siad.service | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 setup-scripts/siad.service diff --git a/setup-scripts/bashrc b/setup-scripts/bashrc index 3cc9f795..29d1c12f 100644 --- a/setup-scripts/bashrc +++ b/setup-scripts/bashrc @@ -112,3 +112,6 @@ if ! shopt -oq posix; then fi fi export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin:/home/user/go/bin + +export SIA_DATA_DIR=/home/user/siad +export SIA_API_PASSWORD=$(cat /home/user/.sia/apipassword) diff --git a/setup-scripts/setup.sh b/setup-scripts/setup.sh index ea1b5a27..78161f0e 100755 --- a/setup-scripts/setup.sh +++ b/setup-scripts/setup.sh @@ -46,7 +46,7 @@ sudo ufw allow 'Nginx HTTP' # Install Go 1.13.7. wget -c https://dl.google.com/go/go1.13.7.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.13.7.linux-amd64.tar.gz -source ~/.bashrc +export PATH=$PATH:$HOME/go/bin rm go1.13.7.linux-amd64.tar.gz # Sanity check that will pass if go was installed correctly. @@ -57,10 +57,17 @@ cwd=$(pwd) # Install Sia cd ~/ git clone https://gitlab.com/NebulousLabs/Sia -cd Sia && git checkout viewnode && make +cd Sia && git checkout v1.4.3 && make # Setup skynet frontend. cd $cwd cd ../ yarn yarn build + +# Enable the systemd service +cd $cwd +mkdir -p $HOME/.config/systemd/user +cp siad.service $HOME/.config/systemd/user/siad.service + +systemctl --user enable siad.service diff --git a/setup-scripts/siad.service b/setup-scripts/siad.service new file mode 100644 index 00000000..36403bef --- /dev/null +++ b/setup-scripts/siad.service @@ -0,0 +1,15 @@ +[Unit] +Description=siad + +[Service] +Type=simple +WorkingDirectory=/home/user/siad +Environment="SIA_DATA_DIR=/home/user/siad" +Environment="SIA_API_PASSWORD=$(cat /home/user/.sia/apipassword)" +Environment="SIA_WALLET_PASSWORD=$(cat /home/user/.sia/walletpassword)" +ExecStart=/home/user/go/bin/siad +ExecStop=/home/user/go/bin/siac stop +Restart=on-failure + +[Install] +WantedBy=default.target From c9d1bbddc84363c50333cef8b0694701ebe157e7 Mon Sep 17 00:00:00 2001 From: Marcin Jachymiak Date: Tue, 25 Feb 2020 12:56:19 -0500 Subject: [PATCH 2/3] Update setup README with systemctl commands --- setup-scripts/README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/setup-scripts/README.md b/setup-scripts/README.md index 49867c4c..e80c78f4 100644 --- a/setup-scripts/README.md +++ b/setup-scripts/README.md @@ -45,10 +45,16 @@ as recent as `v1.4.3`. You still need to setup `siad` for the backend to be complete. -1. `cd ~/; mkdir siad` -2. `nohup siad &>/dev/null &` +The setup script creates a systemd user service that will run `siad` in the +background and automatically restart upon failure. The `siad.service` file must +be placed in `~/.config/systemd/user/` + +To start the service: `systemctl --user start siad` +To stop it: `systemctl --user stop siad` +To check the status of it: `systemctl --user status siad` + +To check standard err/standard out: `journalctl --user-unit siad` -This will start syncing `siad` in the background. ## Portal Setup From bbdb363660e540e374a7fdcb795588b1d9a249f3 Mon Sep 17 00:00:00 2001 From: Marcin Jachymiak Date: Wed, 26 Feb 2020 11:45:50 -0500 Subject: [PATCH 3/3] Use an environment variable file --- setup-scripts/README.md | 7 +++++++ setup-scripts/bashrc | 5 +++-- setup-scripts/setup.sh | 7 ++++--- setup-scripts/sia.env | 3 +++ setup-scripts/siad.service | 4 +--- 5 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 setup-scripts/sia.env diff --git a/setup-scripts/README.md b/setup-scripts/README.md index e80c78f4..829da339 100644 --- a/setup-scripts/README.md +++ b/setup-scripts/README.md @@ -49,6 +49,13 @@ The setup script creates a systemd user service that will run `siad` in the background and automatically restart upon failure. The `siad.service` file must be placed in `~/.config/systemd/user/` +To use the `siad.service`, first fill out `~/.sia/sia.env` environment variables with the +correct values. You will need to initialize your wallet if you have not already +done so. + +To enable the service: `systemctl --user enable siad.service` + +### Useful Commands To start the service: `systemctl --user start siad` To stop it: `systemctl --user stop siad` To check the status of it: `systemctl --user status siad` diff --git a/setup-scripts/bashrc b/setup-scripts/bashrc index 29d1c12f..61d41906 100644 --- a/setup-scripts/bashrc +++ b/setup-scripts/bashrc @@ -113,5 +113,6 @@ if ! shopt -oq posix; then fi export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin:/home/user/go/bin -export SIA_DATA_DIR=/home/user/siad -export SIA_API_PASSWORD=$(cat /home/user/.sia/apipassword) +set -o allexport +source ~/.sia/sia.env +set +o allexport diff --git a/setup-scripts/setup.sh b/setup-scripts/setup.sh index 78161f0e..b1464478 100755 --- a/setup-scripts/setup.sh +++ b/setup-scripts/setup.sh @@ -67,7 +67,8 @@ yarn build # Enable the systemd service cd $cwd -mkdir -p $HOME/.config/systemd/user -cp siad.service $HOME/.config/systemd/user/siad.service +mkdir -p ~/.config/systemd/user +cp siad.service ~/.config/systemd/user/siad.service -systemctl --user enable siad.service +mkdir -p ~/.sia +cp sia.env ~/.sia/ diff --git a/setup-scripts/sia.env b/setup-scripts/sia.env new file mode 100644 index 00000000..cc986b46 --- /dev/null +++ b/setup-scripts/sia.env @@ -0,0 +1,3 @@ +SIA_DATA_DIR="" +SIA_API_PASSWORD="" +SIA_WALLET_PASSWORD="" diff --git a/setup-scripts/siad.service b/setup-scripts/siad.service index 36403bef..769936c2 100644 --- a/setup-scripts/siad.service +++ b/setup-scripts/siad.service @@ -4,9 +4,7 @@ Description=siad [Service] Type=simple WorkingDirectory=/home/user/siad -Environment="SIA_DATA_DIR=/home/user/siad" -Environment="SIA_API_PASSWORD=$(cat /home/user/.sia/apipassword)" -Environment="SIA_WALLET_PASSWORD=$(cat /home/user/.sia/walletpassword)" +EnvironmentFile=/home/user/.sia/sia.env ExecStart=/home/user/go/bin/siad ExecStop=/home/user/go/bin/siac stop Restart=on-failure