Skip to content

Commit

Permalink
chore: add init scripts for systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Apr 10, 2019
1 parent 349e8e8 commit fa52571
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions devtools/ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if [ -n "$TRAVIS_TAG" -a -n "$GITHUB_TOKEN" -a -n "$REL_PKG" ]; then
mkdir "releases/$PKG_NAME"
mv target/release/ckb "releases/$PKG_NAME"
cp README.md CHANGELOG.md COPYING "releases/$PKG_NAME"
cp -R devtools/init/ "releases/$PKG_NAME"
if [ -d docs ]; then
cp -R docs "releases/$PKG_NAME"
fi
Expand Down
11 changes: 11 additions & 0 deletions devtools/init/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Init/Service Scripts

This folder provides the init/service scripts to start CKB node and miner as
daemons on various Unix like distributions.

See the README in each folder for the detailed instructions.

## Disclaimer

Users are expected to know how to administer their system, and these files
should be considered as only a guide or suggestion to setup CKB.
82 changes: 82 additions & 0 deletions devtools/init/linux-systemd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# CKB systemd unit configuration

The provided files should work with systemd version 219 or later.

## Instructions

The following instructions assume that:

* you want to run ckb as user `ckb` and group `ckb`, and store data in `/var/lib/ckb`.
* you want to join testnet.
* you are logging in as a non-root user account that has `sudo` permissions to execute commands as root.

First, get ckb and move the binary into the system binary directory, and setup the appropriate ownership and permissions:

```bash
sudo cp /path/to/ckb /usr/local/bin
sudo chown root:root /usr/local/bin/ckb
sudo chmod 755 /usr/local/bin/ckb
```

Setup the directories and generate config files for testnet.

```bash
sudo mkdir /var/lib/ckb
sudo /usr/local/bin/ckb init -C /var/lib/ckb --spec testnet --log stdout
```

Setup the user and group and the appropriate ownership and permissions.

```bash
sudo groupadd ckb
sudo useradd \
-g ckb --no-user-group \
--home-dir /var/lib/ckb --no-create-home \
--shell /usr/sbin/nologin \
--system ckb

sudo chown -R ckb:ckb /var/lib/ckb
sudo chmod 755 /var/lib/ckb
sudo chmod 644 /var/lib/ckb/ckb.toml /var/lib/ckb/ckb-miner.toml
```

Install the systemd service unit configuration file, reload the systemd daemon,
and start the node:

```bash
curl -L -O https://raw.githubusercontent.com/nervosnetwork/ckb/master/devtools/init/linux-systemd/ckb.service
sudo cp ckb.service /etc/systemd/system/
sudo chown root:root /etc/systemd/system/ckb.service
sudo chmod 644 /etc/systemd/system/ckb.service
sudo systemctl daemon-reload
sudo systemctl start ckb.service
```

Start the node automatically on boot if you like:

```bash
sudo systemctl enable ckb.service
```

If ckb doesn't seem to start properly you can view the logs to figure out the problem:

```bash
journalctl --boot -u ckb.service
```

Following the similar instructions to start a miner:

```bash
curl -L -O https://raw.githubusercontent.com/nervosnetwork/ckb/master/devtools/init/linux-systemd/ckb-miner.service
sudo cp ckb-miner.service /etc/systemd/system/
sudo chown root:root /etc/systemd/system/ckb-miner.service
sudo chmod 644 /etc/systemd/system/ckb-miner.service
sudo systemctl daemon-reload
sudo systemctl start ckb-miner.service
```

Let the miner starts automatically on boot:

```bash
sudo systemctl enable ckb-miner.service
```
21 changes: 21 additions & 0 deletions devtools/init/linux-systemd/ckb-miner.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=Nervos CKB Miner
Documentation=https://github.com/nervosnetwork/ckb
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
User=ckb
Group=ckb
WorkingDirectory=/var/lib/ckb

ExecStart=/usr/local/bin/ckb miner
Restart=on-abnormal
KillMode=mixed
TimeoutStopSec=5s

LimitNOFILE=1048576
LimitNPROC=512

[Install]
WantedBy=multi-user.target
21 changes: 21 additions & 0 deletions devtools/init/linux-systemd/ckb.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=Nervos CKB Node
Documentation=https://github.com/nervosnetwork/ckb
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
User=ckb
Group=ckb
WorkingDirectory=/var/lib/ckb

ExecStart=/usr/local/bin/ckb
Restart=on-abnormal
KillMode=mixed
TimeoutStopSec=5s

LimitNOFILE=1048576
LimitNPROC=512

[Install]
WantedBy=multi-user.target

0 comments on commit fa52571

Please sign in to comment.