Skip to main content

Debian/Ubuntu Bitcoin Daemon Startup Script

`bitcoind` init.d startup script

The Debian bitcoind package does not install or contain any init.d scripts, and net search failed to return any decent examples so I had to crate my own.

If this has helped please comment or follow me on twitter danielsokolows - be great.

#!/bin/sh
### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
### BEGIN INIT INFO
# Provides: bitcoind
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Bitcoin Deamon
# Description: Bitcoin Deamon
### END INIT INFO

# modified by Daniel Sokolowski 

# Install by typing  update-rc.d  defaults

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC=bitcoind
NAME=bitcoind
PIDFILE=/var/run/bitcoind.pid
USER=root
DAEMON=/usr/bin/bitcoind
#DAEMON_ARGS="-pid=$PIDFILE -datadir=/mnt/M=ST8000AS0002-1NA17Z,S=Z840PWH2/bitcoind-datadir -debuglogfile=/var/log/bitcoind.log"
DAEMON_ARGS="-daemon -pid=$PIDFILE -datadir=/mnt/M=ST8000AS0002-1NA17Z,S=Z840PWH2/bitcoind-datadir -debuglogfile=/var/log/bitcoind.log"
#SCRIPTNAME=/etc/init.d/$NAME
#WORKDIR=/var/lib/$NAME

# Check if user exists
if ! id -u $USER > /dev/null 2>&1; then
    echo "The user does not exist; execute below commands to crate and try again:"
    echo "  root@sh1:~# adduser --home /usr/local/freeswitch/ --shell /bin/false --no-create-home --ingroup daemon --disabled-password --disabled-login $USER"
    echo "  ..."
    echo "  root@sh1:~# chown freeswitch:daemon /usr/local/freeswitch/ -R"
    exit 1
fi

[ -x $DAEMON ] || exit 0
#[ -r /etc/default/$NAME ] && . /etc/default/$NAME
. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
  #start-stop-daemon --start --quiet \
  #     --pidfile $PIDFILE --exec $DAEMON --name $NAME --user $USER \
  #     --chdir $WORKDIR -- $DAEMON $DAEMON_OPTS \
#echo $DAEMON $DAEMON_ARGS
  nice -19 $DAEMON $DAEMON_ARGS  || return 1
  return 0
}

do_stop() {
  start-stop-daemon --stop --quiet \
    --pidfile $PIDFILE  --name $NAME --user $USER \
    --retry=TERM/30/KILL/5
}

do_reload() {
  start-stop-daemon --stop --quiet \
    --pidfile $PIDFILE --name $NAME --user $USER \
    --signal HUP
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
    do_start
    case "$?" in
      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
  reload|force-reload)
    log_daemon_msg "Reloading $DESC" "$NAME"
    do_reload
    log_end_msg $?
    ;;
  restart)
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
          0) log_end_msg 0 ;;
          1|*) log_end_msg 1 ;;
        esac
        ;;
      *) log_end_msg 1 ;;
    esac
    ;;
  *)
    echo "Usage:  {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
esac

exit 0

Comments

Popular posts from this blog

Softeher 'Error occurred. (Error code: 2)' sollution

Protocol error occurred. Error was returned from the destination server.The Softether server by default to run on port 443, if you server also hosts normal https then 443 is already taken and so Softether can't bind to it. When you run `vpncmd` it attempts to connect, find an active port, but of course fails with 'Protocol error occurred. Error was returned from the destination server.' because it's not actually connecting to the vpn server. By default Softether also listens on 992, 1194, and 5555 so the sollution is to modify specify `localhost:5555` when executing the `vpncmnd`. If this has helped you feel free to comment or follow me on twitter @danielsokolows.

Duplicate value found: duplicates value on record with id: <unknown>.

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>.The above error is triggered in the database layer and caused by a trigger or workflow outside of your main code of block that is bubbling this exception. This is rather difficult to track down especially if you are unfamiliar with the code, I am sharing my procedure in the hopes this saves you time - if you find this helpful drop me a line or follow me on twitter @danielsokolows. This error is caused by unique field constraint on the object, so the first step is to examine the object and locate the API names of all unique fieds. You can do this through SF direclty 'Setup < Customize &lt <object being inserted> &lt Fields' or by downloading the `src/objects` metadata information and searching for <unique>; I preffer the latter and actually download ALL matadata information f…

Storing passwords in PuTTY

How to save SSH username/password for auto login in PuTTy The answer is you can't do it...at least in plain PuTTy. However there is an awesome fork with that let's you store the username and password and other additional features called KiTTy.



So grab yourself a copy and +1 this if you do, thanks.