Skip to content

Instantly share code, notes, and snippets.

@alainwolf
Last active August 29, 2015 13:57
Show Gist options
  • Save alainwolf/9765228 to your computer and use it in GitHub Desktop.
Save alainwolf/9765228 to your computer and use it in GitHub Desktop.
Electrum Server Ubuntu Upstart Configuration
# electrum-server The Electrum Bitcoin Wallet Server
#
# The server indexes UTXOs by address, in a Patricia tree structure.
# Electrum Bitcoin wallet clients connect to this server.
description "Electrum server"
author "Alain Wolf"
start on started bitcoind
stop on stopping bitcoind
# Allow upto 5 minutes shutdown-time
kill timeout 300
respawn
respawn limit 5 30
limit nofile 16384 16384
console log
expect fork
setuid electrum
setgid electrum
chdir /var/lib/electrum/src/electrum/server
env conf=/etc/electrum.conf
env pidfile=/var/lib/electrum/electrum.pid
env server=/var/lib/electrum/src/electrum/server/server.py
env logfile=/var/log/electrum.log
pre-start script
echo "Doing pre-start checks ... "
echo -n "Checking if a server is already running ... "
if /usr/bin/python $server getpid > /dev/null ; then
echo "Server already running (pid $PID)"
stop
exit 1
else
echo 'OK'
fi
echo -n "Checking for configuration file ... "
if [ ! -f $conf ]; then
echo "$conf does not exist"
stop
exit 1
else
echo 'OK'
fi
echo -n "Checking configuration ... "
path=`grep -e ^path_fulltree $conf |awk -F\= '{print $2}' | tail -n 1`
if ! [ "$path" ]; then
echo "Variable path_fulltree not set in $conf"
stop
exit 1
else
echo 'OK'
fi
echo -n "Checking for database directory ... "
rmdir $path --ignore-fail-on-non-empty
if [ ! -d $path ]; then
echo "No database found in $path."
stop
exit 1
else
echo 'OK'
fi
echo -n "Checking if bitcoind is accepting connections ... "
host=`grep -e ^host $conf |awk -F\= '{print $2}' | tail -n 1`
port=`grep -e ^port $conf |awk -F\= '{print $2}' | tail -n 1`
if nc -z $host $port; then
echo 'OK'
else
echo "Can't connect to bitcoind'."
stop
exit 1
fi
echo 'Starting Electrum Server.'
end script
exec \
/usr/bin/python -u $server > $logfile 2>&1 &
post-start script
# Waiting
echo -n '['`date --rfc-3339=seconds`'] Waiting for server to accept connections '
until /usr/bin/python $server getpid > /dev/null ;
do
sleep 10
echo -n '.'
done
echo '['`date --rfc-3339=seconds`'] Server is now ready.'
end script
pre-stop exec \
/usr/bin/python $server stop
#post-stop exec \
# rm -f $pidfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment