diff options
| author | Slack Coder <slackcoder@server.ky> | 2025-08-26 16:07:00 -0500 |
|---|---|---|
| committer | Slack Coder <slackcoder@server.ky> | 2025-09-04 04:55:00 -0500 |
| commit | f7c9b27b590ed1527d913e6083fa3aa2b7ab3ca7 (patch) | |
| tree | 55cf542918c3748231f006d7700d84c968c31d89 /bitcoin/file/rc.bitcoind.new | |
| parent | 3f799ac48e925555c5a771558633675cf3819cdf (diff) | |
| download | slackbuilds-bitcoin.tar.xz | |
Add bitcoin: add rc.scriptbitcoin
Diffstat (limited to 'bitcoin/file/rc.bitcoind.new')
| -rw-r--r-- | bitcoin/file/rc.bitcoind.new | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/bitcoin/file/rc.bitcoind.new b/bitcoin/file/rc.bitcoind.new new file mode 100644 index 0000000..288f39e --- /dev/null +++ b/bitcoin/file/rc.bitcoind.new @@ -0,0 +1,95 @@ +#!/bin/sh + +# Time to wait for Bitcoin to gracefully stop. +TIMEOUT=${TIMEOUT:-5000} + +create_bitcoind_run_dir() { + if [ ! -d /run/bitcoind/ ]; then + mkdir -p /run/bitcoind + chown bitcoin:bitcoin /run/bitcoind + fi +} + +bitcoind_start() { + create_bitcoind_run_dir + + echo -n "Starting Bitcoin daemon: " + + local pid="" + if [ -f /run/bitcoind/bitcoind.pid ] && ! pid=$(</run/bitcoind/bitcoind.pid); then + return + fi + + if [ ! -z "$pid" ] && /bin/kill -0 "$pid" >/dev/null; then + echo "already running" + + return + fi + + if ! daemon \ + --user bitcoin:bitcoin \ + -- \ + bitcoind \ + -conf=/etc/bitcoin/bitcoind.conf \ + -daemon=0; then + echo "failed" + else + echo "ok" + fi +} + +bitcoind_status() { + create_bitcoind_run_dir + + echo -n "Bitcoin daemon: " + + local pid="" + if [ -f /run/bitcoind/bitcoind.pid ] && ! pid=$(</run/bitcoind/bitcoind.pid); then + return + fi + + if [ ! -z "$pid" ] && /bin/kill -0 "$pid" 2>/dev/null; then + echo "running" + else + echo "not running" + fi +} + +bitcoind_stop() { + create_bitcoind_run_dir + + echo -n "Stopping Bitcoin daemon: " + + local pid="" + if [ -f /run/bitcoind/bitcoind.pid ] && ! pid=$(</run/bitcoind/bitcoind.pid); then + return + fi + + if [ -z "$pid" ] || ! /bin/kill -0 "$pid" 2>/dev/null; then + echo "not running" + + return + fi + + if /bin/kill --timeout "${TIMEOUT}" TERM "$pid"; then + echo "stopped" + else + /bin/kill KILL "$pid" + echo "killed" + fi +} + +case "$1" in +start) + bitcoind_start + ;; +status) + bitcoind_status + ;; +stop) + bitcoind_stop + ;; +*) + echo "Usage: $0 {start|status|stop}" + exit 1 +esac |
