Author

Topic: Detect if Bitcoin is running? (Read 2119 times)

legendary
Activity: 1652
Merit: 2311
Chief Scientist
April 18, 2011, 09:05:01 PM
#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.
newbie
Activity: 19
Merit: 0
April 18, 2011, 08:51:38 PM
#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?
legendary
Activity: 1232
Merit: 1076
April 18, 2011, 06:26:23 AM
#6
administrator
Activity: 5222
Merit: 13032
April 18, 2011, 02: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.
newbie
Activity: 19
Merit: 0
April 18, 2011, 01: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...
administrator
Activity: 5222
Merit: 13032
April 18, 2011, 01: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
legendary
Activity: 1658
Merit: 1001
April 18, 2011, 12:54:39 AM
#2
# ps|grep bitcoind

That is how I normally do a quick check if services are running.
newbie
Activity: 19
Merit: 0
April 18, 2011, 12: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?
Jump to: