fixes for start script
[electrum-server.git] / start
1 #!/bin/bash
2
3 PID=`/usr/bin/python server.py getpid`
4 if [[ $PID != *[!0-9]* ]]; then
5     echo "Server already running (pid $PID)"
6     exit
7 fi
8
9
10 electrum_config="/etc/electrum.conf"
11
12 if [ ! -f $electrum_config ]; then
13     echo "$electrum_config does not exist"
14     exit
15 fi
16
17 path=`grep path_fulltree $electrum_config |awk -F\= '{print $2}'`
18
19 #needs more hardening against double definiton of variable, dismiss commented ones
20
21 if ! [ "$path" ]; then
22     echo "Variable path_fulltree not set in $electrum_config"
23     exit
24     # we're actually forcing fulltree with this clause, which is ok if displaying v0.9 should use fulltree 
25 fi
26
27 rmdir $path --ignore-fail-on-non-empty
28
29 if [ ! -d $path ]; then
30     echo "Database not found in $path."
31     read -p "Do you want to download it from the Electrum foundry to $path ? " -n 1 -r
32     echo
33     if [[ $REPLY =~ ^[Yy]$ ]]; then
34         mkdir $path
35         wget -O - "http://foundry.electrum.org/leveldb-dump/electrum-fulltree-100-latest.tar.gz" | tar --extract --gunzip --strip-components 1 --directory $path --file -
36     fi
37 fi
38
39 echo "Starting server as daemon"
40 nohup /usr/bin/python -u server.py &> /var/log/electrum.log &