From 6407733c8edf30e87014e421eb8008b57f6e294b Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 20 Nov 2020 12:37:30 -0500 Subject: [PATCH] * make llarp.halt rpc call actually return a reply (#1488) * add --kill flag to lokinet-vpn that calls llarp.halt * make macos uninstaller kill lokinet via lokinet-vpn --kill --- contrib/macos/lokinet_uninstall.sh | 9 +++++---- daemon/lokinet-vpn.cpp | 16 +++++++++++++++- llarp/rpc/rpc_server.cpp | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/contrib/macos/lokinet_uninstall.sh b/contrib/macos/lokinet_uninstall.sh index e094f5884..63885b972 100755 --- a/contrib/macos/lokinet_uninstall.sh +++ b/contrib/macos/lokinet_uninstall.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -x test `whoami` == root || exit 1 @@ -28,11 +28,12 @@ SERVICE_NAME=`scutil_query Setup:/Network/Service/$SERVICE_GUID \ # tell dns to be "empty" so that it's reset networksetup -setdnsservers "$SERVICE_NAME" empty -# shut off exit if it's up -pgrep lokinet$ && /opt/lokinet/bin/lokinet-vpn --down - # Prevent restarting on exit touch /var/lib/lokinet/suspend-launchd-service + +# shut off lokinet gracefully +pgrep lokinet$ && /opt/lokinet/bin/lokinet-vpn --kill + # kill the gui and such killall LokinetGUI killall lokinet diff --git a/daemon/lokinet-vpn.cpp b/daemon/lokinet-vpn.cpp index 51ac591bc..5e43f6722 100644 --- a/daemon/lokinet-vpn.cpp +++ b/daemon/lokinet-vpn.cpp @@ -59,6 +59,7 @@ main(int argc, char* argv[]) opts.add_options() ("v,verbose", "Verbose", cxxopts::value()) ("h,help", "help", cxxopts::value()) + ("kill", "kill the daemon", cxxopts::value()) ("up", "put vpn up", cxxopts::value()) ("down", "put vpn down", cxxopts::value()) ("exit", "specify exit node address", cxxopts::value()) @@ -77,6 +78,7 @@ main(int argc, char* argv[]) bool goUp = false; bool goDown = false; bool printStatus = false; + bool killDaemon = false; try { const auto result = opts.parse(argc, argv); @@ -102,6 +104,7 @@ main(int argc, char* argv[]) goUp = result.count("up") > 0; goDown = result.count("down") > 0; printStatus = result.count("status") > 0; + killDaemon = result.count("kill") > 0; if (result.count("endpoint") > 0) { @@ -127,7 +130,7 @@ main(int argc, char* argv[]) std::cout << ex.what() << std::endl; return 1; } - if ((not goUp) and (not goDown) and (not printStatus)) + if ((not goUp) and (not goDown) and (not printStatus) and (not killDaemon)) { std::cout << opts.help() << std::endl; return 1; @@ -161,6 +164,17 @@ main(int argc, char* argv[]) return 1; } + if (killDaemon) + { + const auto maybe = LMQ_Request(lmq, connID, "llarp.halt"); + if (not maybe.has_value()) + { + std::cout << "call to llarp.admin.die failed" << std::endl; + return 1; + } + return 0; + } + if (printStatus) { const auto maybe_status = LMQ_Request(lmq, connID, "llarp.status"); diff --git a/llarp/rpc/rpc_server.cpp b/llarp/rpc/rpc_server.cpp index 1dd861cc3..a0d138f54 100644 --- a/llarp/rpc/rpc_server.cpp +++ b/llarp/rpc/rpc_server.cpp @@ -93,8 +93,8 @@ namespace llarp::rpc msg.send_reply(CreateJSONError("router is not running")); return; } - m_Router->Stop(); msg.send_reply(CreateJSONResponse("OK")); + m_Router->Stop(); }) .add_request_command( "version",