forked from spesmilo/electrum-server
-
Notifications
You must be signed in to change notification settings - Fork 17
/
electrum-server
executable file
·111 lines (98 loc) · 2.05 KB
/
electrum-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#! /bin/bash
electrum_config="/etc/electrum.conf"
if [ ! -f $electrum_config ]; then
echo "$electrum_config does not exist"
echo "please run 'configure'"
exit 1
fi
if ! hash run_electrum_server 2>/dev/null; then
echo "run_electrum_server is not installed"
echo "Please run 'python setup.py install'"
exit 1
fi
function read_config()
{
text=$1
echo `grep -e ^$text $electrum_config |awk -F\= '{print $2}' | tail -n 1| tr -d ' '`
}
# read path from config
path=$(read_config "path")
# read username
user=$(read_config "username")
# get PID of server
if [ `id -u` = 0 ] ; then
if ! PID=`su $user -c "run_electrum_server getpid"`; then
PID=""
fi
else
if ! PID=`run_electrum_server getpid`; then
PID=""
fi
fi;
case "$1" in
start)
if [ "$PID" ]; then
echo "Server already running (pid $PID)"
exit
fi
if ! [ "$path" ]; then
echo "Variable path not set in $electrum_config"
exit
fi
logfile=$(read_config "logfile")
if ! [ -f $logfile ]; then
touch $logfile
chown $user:$user $logfile
fi
echo "Starting server as daemon"
cmd="ulimit -n 65536; nohup run_electrum_server > /dev/null &"
if [ `id -u` = 0 ] ; then
su $user -c "$cmd"
else
$cmd
fi
;;
stop)
if [ ! $PID ]; then
echo "Server not running"
exit
fi
cmd="run_electrum_server stop"
if [ `id -u` = 0 ] ; then
su $user -c "$cmd"
else
$cmd
fi
echo "Waiting until process $PID terminates..."
while ps -p $PID > /dev/null; do sleep 1; done
echo "Done."
;;
status)
if [ ! "$PID" ]; then
echo "Server not running"
else
echo "Server running (pid $PID)"
fi
;;
getinfo|peers|numpeers|sessions|numsessions)
if [ ! "$PID" ]; then
echo "Server not running"
exit
fi
cmd="run_electrum_server $1"
if [ `id -u` = 0 ] ; then
su $user -c "$cmd"
else
$cmd
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: electrum-server {start|stop|restart|status|getinfo|peers|numpeers|sessions|numsessions}"
exit 1
;;
esac
exit 0