mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Windows auto-updater invocation works... time to try an installer!
This commit is contained in:
parent
268ec8d1e0
commit
2203958798
3 changed files with 51 additions and 24 deletions
15
main.cpp
15
main.cpp
|
@ -641,7 +641,20 @@ int main(int argc,char **argv)
|
||||||
try {
|
try {
|
||||||
node = new Node(homeDir,port,controlPort);
|
node = new Node(homeDir,port,controlPort);
|
||||||
switch(node->run()) {
|
switch(node->run()) {
|
||||||
#ifndef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
case Node::NODE_RESTART_FOR_UPGRADE: {
|
||||||
|
const char *upgPath = node->reasonForTermination();
|
||||||
|
if (upgPath) {
|
||||||
|
if (!ZeroTierOneService::doStartUpgrade(std::string(upgPath))) {
|
||||||
|
exitCode = 3;
|
||||||
|
fprintf(stderr,"%s: abnormal termination: unable to execute update at %s (doStartUpgrade failed)\n",argv[0],(upgPath) ? upgPath : "(unknown path)");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
exitCode = 3;
|
||||||
|
fprintf(stderr,"%s: abnormal termination: unable to execute update at %s (no upgrade path provided)\n",argv[0],(upgPath) ? upgPath : "(unknown path)");
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
#else // __UNIX_LIKE__
|
||||||
case Node::NODE_RESTART_FOR_UPGRADE: {
|
case Node::NODE_RESTART_FOR_UPGRADE: {
|
||||||
const char *upgPath = node->reasonForTermination();
|
const char *upgPath = node->reasonForTermination();
|
||||||
// On Unix-type OSes we exec() right into the upgrade. This in turn will
|
// On Unix-type OSes we exec() right into the upgrade. This in turn will
|
||||||
|
|
|
@ -67,37 +67,21 @@ restart_node:
|
||||||
_node = (ZeroTier::Node *)0;
|
_node = (ZeroTier::Node *)0;
|
||||||
}
|
}
|
||||||
std::string msiPath;
|
std::string msiPath;
|
||||||
const char *msiPathTmp = n->reasonForTermination();
|
if (n) {
|
||||||
if (msiPathTmp)
|
const char *msiPathTmp = n->reasonForTermination();
|
||||||
msiPath = msiPathTmp;
|
if (msiPathTmp)
|
||||||
|
msiPath = msiPathTmp;
|
||||||
|
}
|
||||||
delete n;
|
delete n;
|
||||||
|
|
||||||
// Write a batch file to ensure the service is stopped
|
|
||||||
if ((!msiPath.length())||(!ZeroTier::Utils::fileExists(msiPath.c_str()))) {
|
if ((!msiPath.length())||(!ZeroTier::Utils::fileExists(msiPath.c_str()))) {
|
||||||
WriteEventLogEntry("auto-update failed: no msi path provided by Node",EVENTLOG_ERROR_TYPE);
|
WriteEventLogEntry("auto-update failed: no msi path provided by Node",EVENTLOG_ERROR_TYPE);
|
||||||
Sleep(5000);
|
Sleep(5000);
|
||||||
goto restart_node;
|
goto restart_node;
|
||||||
}
|
}
|
||||||
std::string bat(ZeroTier::ZT_DEFAULTS.defaultHomePath + "\\InstallAndRestartService.bat");
|
|
||||||
FILE *batf = fopen(bat.c_str(),"wb");
|
|
||||||
if (!batf) {
|
|
||||||
WriteEventLogEntry("auto-update failed: unable to create InstallAndRestartService.bat",EVENTLOG_ERROR_TYPE);
|
|
||||||
Sleep(5000);
|
|
||||||
goto restart_node;
|
|
||||||
}
|
|
||||||
fprintf(batf,"TIMEOUT.EXE /T 1 /NOBREAK\r\n");
|
|
||||||
fprintf(batf,"NET.EXE STOP \"ZeroTier One\"\r\n");
|
|
||||||
fprintf(batf,"MSIEXEC.EXE /i \"%s\" /qn\r\n",msiPath.c_str());
|
|
||||||
fprintf(batf,"NET.EXE START \"ZeroTier One\"\r\n");
|
|
||||||
fclose(batf);
|
|
||||||
|
|
||||||
// Execute updater, which will update and restart service
|
if (!doStartUpgrade(msiPath)) {
|
||||||
STARTUPINFOA si;
|
WriteEventLogEntry("auto-update failed: unable to create InstallAndRestartService.bat",EVENTLOG_ERROR_TYPE);
|
||||||
PROCESS_INFORMATION pi;
|
|
||||||
memset(&si,0,sizeof(si));
|
|
||||||
memset(&pi,0,sizeof(pi));
|
|
||||||
if (!CreateProcessA(NULL,const_cast <LPSTR>((std::string("CMD.EXE /c \"") + bat + "\"").c_str()),NULL,NULL,FALSE,CREATE_NO_WINDOW|CREATE_NEW_PROCESS_GROUP,NULL,NULL,&si,&pi)) {
|
|
||||||
WriteEventLogEntry("auto-update failed: unable to execute InstallAndRestartService.bat",EVENTLOG_ERROR_TYPE);
|
|
||||||
Sleep(5000);
|
Sleep(5000);
|
||||||
goto restart_node;
|
goto restart_node;
|
||||||
}
|
}
|
||||||
|
@ -133,6 +117,31 @@ restart_node:
|
||||||
_lock.unlock();
|
_lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ZeroTierOneService::doStartUpgrade(const std::string &msiPath)
|
||||||
|
{
|
||||||
|
std::string msiLog(ZeroTier::ZT_DEFAULTS.defaultHomePath + "\\LastUpdateLog.txt");
|
||||||
|
ZeroTier::Utils::rm(msiLog);
|
||||||
|
|
||||||
|
std::string bat(ZeroTier::ZT_DEFAULTS.defaultHomePath + "\\InstallAndRestartService.bat");
|
||||||
|
FILE *batf = fopen(bat.c_str(),"wb");
|
||||||
|
if (!batf)
|
||||||
|
return false;
|
||||||
|
fprintf(batf,"TIMEOUT.EXE /T 1 /NOBREAK\r\n");
|
||||||
|
fprintf(batf,"NET.EXE STOP \"ZeroTier One\"\r\n");
|
||||||
|
fprintf(batf,"MSIEXEC.EXE /i \"%s\" /l* \"%s\" /qn\r\n",msiPath.c_str(),msiLog.c_str());
|
||||||
|
fprintf(batf,"NET.EXE START \"ZeroTier One\"\r\n");
|
||||||
|
fclose(batf);
|
||||||
|
|
||||||
|
STARTUPINFOA si;
|
||||||
|
PROCESS_INFORMATION pi;
|
||||||
|
memset(&si,0,sizeof(si));
|
||||||
|
memset(&pi,0,sizeof(pi));
|
||||||
|
if (!CreateProcessA(NULL,const_cast <LPSTR>((std::string("CMD.EXE /c \"") + bat + "\"").c_str()),NULL,NULL,FALSE,CREATE_NO_WINDOW|CREATE_NEW_PROCESS_GROUP,NULL,NULL,&si,&pi))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ZeroTierOneService::OnStart(DWORD dwArgc, LPSTR *lpszArgv)
|
void ZeroTierOneService::OnStart(DWORD dwArgc, LPSTR *lpszArgv)
|
||||||
{
|
{
|
||||||
if (_node)
|
if (_node)
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#include "ServiceBase.h"
|
#include "ServiceBase.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "../../node/Node.hpp"
|
#include "../../node/Node.hpp"
|
||||||
#include "../../node/Defaults.hpp"
|
#include "../../node/Defaults.hpp"
|
||||||
#include "../../node/Thread.hpp"
|
#include "../../node/Thread.hpp"
|
||||||
|
@ -54,6 +56,9 @@ public:
|
||||||
void threadMain()
|
void threadMain()
|
||||||
throw();
|
throw();
|
||||||
|
|
||||||
|
// Returns false on failure.
|
||||||
|
static bool doStartUpgrade(const std::string &msiPath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnStart(DWORD dwArgc, PSTR *pszArgv);
|
virtual void OnStart(DWORD dwArgc, PSTR *pszArgv);
|
||||||
virtual void OnStop();
|
virtual void OnStop();
|
||||||
|
|
Loading…
Add table
Reference in a new issue