Created
          February 6, 2015 07:46 
        
      - 
      
- 
        Save LTGIV/f429ffb08ad8779d9269 to your computer and use it in GitHub Desktop. 
    bitcoind and insight-api startup scripts (Ubuntu 14.04.1 LTS)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # | |
| # bitcoind upstart v201502051158 | |
| # Louis T. Getterman IV (@LTGIV) | |
| # www.GotGetLLC.com / www.opensour.cc | |
| # | |
| # Example usage: | |
| # Save as /etc/init/bitcoind.conf | |
| # service bitcoind (start|stop|status|restart) | |
| # | |
| # Thanks to: | |
| # | |
| # https://github.com/CounterpartyXCP/counterpartyd_build/blob/master/dist/linux/init/bitcoind.conf.template | |
| # https://github.com/CounterpartyXCP/counterpartyd_build/blob/master/dist/linux/init/insight.conf.template | |
| # http://bitcoin.stackexchange.com/questions/13795/ubuntu-linux-how-do-i-start-bitcoind-as-a-service-to-run-automatically | |
| # https://bitcointalk.org/index.php?topic=25518.0 | |
| # | |
| description "bitcoind" | |
| start on filesystem | |
| stop on runlevel [!2345] | |
| oom score -500 | |
| expect fork | |
| respawn | |
| respawn limit 10 60 # 10 times in 60 seconds | |
| pre-start script | |
| echo; | |
| echo "$(date +"%Y-%m-%d_%H-%M-%S-%Z"): bitcoind starting up..." | |
| end script | |
| post-stop script | |
| echo; | |
| echo -n "$(date +"%Y-%m-%d_%H-%M-%S-%Z"): bitcoind shutdown in 5 seconds..." | |
| /bin/sleep 5 | |
| echo 'Goodbye' | |
| end script | |
| script | |
| # Variables to change: | |
| USER=insight | |
| HOME=/home/$USER | |
| CMD="$HOME/bin/bitcoind" | |
| ARGS='-daemon=0' | |
| PIDFILE=/var/run/bitcoind.pid | |
| # Meat & Potatoes: | |
| # start-stop-daemon --start --chuid $USER --chdir $USER_HOME --make-pidfile --pidfile $PIDFILE --exec $CMD -- $ARGS | |
| # start-stop-daemon --start -c $USER --make-pidfile --pidfile $PIDFILE --exec $CMD -- $ARGS | |
| start-stop-daemon --start --chuid $USER --make-pidfile --pidfile $PIDFILE --exec $CMD -- $ARGS | |
| end script | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # | |
| # insight upstart v201502060739 | |
| # Louis T. Getterman IV (@LTGIV) | |
| # www.GotGetLLC.com / www.opensour.cc | |
| # | |
| # Example usage: | |
| # Save as /etc/init/insight.conf | |
| # service insight (start|stop|status|restart) | |
| # | |
| # Thanks to: | |
| # | |
| # https://github.com/CounterpartyXCP/counterpartyd_build/blob/master/dist/linux/init/bitcoind.conf.template | |
| # https://github.com/CounterpartyXCP/counterpartyd_build/blob/master/dist/linux/init/insight.conf.template | |
| # http://bitcoin.stackexchange.com/questions/13795/ubuntu-linux-how-do-i-start-bitcoind-as-a-service-to-run-automatically | |
| # https://bitcointalk.org/index.php?topic=25518.0 | |
| # https://gist.github.com/orweinberger/15ada78c2af06d9cca06 | |
| # | |
| description "insight" | |
| start on started bitcoind | |
| stop on stopping bitcoind | |
| oom score -500 | |
| respawn | |
| respawn limit 10 60 # 10 times in 60 seconds | |
| # Variables to change - Upstart (1/2): | |
| env USER=insight | |
| # Variables to change - Upstart (1/2): | |
| #env USER_HOME=$(eval echo ~${USER}) | |
| pre-start script | |
| # Wait 5 minutes maximum or when Bitcoin gives us a return | |
| timeout=300 | |
| echo; | |
| echo "$(date +"%Y-%m-%d_%H-%M-%S-%Z"): startup insight-API timeout is ${timeout} seconds with ${USER} user. Giving time for bitcoind to settle. Checking every 10 seconds." | |
| seconds=1 | |
| while [ $seconds -lt $timeout ]; do | |
| if [ $(( $seconds % 10 )) -eq 0 ]; then | |
| # CHANGE PATH TO A VARIABLE | |
| case "$( su - insight -c '/home/insight/bin/bitcoin-cli getinfo | grep connections | wc -w' 2>/dev/null )" in | |
| 3) echo "$(date +"%Y-%m-%d_%H-%M-%S-%Z"): bitcoind is ready to go." | |
| break; | |
| ;; | |
| *) echo "$(date +"%Y-%m-%d_%H-%M-%S-%Z"): bitcoind isn't ready, waiting a little longer." | |
| ;; | |
| esac | |
| fi | |
| seconds=$(( $seconds + 1 )) | |
| sleep 1 | |
| done | |
| # END WHILE LOOP: $seconds < $timeout | |
| # Never managed to start, let's bail out | |
| if [ $seconds -eq $timeout ]; then | |
| echo "$(date +"%Y-%m-%d_%H-%M-%S-%Z"): insight-API failed to properly start. Exiting." | |
| stop; exit 0; | |
| fi | |
| end script | |
| post-stop script | |
| echo; | |
| echo -n "$(date +"%Y-%m-%d_%H-%M-%S-%Z"): insight-API shutdown in 5 seconds..." | |
| /bin/sleep 5 | |
| echo 'Goodbye' | |
| end script | |
| script | |
| # Variables to change - Upstart (1/2): | |
| USER_HOME=$(eval echo ~${USER}) | |
| # Variables to change - Upstart (2/2): | |
| CMD="${USER_HOME}/.nvm/v0.10.36/bin/node" | |
| ARGS="${USER_HOME}/bin/insight-api/insight.js" | |
| PIDFILE=/var/run/insight.pid | |
| # Variables to change - Insight: | |
| # (see https://github.com/bitpay/insight-api for more information) | |
| export INSIGHT_NETWORK=livenet | |
| export BITCOIND_DATADIR=$USER_HOME/.bitcoin/ | |
| export BITCOIND_USER=`cat $USER_HOME/.bitcoin/bitcoin.conf | sed -n 's/.*rpcuser=\([^ \n]*\).*/\1/p'` | |
| export BITCOIND_PASS=`cat $USER_HOME/.bitcoin/bitcoin.conf | sed -n 's/.*rpcpassword=\([^ \n]*\).*/\1/p'` | |
| export INSIGHT_IGNORE_CACHE=1 | |
| # Meat & Potatoes: | |
| start-stop-daemon --start --chuid $USER --chdir $USER_HOME --make-pidfile --pidfile $PIDFILE --exec $CMD -- $ARGS | |
| end script | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment