Bitcoin Forum
December 10, 2016, 10:25:36 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Detect if Bitcoin is running?  (Read 1709 times)
Rena
Newbie
*
Offline Offline

Activity: 19



View Profile WWW
April 18, 2011, 05:51:58 AM
 #1

What would be the proper/best way for a script to tell if bitcoin[d] is running? I'm writing a Lua script that calls `bitcoin getinfo` and similar commands, and I see it outputs a message to stderr if the server isn't running, but Lua doesn't provide any standard way to read stderr, so I was hoping there's another way to check?

15R7dpxfWuDrQY9CtUzMsg6A7sKMdWbTd3
1481408736
Hero Member
*
Offline Offline

Posts: 1481408736

View Profile Personal Message (Offline)

Ignore
1481408736
Reply with quote  #2

1481408736
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481408736
Hero Member
*
Offline Offline

Posts: 1481408736

View Profile Personal Message (Offline)

Ignore
1481408736
Reply with quote  #2

1481408736
Report to moderator
BioMike
Legendary
*
Offline Offline

Activity: 1259


View Profile
April 18, 2011, 05:54:39 AM
 #2

# ps|grep bitcoind

That is how I normally do a quick check if services are running.
theymos
Administrator
Legendary
*
expert
Offline Offline

Activity: 2506


View Profile
April 18, 2011, 06:04:14 AM
 #3

Code:
if curl -s 127.0.0.1:8332 >/dev/null; then
echo "running"
else
echo "not running"
fi

Edit: Another way (faster):
Code:
if /sbin/ss -l |grep -q "127.0.0.1:8332"; then
echo "running"
else
echo "not running"
fi

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
Rena
Newbie
*
Offline Offline

Activity: 19



View Profile WWW
April 18, 2011, 06:27:46 AM
 #4

Hmm, both of those rely on Unix shell commands and redirection. I was hoping for something like a PID file I can check that only exists when the server is running. I can do similar just by appending 2>&1 to the command I call from Lua, but as far as I know there's no guarantee that io.popen() will actually execute the command the way a shell would rather than, for example, just passing everything after the first space as the parameter to the program being called.
I can use sockets as well, but that requires adding LuaSocket, and I was hoping not to depend on any external libraries. Lua doesn't provide much on its own (it focuses on being simple and lightweight) so that may prove difficult to avoid...

15R7dpxfWuDrQY9CtUzMsg6A7sKMdWbTd3
theymos
Administrator
Legendary
*
expert
Offline Offline

Activity: 2506


View Profile
April 18, 2011, 07:01:29 AM
 #5

There is a .lock file in the data directory, though I don't know how reliable this is. Maybe it only appears when Bitcoin is doing something to the database.

You could parse /proc/net/tcp.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
genjix
Legendary
*
expert
Offline Offline

Activity: 1232


View Profile
April 18, 2011, 11:26:23 AM
 #6

Use my branch and do getinfo

https://github.com/genjix/bitcoin/tree/isinitialized
Rena
Newbie
*
Offline Offline

Activity: 19



View Profile WWW
April 19, 2011, 01:51:38 AM
 #7

That's the kind of thing I was looking for. Of course that means anyone using my script also has to use that branch. Will that change be in the official client in some future version?

15R7dpxfWuDrQY9CtUzMsg6A7sKMdWbTd3
Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW
April 19, 2011, 02:05:01 AM
 #8

Hmm, both of those rely on Unix shell commands and redirection. I was hoping for something like a PID file..

I pulled a patch that makes Linux/Mac bitcoin/bitcoind write a bitcoind.pid file when started with the -daemon switch (and erases it on shutdown).

Next release will have several changes to make startup on Linux/Mac more unix-standard-like.

How often do you get the chance to work on a potentially world-changing project?
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!