Skip to content

Commit

Permalink
Problem: (fix #246)missing service file for chain-maind (#247)
Browse files Browse the repository at this point in the history
Solution: adding sample template and helper script
  • Loading branch information
allthatjazzleo authored Nov 5, 2020
1 parent 4687b82 commit 6988a00
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ clean:
clean-docker-compose: localnet-stop
rm -rf $(BUILDDIR)/node* $(BUILDDIR)/gentxs

create-systemd:
./networks/create-service.sh

###############################################################################
### Nix ###
###############################################################################
Expand Down Expand Up @@ -180,6 +183,9 @@ else
endif
endif

###############################################################################
### Release ###
###############################################################################
.PHONY: release-dry-run
release-dry-run:
docker run \
Expand Down
17 changes: 17 additions & 0 deletions networks/chain-maind.service.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# /etc/systemd/system/chain-maind.service
[Unit]
Description=Chain-maind
ConditionPathExists=<CHAIN_MAIND_BINARY>
After=network.target

[Service]
Type=simple
User=<CHAIN_MAIND_USER>
WorkingDirectory=<CHAIN_MAIND_BINARY_DIR>
ExecStart=<CHAIN_MAIND_BINARY> start --home <CHAIN_MAIND_USER_HOME>/.chain-maind
Restart=on-failure
RestartSec=10
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target
24 changes: 24 additions & 0 deletions networks/create-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -e

BASEDIR=$(dirname "$0")

CHAIN_MAIND_BINARY=$(which chain-maind || (echo -e "\033[31mPlease add chain-maind to PATH\033[0m" 1>&2 && exit 1))
CHAIN_MAIND_USER=$USER
CHAIN_MAIND_BINARY_DIR=$(dirname $(which chain-maind))
CHAIN_MAIND_USER_HOME=$(eval echo "~$USER")

sed "s#<CHAIN_MAIND_BINARY>#$CHAIN_MAIND_BINARY#g; s#<CHAIN_MAIND_USER>#$CHAIN_MAIND_USER#g; s#<CHAIN_MAIND_BINARY_DIR>#$CHAIN_MAIND_BINARY_DIR#g; s#<CHAIN_MAIND_USER_HOME>#$CHAIN_MAIND_USER_HOME#g" $BASEDIR/chain-maind.service.template > $BASEDIR/chain-maind.service

echo -e "\033[32mGenerated $BASEDIR/chain-maind.service\033[0m"

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo cp $BASEDIR/chain-maind.service /etc/systemd/system/chain-maind.service
sudo systemctl daemon-reload
sudo systemctl enable chain-maind.service
echo -e "\033[32mCreated /etc/systemd/system/chain-maind.service\033[0m"
else
echo -e "\033[31mCan only create /etc/systemd/system/chain-maind.service for linux\033[0m" 1>&2
exit 1
fi

0 comments on commit 6988a00

Please sign in to comment.