Commit 95326aca authored by Ashot's avatar Ashot
Browse files

Added restart functionality

parent 22b46f52
No related merge requests found
Showing with 64 additions and 1 deletion
+64 -1
......@@ -35,6 +35,7 @@
*/
static bool fDaemon;
std::string appPath;
void DetectShutdownThread(boost::thread_group* threadGroup)
{
......@@ -186,6 +187,21 @@ bool AppInit(int argc, char* argv[])
delete detectShutdownThread;
detectShutdownThread = NULL;
}
if (RestartRequested())
{
// If restart requested cleanup resources and run application again.
// The old one will be exited below.
PrepareShutdown();
CExplicitNetCleanup::callCleanup();
if (appPath.empty())
{
fprintf(stderr, "Error: Application name couldn't be detected.");
}
else
{
runCommand(appPath + " &");
}
}
Shutdown();
return fRet;
......@@ -193,6 +209,10 @@ bool AppInit(int argc, char* argv[])
int main(int argc, char* argv[])
{
if (argc > 0)
{
appPath = std::string(argv[0]);
}
SetupEnvironment();
// Connect crownd signal handlers
......
......@@ -122,10 +122,18 @@ void StartShutdown()
{
fRequestShutdown = true;
}
void StartRestart()
{
fRestartRequested = true;
}
bool ShutdownRequested()
{
return fRequestShutdown || fRestartRequested;
}
bool RestartRequested()
{
return fRestartRequested;
}
class CCoinsViewErrorCatcher : public CCoinsViewBacked
{
......
......@@ -18,7 +18,9 @@ class thread_group;
extern CWallet* pwalletMain;
void StartShutdown();
void StartRestart();
bool ShutdownRequested();
bool RestartRequested();
void Shutdown();
void PrepareShutdown();
bool AppInit2(boost::thread_group& threadGroup);
......
......@@ -235,6 +235,17 @@ Value stop(const Array& params, bool fHelp)
return "Crown server stopping";
}
Value restart(const Array& params, bool fHelp)
{
// Accept the deprecated and ignored 'detach' boolean argument
if (fHelp || params.size() > 1)
throw runtime_error(
"restart\n"
"\nRestart Crown server.");
// Restart will take long enough that the response should get back
StartRestart();
return "Crown server restarting";
}
/**
......@@ -247,6 +258,7 @@ static const CRPCCommand vRPCCommands[] =
{ "control", "getinfo", &getinfo, true, false, false }, /* uses wallet if enabled */
{ "control", "help", &help, true, true, false },
{ "control", "stop", &stop, true, true, false },
{ "control", "restart", &restart, true, true, false },
/* P2P networking */
{ "network", "getnetworkinfo", &getnetworkinfo, true, false, false },
......
......@@ -106,6 +106,9 @@ void RPCInstall()
} else {
RPCUpdate::statusObj.push_back(Pair("Install", "Done"));
}
// Restart crownd
StartRestart();
}
boost::filesystem::remove_all(dir);
......
......@@ -4,6 +4,7 @@
#include "updater.h"
#include "clientversion.h"
#include "util.h"
#include "chainparams.h"
#include <stdio.h>
#include <curl/curl.h>
......@@ -19,7 +20,6 @@ struct myprogress {
Updater updater;
Updater::Updater() :
updaterInfoUrl("https://raw.githubusercontent.com/ashotkhachatryan/crowncoin/systemnode/update1.json"),
os(Updater::UNKNOWN),
status(false),
version(-1),
......@@ -80,11 +80,28 @@ bool Updater::NeedToBeUpdated()
return false;
}
void Updater::SetJsonPath()
{
if (updaterInfoUrl.empty())
{
if (Params().NetworkID() == CBaseChainParams::MAIN)
{
updaterInfoUrl = "https://raw.githubusercontent.com/Crowndev/crowncoin/master/update.json";
}
else
{
updaterInfoUrl = "https://raw.githubusercontent.com/Crowndev/crowncoin/master/update_testnet.json";
}
}
std::cout << updaterInfoUrl << std::endl;
}
bool Updater::LoadUpdateInfo()
{
bool result = false;
CURL *curl;
std::string updateData;
SetJsonPath();
CURLcode res = CURLE_FAILED_INIT;
curl = curl_easy_init();
if (curl)
......
......@@ -55,6 +55,7 @@ private:
std::string updaterInfoUrl;
bool LoadUpdateInfo();
Value ParseJson(std::string info);
void SetJsonPath();
void SetOS();
bool NeedToBeUpdated();
int GetVersionFromJson();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment