Bitcoin Forum
June 21, 2024, 09:30:47 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Cant auto start Bitcoind on restart  (Read 1380 times)
chek2fire (OP)
Legendary
*
Offline Offline

Activity: 3416
Merit: 1142


Intergalactic Conciliator


View Profile
August 05, 2015, 04:36:55 PM
 #1

I have a home 24/7 small bitcoin node and time to time i have to restart it manual for several reasons like a suddenly power of etc. I try to create a script to auro restart the programme especially with restart but with no luck. Everything i have try was a failure.
My system is Ubuntu server 14.04 with upstart and i will describe as better as i can what i have done so far until now.

1)First i try to type this in contrab -e

@reboot bitcoind -daemon

and then this

@reboot /usr/bin/bitcoind -daemon

but bitcoind didnt start at all and i have again to start it manual.


2) then i try to type a script in the /etc/rc0.d or to rc.local. The script was that

#!/bin/bash

while true; do
  sleep 5
  if [ ! "$(pidof bitcoind)" ]; then
    bitcoind
  fi
done

the script was working alone if i run it, was working after restart but was not able to start bitcoind.


3) then i try this

http://bitcoin.stackexchange.com/questions/13795/ubuntu-linux-how-do-i-start-bitcoind-as-a-service-to-run-automatically

Quote
description "bitcoind"
 
start on filesystem
stop on runlevel [!2345]
oom score -500
expect fork
respawn
respawn limit 10 60 # 10 times in 60 seconds
 
script
user=mobinmob
home=/home/$user
cmd=/usr/bin/bitcoind
pidfile=$home/bitcoind.pid
# Don't change anything below here unless you know what you're doing
[[ -e $pidfile && ! -d "/proc/$(cat $pidfile)" ]] && rm $pidfile
[[ -e $pidfile && "$(cat /proc/$(cat $pidfile)/cmdline)" != $cmd* ]] && rm $pidfile
exec start-stop-daemon --start -c $user --chdir $home --pidfile $pidfile --startas $cmd -b -m
end script

i have add it to /etc/init as bitcoind.conf i restart my server but again bitcoind was not running.
The strange is that if i try to manual start it with this command

sudo service bitcoind start

it returns

start: Job is already running: bitcoind

but when i check it with bitcoin-cli getinfo the system say error: couldn't connect to server and i have again to start it manual or i have to stop the service and the again type sudo service bitcoind start.
I dont know but bitcoind it seems that cant start before the login in the system or something like that. I cant find any other explanation Sad

http://www.bitcoin-gr.org
4411 804B 0181 F444 ADBD 01D4 0664 00E4 37E7 228E
tl121
Sr. Member
****
Offline Offline

Activity: 278
Merit: 252


View Profile
August 05, 2015, 05:56:11 PM
 #2

On my system bitcoind runs as user bitcoin group bitcoin.  The file name is /etc/init/bitcoin.conf and its contents are:
====================

start on stopped rc RUNLEVEL=[2345] and (

            not-container or

            container CONTAINER=lxc or

            container CONTAINER=lxc-libvirt)



stop on runlevel [!2345]



respawn

exec start-stop-daemon --start --user bitcoin --chuid bitcoin --chdir /home/bitcoin --exec /home/bitcoin/bin/bitcoind -- -conf=/home/bitcoin/.bitcoin/bitcoin.conf -disablewallet

=========================
chek2fire (OP)
Legendary
*
Offline Offline

Activity: 3416
Merit: 1142


Intergalactic Conciliator


View Profile
August 05, 2015, 06:22:39 PM
 #3

and my user is part of bitcoin group. groups returns

bitcoin adm cdrom sudo dip plugdev lpadmin sambashare

http://www.bitcoin-gr.org
4411 804B 0181 F444 ADBD 01D4 0664 00E4 37E7 228E
chek2fire (OP)
Legendary
*
Offline Offline

Activity: 3416
Merit: 1142


Intergalactic Conciliator


View Profile
August 10, 2015, 07:19:27 PM
 #4

Ok i find a solution with runit. In my ubuntu server system i first to install the runit package

2. then i have to create an upstart script and save it in /etc/init/ as runit.conf

Quote
description "runit"

start on filesystem
stop on shutdown

respawn

script
exec runsvdir-start
end script


3.then i have to create a new folder in /etc/svn and a run excetuble

sudo mkdir /etc/sv/bitcoind/
cd /etc/sv/bitcoind/
sudo touch run
sudo chmod +x run

the run file must contain this

#!/bin/sh
exec chpst -u username -n 9 env HOME=/home/username bitcoind


4.then sysmlink this to etc service

Quote
sudo ln -s /etc/sv/bitcoind/ /etc/service/

5. finally i have to start it Cheesy

sudo service runit start

and it works fine Cheesy
A big thx to mobinmob

http://www.insomnia.gr/topic/577198-script-%CE%B3%CE%B9%CE%B1-relaunch-%CF%80%CF%81%CE%BF%CE%B3%CF%81%CE%AC%CE%BC%CE%BC%CE%B1%CF%84%CE%BF%CF%82/page-6?

http://www.bitcoin-gr.org
4411 804B 0181 F444 ADBD 01D4 0664 00E4 37E7 228E
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!