Skip to content

Commit

Permalink
Support logpath for daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
ckyang committed Jul 8, 2019
1 parent a4038d7 commit 01e9a14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
24 changes: 19 additions & 5 deletions daemon/ZilliqaDaemon_AWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ const string PRIVKEY_OPT = "--privk";
const string PUBKEY_OPT = "--pubk";
const string IP_OPT = "--address";
const string PORT_OPT = "--port";
const string LOGPATH_OPT = "--logpath";
const string SUSPEND_LAUNCH = "/run/zilliqa/SUSPEND_LAUNCH";
const string start_downloadScript = "python /run/zilliqa/downloadIncrDB.py";

unordered_map<int, string> PrivKey;
unordered_map<int, string> PubKey;
unordered_map<int, string> IP;
unordered_map<int, string> Port;
unordered_map<int, string> LogPath;
unordered_map<int, string> Path;

enum SyncType : unsigned int {
Expand Down Expand Up @@ -204,6 +206,15 @@ vector<pid_t> getProcIdByName(const string& procName, ofstream& log) {
fullLine = fullLine.substr(space_pos + 1);
continue;
}

if (token == LOGPATH_OPT) {
space_pos = (string::npos == fullLine.find('\0'))
? fullLine.size()
: fullLine.find('\0');
LogPath[id] = fullLine.substr(0, space_pos);
fullLine = fullLine.substr(space_pos + 1);
continue;
}
}

Path[id] = path;
Expand Down Expand Up @@ -270,8 +281,9 @@ bool DownloadPersistenceFromS3(ofstream& log) {
}

void StartNewProcess(const string& pubKey, const string& privKey,
const string& ip, const string& port, const string& path,
const bool& cseed, ofstream& log) {
const string& ip, const string& port,
const string& logPath, const string& path, bool cseed,
ofstream& log) {
log << currentTimeStamp().c_str() << "Create new Zilliqa process..." << endl;
signal(SIGCHLD, SIG_IGN);
pid_t pid;
Expand Down Expand Up @@ -307,7 +319,8 @@ void StartNewProcess(const string& pubKey, const string& privKey,
}
log << "\" "
<< execute(restart_zilliqa + " " + pubKey + " " + privKey + " " + ip +
" " + port + " " + syncType + " " + path + " 2>&1")
" " + port + " " + syncType + " " + logPath + " " + path +
" 2>&1")
<< " \"" << endl;
exit(0);
}
Expand Down Expand Up @@ -358,13 +371,14 @@ void MonitorProcess(unordered_map<string, vector<pid_t>>& pids,
pids[name].erase(it);
}

StartNewProcess(PubKey[pid], PrivKey[pid], IP[pid], Port[pid], Path[pid],
cseed, log);
StartNewProcess(PubKey[pid], PrivKey[pid], IP[pid], Port[pid],
LogPath[pid], Path[pid], cseed, log);
died.erase(pid);
PrivKey.erase(pid);
PubKey.erase(pid);
IP.erase(pid);
Port.erase(pid);
LogPath.erase(pid);
Path.erase(pid);
}
}
Expand Down
10 changes: 6 additions & 4 deletions tests/Zilliqa/daemon_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
PROJ_DIR = '/run/zilliqa'

def main():
if len(sys.argv) == 6:
run_restart(sys.argv[1],sys.argv[2],sys.argv[3], sys.argv[4], sys.argv[5], '')
if len(sys.argv) == 7:
run_restart(sys.argv[1],sys.argv[2],sys.argv[3], sys.argv[4], sys.argv[5], '', sys.argv[6])
elif len(sys.argv) == 6:
run_restart(sys.argv[1],sys.argv[2],sys.argv[3], sys.argv[4], sys.argv[5], '', './')
else:
print "Not enough args"

Expand All @@ -52,7 +54,7 @@ def isPortOpen(port):
sock.close()
return True

def run_restart(pubKey, privKey, ip, port, typ, path):
def run_restart(pubKey, privKey, ip, port, typ, path, logPath):
keypairs = []
keypairs.append(privKey + " " + pubKey)

Expand All @@ -62,7 +64,7 @@ def run_restart(pubKey, privKey, ip, port, typ, path):
for x in range(0, 1):
keypair = keypairs[x].split(" ")
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
os.system('cd ' + PROJ_DIR + '; ulimit -Sc unlimited; ulimit -Hc unlimited;' + path + 'zilliqa' + ' --privk ' + keypair[0] + ' --pubk ' + keypair[1] + ' --address ' + ip + ' --port ' + str(port) + ' --synctype ' + typ + ' --recovery >> ./error_log_zilliqa 2>&1')
os.system('cd ' + PROJ_DIR + '; ulimit -Sc unlimited; ulimit -Hc unlimited;' + path + 'zilliqa' + ' --privk ' + keypair[0] + ' --pubk ' + keypair[1] + ' --address ' + ip + ' --port ' + str(port) + ' --synctype ' + typ + ' --logpath ' + logPath + ' --recovery >> ./error_log_zilliqa 2>&1')

if __name__ == "__main__":
main()

0 comments on commit 01e9a14

Please sign in to comment.