Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
systemd service to run the Bitcoin core daemon
[Unit]
Description=bitcoind
Requires=docker.service
[Service]
WorkingDirectory=/root
TimeoutStartSec=0
# Kill and rm leftover containers
ExecStartPre=-/bin/docker pull abrkn/bitcoind
ExecStartPre=-/bin/docker pull abrkn/ebs-sidekick
ExecStartPre=-/bin/docker pull abrkn/elb-sidekick
ExecStartPre=-/bin/docker kill bitcoind bitcoind-ebs bitcoind-elb
ExecStartPre=-/bin/docker rm bitcoind bitcoind-ebs bitcoind-elb
# Attach EBS volume
ExecStartPre=/bin/bash -c "\
docker run \
-d \
--name bitcoind-ebs \
--env AWS_ACCESS_KEY_ID=$(etcdctl get /aws_key) \
--env AWS_SECRET_ACCESS_KEY=$(etcdctl get /aws_secret) \
--env VOLUME_ID=$(etcdctl get /bitcoind_volume_id) \
--env DEVICE=/dev/sdf \
--env AWS_DEFAULT_REGION=eu-west-1 \
abrkn/ebs-sidekick ; \
sleep 10 ; \
mkdir -p /bitcoind ; \
[ -z $(lsblk | grep -qs ^xvdf )] && mount /dev/xvdf /bitcoind \
"
# Run bitcoind container
ExecStart=/bin/docker run \
-v /bitcoind:/data \
--name bitcoind \
abrkn/bitcoind
# Register to ELB
ExecStartPost=/bin/bash -c "\
docker run \
-d \
--name bitcoind-elb \
--env AWS_ACCESS_KEY_ID=$(etcdctl get /aws_key) \
--env AWS_SECRET_ACCESS_KEY=$(etcdctl get /aws_secret) \
--env ELB_NAME=jc-testing-bitcoind \
--env AWS_DEFAULT_REGION=eu-west-1 \
abrkn/elb-sidekick \
"
# Deregister from ELB
ExecStop=/bin/docker stop -t 30 bitcoind-elb
ExecStop=/bin/docker stop -t 60 bitcoind
# Detach EBS volume
ExecStopPost=/bin/bash -c "\
docker stop bitcoind ; \
umount /bitcoind ; \
docker stop bitcoind-ebs \
"
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.