* 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
This commit is contained in:
Jeff 2020-11-20 12:37:30 -05:00 committed by GitHub
parent f1b074bb95
commit 6407733c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
set -x set -x
test `whoami` == root || exit 1 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 # tell dns to be "empty" so that it's reset
networksetup -setdnsservers "$SERVICE_NAME" empty networksetup -setdnsservers "$SERVICE_NAME" empty
# shut off exit if it's up
pgrep lokinet$ && /opt/lokinet/bin/lokinet-vpn --down
# Prevent restarting on exit # Prevent restarting on exit
touch /var/lib/lokinet/suspend-launchd-service touch /var/lib/lokinet/suspend-launchd-service
# shut off lokinet gracefully
pgrep lokinet$ && /opt/lokinet/bin/lokinet-vpn --kill
# kill the gui and such # kill the gui and such
killall LokinetGUI killall LokinetGUI
killall lokinet killall lokinet

View File

@ -59,6 +59,7 @@ main(int argc, char* argv[])
opts.add_options() opts.add_options()
("v,verbose", "Verbose", cxxopts::value<bool>()) ("v,verbose", "Verbose", cxxopts::value<bool>())
("h,help", "help", cxxopts::value<bool>()) ("h,help", "help", cxxopts::value<bool>())
("kill", "kill the daemon", cxxopts::value<bool>())
("up", "put vpn up", cxxopts::value<bool>()) ("up", "put vpn up", cxxopts::value<bool>())
("down", "put vpn down", cxxopts::value<bool>()) ("down", "put vpn down", cxxopts::value<bool>())
("exit", "specify exit node address", cxxopts::value<std::string>()) ("exit", "specify exit node address", cxxopts::value<std::string>())
@ -77,6 +78,7 @@ main(int argc, char* argv[])
bool goUp = false; bool goUp = false;
bool goDown = false; bool goDown = false;
bool printStatus = false; bool printStatus = false;
bool killDaemon = false;
try try
{ {
const auto result = opts.parse(argc, argv); const auto result = opts.parse(argc, argv);
@ -102,6 +104,7 @@ main(int argc, char* argv[])
goUp = result.count("up") > 0; goUp = result.count("up") > 0;
goDown = result.count("down") > 0; goDown = result.count("down") > 0;
printStatus = result.count("status") > 0; printStatus = result.count("status") > 0;
killDaemon = result.count("kill") > 0;
if (result.count("endpoint") > 0) if (result.count("endpoint") > 0)
{ {
@ -127,7 +130,7 @@ main(int argc, char* argv[])
std::cout << ex.what() << std::endl; std::cout << ex.what() << std::endl;
return 1; 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; std::cout << opts.help() << std::endl;
return 1; return 1;
@ -161,6 +164,17 @@ main(int argc, char* argv[])
return 1; 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) if (printStatus)
{ {
const auto maybe_status = LMQ_Request(lmq, connID, "llarp.status"); const auto maybe_status = LMQ_Request(lmq, connID, "llarp.status");

View File

@ -93,8 +93,8 @@ namespace llarp::rpc
msg.send_reply(CreateJSONError("router is not running")); msg.send_reply(CreateJSONError("router is not running"));
return; return;
} }
m_Router->Stop();
msg.send_reply(CreateJSONResponse("OK")); msg.send_reply(CreateJSONResponse("OK"));
m_Router->Stop();
}) })
.add_request_command( .add_request_command(
"version", "version",