Skip to content

Commit 7f870f5

Browse files
committed
replace daemon 'start' subdommand with -d
1 parent 241a37d commit 7f870f5

4 files changed

Lines changed: 32 additions & 52 deletions

File tree

electrum/commands.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,7 @@ def get_parser():
11391139
add_global_options(parser_gui)
11401140
# daemon
11411141
parser_daemon = subparsers.add_parser('daemon', help="Run Daemon")
1142-
parser_daemon.add_argument("subcommand", choices=['start', 'status', 'stop', 'load_wallet', 'close_wallet'], nargs='?')
1143-
#parser_daemon.set_defaults(func=run_daemon)
1142+
parser_daemon.add_argument("-d", "--detached", action="store_true", dest="detach", default=False, help="run daemon in detached mode")
11441143
add_network_options(parser_daemon)
11451144
add_global_options(parser_daemon)
11461145
# commands

electrum/daemon.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ async def start_jsonrpc(self, config: SimpleConfig, fd):
243243
self.methods = jsonrpcserver.methods.Methods()
244244
self.methods.add(self.ping)
245245
self.methods.add(self.gui)
246-
self.methods.add(self.daemon)
247246
self.cmd_runner = Commands(self.config, None, self.network, self)
248247
for cmdname in known_commands:
249248
self.methods.add(getattr(self.cmd_runner, cmdname))
@@ -261,17 +260,6 @@ async def start_jsonrpc(self, config: SimpleConfig, fd):
261260
async def ping(self):
262261
return True
263262

264-
async def daemon(self, config_options):
265-
config = SimpleConfig(config_options)
266-
sub = config.get('subcommand')
267-
assert sub in [None, 'start', 'stop']
268-
if sub in [None, 'start']:
269-
response = "Daemon already running"
270-
elif sub == 'stop':
271-
self.stop()
272-
response = "Daemon stopped"
273-
return response
274-
275263
async def gui(self, config_options):
276264
config = SimpleConfig(config_options)
277265
if self.gui_object:

electrum/tests/regtest/regtest.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ fi
8989

9090
# start daemons. Bob is started first because he is listening
9191
if [[ $1 == "start" ]]; then
92-
$bob daemon start
93-
$alice daemon start
94-
$carol daemon start
92+
$bob daemon -d
93+
$alice daemon -d
94+
$carol daemon -d
9595
$bob load_wallet
9696
$alice load_wallet
9797
$carol load_wallet
@@ -158,7 +158,7 @@ fi
158158

159159
if [[ $1 == "redeem_htlcs" ]]; then
160160
$bob stop
161-
ELECTRUM_DEBUG_LIGHTNING_SETTLE_DELAY=10 $bob daemon start
161+
ELECTRUM_DEBUG_LIGHTNING_SETTLE_DELAY=10 $bob daemon -d
162162
sleep 1
163163
$bob load_wallet
164164
sleep 1
@@ -204,7 +204,7 @@ fi
204204

205205
if [[ $1 == "breach_with_unspent_htlc" ]]; then
206206
$bob stop
207-
ELECTRUM_DEBUG_LIGHTNING_SETTLE_DELAY=3 $bob daemon start
207+
ELECTRUM_DEBUG_LIGHTNING_SETTLE_DELAY=3 $bob daemon -d
208208
sleep 1
209209
$bob load_wallet
210210
wait_for_balance alice 1
@@ -236,7 +236,7 @@ fi
236236

237237
if [[ $1 == "breach_with_spent_htlc" ]]; then
238238
$bob stop
239-
ELECTRUM_DEBUG_LIGHTNING_SETTLE_DELAY=3 $bob daemon start
239+
ELECTRUM_DEBUG_LIGHTNING_SETTLE_DELAY=3 $bob daemon -d
240240
sleep 1
241241
$bob load_wallet
242242
wait_for_balance alice 1
@@ -276,7 +276,7 @@ if [[ $1 == "breach_with_spent_htlc" ]]; then
276276
# (to_local needs to_self_delay blocks; htlc needs whatever we put in invoice)
277277
new_blocks 150
278278
$alice stop
279-
$alice daemon start
279+
$alice daemon -d
280280
sleep 1
281281
$alice load_wallet -w /tmp/alice/regtest/wallets/toxic_wallet
282282
# wait until alice has spent both ctx outputs
@@ -285,7 +285,7 @@ if [[ $1 == "breach_with_spent_htlc" ]]; then
285285
wait_until_spent $ctx_id 1
286286
new_blocks 1
287287
echo "bob comes back"
288-
$bob daemon start
288+
$bob daemon -d
289289
sleep 1
290290
$bob load_wallet
291291
wait_for_balance bob 0.049
@@ -299,8 +299,8 @@ if [[ $1 == "watchtower" ]]; then
299299
$alice setconfig --offline watchtower_url http://127.0.0.1:12345
300300
$carol setconfig --offline watchtower_host 127.0.0.1
301301
$carol setconfig --offline watchtower_port 12345
302-
$carol daemon start
303-
$alice daemon start
302+
$carol daemon -d
303+
$alice daemon -d
304304
sleep 1
305305
$alice load_wallet
306306
wait_for_balance alice 1

run_electrum

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ if __name__ == '__main__':
327327
config = SimpleConfig(config_options)
328328

329329
cmdname = config.get('cmd')
330-
subcommand = config.get('subcommand')
331330

332331
if config.get('testnet'):
333332
constants.set_testnet()
@@ -338,7 +337,7 @@ if __name__ == '__main__':
338337
elif config.get('lightning') and not config.get('reckless'):
339338
raise Exception('lightning branch not available on mainnet')
340339

341-
if cmdname == 'daemon' and subcommand == 'start':
340+
if cmdname == 'daemon' and config.get("detach"):
342341
# fork before creating the asyncio event loop
343342
pid = os.fork()
344343
if pid:
@@ -370,32 +369,26 @@ if __name__ == '__main__':
370369

371370
elif cmdname == 'daemon':
372371

373-
if subcommand in [None, 'start']:
374-
configure_logging(config)
375-
fd = daemon.get_file_descriptor(config)
376-
if fd is not None:
377-
# run daemon
378-
init_plugins(config, 'cmdline')
379-
d = daemon.Daemon(config, fd)
380-
if config.get('websocket_server'):
381-
from electrum import websockets
382-
websockets.WebSocketServer(config, d.network)
383-
if config.get('requests_dir'):
384-
path = os.path.join(config.get('requests_dir'), 'index.html')
385-
if not os.path.exists(path):
386-
print("Requests directory not configured.")
387-
print("You can configure it using https://github.com/spesmilo/electrum-merchant")
388-
sys_exit(1)
389-
d.run_daemon()
390-
sys_exit(0)
391-
else:
392-
result = daemon.request(config, 'daemon', (config_options,))
372+
configure_logging(config)
373+
fd = daemon.get_file_descriptor(config)
374+
if fd is not None:
375+
# run daemon
376+
init_plugins(config, 'cmdline')
377+
d = daemon.Daemon(config, fd)
378+
if config.get('websocket_server'):
379+
from electrum import websockets
380+
websockets.WebSocketServer(config, d.network)
381+
if config.get('requests_dir'):
382+
path = os.path.join(config.get('requests_dir'), 'index.html')
383+
if not os.path.exists(path):
384+
print("Requests directory not configured.")
385+
print("You can configure it using https://github.com/spesmilo/electrum-merchant")
386+
sys_exit(1)
387+
d.run_daemon()
388+
sys_exit(0)
393389
else:
394-
try:
395-
result = daemon.request(config, 'daemon', (config_options,))
396-
except daemon.DaemonNotRunning:
397-
print_msg("Daemon not running")
398-
sys_exit(1)
390+
print_msg("Daemon already running")
391+
sys_exit(1)
399392
else:
400393
# command line
401394
cmd = known_commands[cmdname]
@@ -406,7 +399,7 @@ if __name__ == '__main__':
406399
try:
407400
result = daemon.request(config, 'run_cmdline', (config_options,), timeout)
408401
except daemon.DaemonNotRunning:
409-
print_msg("Daemon not running; try 'electrum daemon start'")
402+
print_msg("Daemon not running; try 'electrum daemon -d'")
410403
if not cmd.requires_network:
411404
print_msg("To run this command without a daemon, use --offline")
412405
sys_exit(1)

0 commit comments

Comments
 (0)