Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/cellframe-node
  • evseev/cellframe-node
  • dmitry.puzyrkov/cellframe-node
  • MIKA83/cellframe-node
4 results
Show changes
Showing
with 929 additions and 93 deletions
#pragma once
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include <regex>
#include <unordered_map>
#include <memory>
#include <string>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iterator>
#include <numeric>
#include "../commands/AbstractCommand.h"
#include "../build_config.h"
namespace fs = std::filesystem;
enum ENetworkConfigType{
CFG_GENERAL,
CFG_MAINCHAIN,
CFG_ZEROCHAIN
};
enum ENetworkConfigState{
CFG_ON = 1,
CFG_OFF = 1 << 2,
CFG_TEMPLATE = 1 << 3,
};
enum EPathConfigType{
CFG_NODE = 0,
CFG_NODE_TEMPLATE,
CFG_NETWORK,
CFG_NETWORK_TEMPLATE
};
fs::path config_path(const std::string &netname, ENetworkConfigType type, ENetworkConfigState state = CFG_ON);
fs::path get_config_path(EPathConfigType pathType = CFG_NETWORK);
struct CellframeConfigurationFile {
CellframeConfigurationFile(fs::path filepath, int flags = 0);
bool exists(const std::string & group, const std::string & param, std::string *value = nullptr, int *line_no = nullptr, bool *group_exists = nullptr);
std::string set(const std::string & group, const std::string & param, const std::string &value);
void replace_placeholders(std::map<std::string, std::string> data);
bool save();
private:
fs::path path;
std::vector<std::string> lines;
int flags;
};
std::string substitute_variables(const std::string &string);
/*
Cellframe-Node Configuration controll tool.
2024 dmitry.puzrkov@demlabs.net
confctl tool uses .setup files with basic command and scripting capabilities to
initial setup of cellframe-node as intended by developers.
It will not alter any user settings if they exists.
// cellframe-node-config --init /path/to/cellframe-node.setup [-v | --verbose]
// .setup file syntax:
command param1 param2 param3 ....
*/
#include <algorithm>
#include <map>
#include <string>
#include <iostream>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include "commands/AbstractCommand.h"
#include <stdexcept>
#ifdef __linux__
#include <unistd.h> //Linux
#endif
#ifdef __APPLE__
#include <unistd.h> //Apple
#endif
#ifdef _WIN32
#include <winsock.h> //Windows
#include <windows.h>
#endif
namespace conftool {
std::string getHostName(void)
{
std::string res = "unknown";
char tmp[0x100];
if( gethostname(tmp, sizeof(tmp)) == 0 )
{
res = tmp;
}
return res;
}
#ifdef WIN32
LONG GetDWORDRegKey(HKEY hKey, const std::wstring &strValueName, DWORD &nValue, DWORD nDefaultValue)
{
nValue = nDefaultValue;
DWORD dwBufferSize(sizeof(DWORD));
DWORD nResult(0);
LONG nError = ::RegQueryValueExW(hKey,
strValueName.c_str(),
0,
NULL,
reinterpret_cast<LPBYTE>(&nResult),
&dwBufferSize);
if (ERROR_SUCCESS == nError)
{
nValue = nResult;
}
return nError;
}
LONG GetBoolRegKey(HKEY hKey, const std::wstring &strValueName, bool &bValue, bool bDefaultValue)
{
DWORD nDefValue((bDefaultValue) ? 1 : 0);
DWORD nResult(nDefValue);
LONG nError = GetDWORDRegKey(hKey, strValueName.c_str(), nResult, nDefValue);
if (ERROR_SUCCESS == nError)
{
bValue = (nResult != 0) ? true : false;
}
return nError;
}
LONG GetStringRegKey(HKEY hKey, const std::wstring &strValueName, std::wstring &strValue, const std::wstring &strDefaultValue)
{
strValue = strDefaultValue;
WCHAR szBuffer[512];
DWORD dwBufferSize = sizeof(szBuffer);
ULONG nError;
nError = RegQueryValueExW(hKey, strValueName.c_str(), 0, NULL, (LPBYTE)szBuffer, &dwBufferSize);
if (ERROR_SUCCESS == nError)
{
strValue = szBuffer;
}
return nError;
}
#endif
namespace fs = std::filesystem;
std::string getNodeConfigPath(std::string basepath){
#ifdef ANDROID
return basepath;
#endif
#ifdef __linux__
return "/opt/cellframe-node";
#endif
#ifdef __APPLE__
return "/Library/Application Support/CellframeNode";
#endif
#ifdef WIN32
HKEY hKey;
LONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 0, KEY_READ, &hKey);
bool bExistsAndSuccess (lRes == ERROR_SUCCESS);
bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);
std::wstring path;
GetStringRegKey(hKey, L"Common Documents", path, L"");
std::string stdpath(path.begin(),path.end());
return (std::filesystem::path{stdpath}/"cellframe-node").string();
#endif
}
std::string getNodeBinaryPath(){
#ifdef __linux__
return "/opt/cellframe-node/bin/";
#endif
#ifdef __APPLE__
return "/Applications/CellframeNode.app/Contents/MacOS/";
#endif
#ifdef WIN32
//HKLM "Software\${APP_NAME}" "Path"
HKEY hKey;
LONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\cellframe-node\\", 0, KEY_READ, &hKey);
bool bExistsAndSuccess (lRes == ERROR_SUCCESS);
bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);
std::wstring path;
GetStringRegKey(hKey, L"Path", path, L"");
std::string stdpath(path.begin(),path.end());
return (std::filesystem::path{stdpath}).string();
#endif
}
bool cmdOptionExists(char** begin, char** end, const std::string& option)
{
return std::find(begin, end, option) != end;
}
std::string getCmdOption(char ** begin, char ** end, const std::string & option_long, const std::string & option_short )
{
std::string option = option_long;
if (!cmdOptionExists(begin, end, option))
option = option_short;
char ** itr = std::find(begin, end, option);
if (itr != end && ++itr != end)
{
return std::string(*itr);
}
return std::string();
}
void print_help()
{
std::cout << "cellframe-node-config -h | --help" << std::endl;
std::cout << "\t prints this help message" << std::endl;
std::cout << "cellframe-node-config -s | --vars" << std::endl;
std::cout << "\t prints installation config variables." << std::endl;
std::cout << "cellframe-node-config -v | --verbose" << std::endl;
std::cout << "\t enable verbose output" << std::endl;
std::cout << "cellframe-node-config -d | --dry-run" << std::endl;
std::cout << "\t do not actual do a file-system commands" << std::endl;
std::cout << "cellframe-node-config -i | --init /path/to/cellframe-node.setup" << std::endl;
std::cout << "\t do initial configuration based on provided setup script" << std::endl;
std::cout << "cellframe-node-config -e | --exec <command> [and <command> [and <command>]...]" << std::endl;
std::cout << "\t execute provided commands. " << std::endl<< std::endl;
std::cout << "Allowed commands:" << std::endl;
std::cout << "\tnetwork <netname> ensure on|off" << std::endl;
std::cout << "\t\t enable | disable <netname> network" << std::endl;
std::cout << "\tnet_list all|on|off" << std::endl;
std::cout << "\t\t on - active networks. off - not active networks. all or nothing - all network" << std::endl;
std::cout << "\tconfig <configname> <section> <param> ensure <value>" << std::endl;
std::cout << "\t\t set a parameter <param> in section <section> in config <configname> to <value>" << std::endl;
std::cout << "\t\t Possible configs: \"cellframe-node\", \"<netname>\"" << std::endl;
std::cout << "\tservice enable" << std::endl;
std::cout << "\t\t set cellframe-node to autostart on boot" << std::endl;
std::cout << "\tservice disable" << std::endl;
std::cout << "\t\t remove cellframe-node from autostart on boot" << std::endl;
std::cout << "\tservice start" << std::endl;
std::cout << "\t\t start cellframe-node (if registred as service!)" << std::endl;
std::cout << "\tservice stop" << std::endl;
std::cout << "\t\t stop cellframe-node (if registred as service!)" << std::endl;
std::cout << "\tservice status" << std::endl;
std::cout << "\t\t get service & process statuses" << std::endl;
}
std::unique_ptr<CAbstractScriptCommand> parse_line_to_cmd(std::string line, int line_no, int flags) {
auto cmd = CAbstractScriptCommand::build(line);
if (!cmd)
throw std::invalid_argument("setup file line " + std::to_string(line_no) + " << {" +line +"} >> error: unknown command");
if (flags & F_VERBOSE) std::cout << "[V] Command: " << cmd->represent() <<std::endl;
return cmd;
}
std::vector <std::unique_ptr<CAbstractScriptCommand> > parse_setup_file(const std::string &init_file_name, int flags)
{
std::ifstream infile(init_file_name);
std::vector <std::unique_ptr<CAbstractScriptCommand> > res;
size_t line_num = 0;
if (flags & F_VERBOSE) std::cout << "[V] Parsing "<<init_file_name << " as setup-script" << std::endl;
for( std::string line; std::getline( infile, line ); line_num++)
{
trim(line);
line = line.substr(0, line.find("#")); //skip comments
if(line.empty()) continue; //skip empties
res.push_back(std::move(parse_line_to_cmd(line, line_num, flags)));
}
return res;
}
void print_cond_stack(std::vector < std::unique_ptr<CAbstractScriptCommand>> &condition_stack)
{
std::cout << "[VE] Condition stack: [";
for (auto &a : condition_stack)
std::cout << "{" << a->represent() << "} ";
std::cout << "] "<<std::endl;
}
bool run_commands(std::vector <std::unique_ptr<CAbstractScriptCommand>> &commands, int interactive, int flags)
{
//dry_run for conditions check
std::vector<std::unique_ptr <CAbstractScriptCommand>> condition_stack;
for (auto &cmd : commands)
{
if (cmd->is_condition_open() || cmd->is_condition_close()) {
if (cmd->is_condition_open()) condition_stack.push_back(std::move(cmd));
else if (cmd->is_condition_close()) condition_stack.pop_back();
if (flags & F_VERBOSE) print_cond_stack(condition_stack);
continue;
}
if (condition_stack.size() > 0)
{
//execute only of condition passed
if (condition_stack.back()->execute(!interactive, flags)) cmd->execute(!interactive, flags);
} else
{
//no condition in stack, exec command
cmd->execute(!interactive, flags);
}
}
return true;
}
void populate_variables(std::string basepath)
{
variable_storage["HOST_OS"] = HOST_OS;
variable_storage["HOSTNAME"] = getHostName();
variable_storage["CONFIGS_PATH"] = getNodeConfigPath(basepath);
variable_storage["NODE_BINARY_PATH"] = getNodeBinaryPath();
}
int init_configs(std::string init_file_name, int flags, int non_interactive)
{
if (init_file_name.empty())
{
std::cout << "No setup file provided for init procedure, see --help" << std::endl;
return -1;
}
if (!fs::exists(fs::path{init_file_name}))
{
std::cout << "Setup file " << init_file_name << " not found" << std::endl;
return -1;
}
std::cout << "Cellframe-node configs install path: " << variable_storage["CONFIGS_PATH"] << std::endl;
auto commands = parse_setup_file(init_file_name, flags);
run_commands(commands, !non_interactive, flags);
return 0;
}
}
using namespace conftool;
int main(int argc, char * argv[])
{
populate_variables(""); //basepath used only for android
if(cmdOptionExists(argv, argv+argc, "-h") || cmdOptionExists(argv, argv+argc, "--help"))
{
print_help();
return 0;
}
int flags = 0;
if (cmdOptionExists(argv, argv+argc, "--verbose") || cmdOptionExists(argv, argv+argc, "-v")) flags = flags | F_VERBOSE;
if (cmdOptionExists(argv, argv+argc, "--vars") || cmdOptionExists(argv, argv+argc, "-s")) {
for (auto v: variable_storage)
{
std::cout << v.first << "="<<v.second<<std::endl;
}
return 0;
}
if (cmdOptionExists(argv, argv+argc, "--dryrun") || cmdOptionExists(argv, argv+argc, "-d")) flags = flags | F_DRYRUN;
if(cmdOptionExists(argv, argv+argc, "-i") || cmdOptionExists(argv, argv+argc, "--init"))
{
//--init already exists, give me filename
std::string init_file_name = getCmdOption(argv, argv+argc, "--init", "-i");
std::string node_intall_path = getCmdOption(argv, argv+argc, "--path", "-p");
if (!node_intall_path.empty())
{
variable_storage["CONFIGS_PATH"] = node_intall_path;
}
bool non_interactive = cmdOptionExists(argv, argv+argc, "--non-interactive") || cmdOptionExists(argv, argv+argc, "-n");
return init_configs(init_file_name, flags, non_interactive);
}
if(cmdOptionExists(argv, argv+argc, "-e") || cmdOptionExists(argv, argv+argc, "--exec"))
{
std::string option = "-e";
if (cmdOptionExists(argv, argv+argc, "--exec")) option = "--exec";
auto pos = std::find(argv, argv+argc, option);
std::vector <std::string> commands_lines;
std::string curr_cmd;
while (pos != argv+argc-1)
{
pos++;
if (std::string(*pos) == "and") { commands_lines.push_back(curr_cmd); curr_cmd = ""; continue; }
curr_cmd += *pos;
curr_cmd += " ";
}
commands_lines.push_back(curr_cmd);
std::vector <std::unique_ptr<CAbstractScriptCommand> > script_cmds;
for (int i =0; i< commands_lines.size(); i++) {
script_cmds.push_back(parse_line_to_cmd(commands_lines[i], i, flags));
}
run_commands(script_cmds, false, flags);
return 0;
}
print_help();
return 0;
}
extern "C" int callSec (char *tool, char* args[]);
extern "C" int callSecScript(char *script);
\ No newline at end of file
#ifdef __APPLE__
#import <Foundation/Foundation.h>
#include "Foundation/NSString.h"
#include "Foundation/NSAppleScript.h"
#
int callSec (char *tool, char* args[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Create authorization reference
AuthorizationRef authorizationRef;
OSStatus status;
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef);
// Run the tool using the authorization reference
FILE *pipe = NULL;
status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe);
if (status == errAuthorizationSuccess) {
return 0;
} else {
NSLog(@"Authorization Result Code: %d", status);
}
[pool drain];
return -1;
}
int callSecScript(char *script)
{
NSDictionary *error = [NSDictionary new];
NSString *appleScriptString = @"do shell script ";
appleScriptString = [appleScriptString stringByAppendingString:@"\""];
appleScriptString = [appleScriptString stringByAppendingString:[NSString stringWithUTF8String: script]];
appleScriptString = [appleScriptString stringByAppendingString:@"\""];
appleScriptString = [appleScriptString stringByAppendingString:@" with administrator privileges"];
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:appleScriptString];
NSString *result;
result = [[appleScript executeAndReturnError: &error] stringValue];
return 0;
}
#endif
\ No newline at end of file
#include <algorithm>
#include <map>
#include <string>
#include <iostream>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include <stdexcept>
enum EServiceStatus{
SERVICE_ENABLED = 1 << 0,
PROCESS_RUNNING = 1 << 2,
};
struct CServiceControl
{
static bool enable();
static bool disable();
static unsigned int serviceStatus();
static bool start();
static bool stop();
static bool restart();
};
\ No newline at end of file
#ifdef __linux__
#include "service.h"
#include "../commands/AbstractCommand.h"
bool CServiceControl::enable(){
std::string cmd = "systemctl enable " + (std::filesystem::path{variable_storage["CONFIGS_PATH"]}/"share"/"cellframe-node.service > /dev/null").string();
int res = std::system(cmd.c_str());
return res == 0 ? true : false;
}
bool CServiceControl::disable()
{
std::string cmd = "systemctl disable cellframe-node.service > /dev/null";
int res = std::system(cmd.c_str());
return res == 0 ? true : false;
}
unsigned int CServiceControl::serviceStatus()
{
unsigned int status = 0;
std::string cmd = "systemctl is-enabled cellframe-node.service > /dev/null";
int res = std::system(cmd.c_str());
if (res == 0)
{
status |= SERVICE_ENABLED;
}
cmd = "pgrep -x cellframe-node > /dev/null";
res = std::system(cmd.c_str());
if (res == 0)
{
status |= PROCESS_RUNNING;
}
return (unsigned int)status;
}
bool CServiceControl::start()
{
std::string cmd = "systemctl start cellframe-node.service > /dev/null";
int res = std::system(cmd.c_str());
return res == 0 ? true : false;
}
bool CServiceControl::stop()
{
std::string cmd = "systemctl stop cellframe-node.service > /dev/null";
int res = std::system(cmd.c_str());
return res == 0 ? true : false;
}
bool CServiceControl::restart()
{
std::string cmd = "systemctl restart cellframe-node.service > /dev/null";
int res = std::system(cmd.c_str());
return res == 0 ? true : false;
}
#endif
#ifdef __APPLE__
#include "service.h"
#include "../commands/AbstractCommand.h"
#include "macos_auth.h"
bool CServiceControl::enable()
{
int res = callSecScript("launchctl load -w /Library/LaunchDaemons/com.demlabs.cellframe-node.plist");
return res == 0 ? true : false;
}
bool CServiceControl::disable()
{
int res = callSecScript("launchctl unload -w /Library/LaunchDaemons/com.demlabs.cellframe-node.plist");
return res == 0 ? true : false;
}
unsigned int CServiceControl::serviceStatus()
{
unsigned int status = 0;
std::string cmd = std::string();
int res = std::system("launchctl print system/com.demlabs.cellframe-node > /dev/null");
if (res == 0)
{
status |= SERVICE_ENABLED;
}
cmd = "pgrep -x cellframe-node > /dev/null";
res = std::system(cmd.c_str());
if (res == 0)
{
status |= PROCESS_RUNNING;
}
return (unsigned int)status;
}
bool CServiceControl::start()
{
return enable();
}
bool CServiceControl::stop()
{
return disable();
}
bool CServiceControl::restart()
{
stop();
start();
return true;
}
#endif
#ifdef WIN32
#include "service.h"
#include "../commands/AbstractCommand.h"
#include <windows.h>
#include <windowsx.h>
#include <shlobj.h>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
bool isProcessRunning(const TCHAR* const executableName) {
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (!Process32First(snapshot, &entry)) {
CloseHandle(snapshot);
return false;
}
do {
if (!_tcsicmp(entry.szExeFile, executableName)) {
CloseHandle(snapshot);
return true;
}
} while (Process32Next(snapshot, &entry));
CloseHandle(snapshot);
return false;
}
int runShellAdmin(std::string app, std::string cmd)
{
// Launch itself as admin
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpVerb = "runas";
sei.lpFile = app.c_str();
sei.lpParameters = cmd.c_str();
sei.hwnd = NULL;
sei.nShow = SW_HIDE;
if (!ShellExecuteEx(&sei))
{
DWORD dwError = GetLastError();
if (dwError == ERROR_CANCELLED)
{
std::cout << "End user did not allow elevation" << std::endl;
return -1;
}
std::cout << "Exec failed" << dwError<< std::endl;
}
WaitForSingleObject(sei.hProcess,INFINITE);
long unsigned int rc;
GetExitCodeProcess(sei.hProcess, &rc);
return rc;
}
bool CServiceControl::enable()
{
auto nodebinpath = std::filesystem::path{variable_storage["NODE_BINARY_PATH"]}/"cellframe-node.exe";
std::string cmd = std::string("/Create /F /RL highest /SC onlogon /TR \"'") + nodebinpath.string() + "'\" /TN CellframeNode";
long unsigned int res = runShellAdmin("schtasks.exe", cmd);
return res == 0 ? true : false;
}
bool CServiceControl::disable()
{
std::string cmd = std::string("/Delete /TN CellframeNode /f");
long unsigned int res = runShellAdmin("schtasks.exe", cmd);
return res == 0 ? true : false;
}
unsigned int CServiceControl::serviceStatus()
{
unsigned int status = 0;
std::string cmd = std::string("schtasks /query /TN CellframeNode");
int res = std::system(cmd.c_str());
if (res == 0)
{
status |= SERVICE_ENABLED;
}
if (isProcessRunning("cellframe-node.exe"))
{
std::cout << "proc running" << std::endl;
status |= PROCESS_RUNNING;
}
return (unsigned)status;
}
bool CServiceControl::start()
{
std::string cmd = std::string("/run /TN CellframeNode");
long unsigned int res = runShellAdmin("schtasks.exe", cmd);
return res==0 ? true : false;
}
bool CServiceControl::stop()
{
std::string cmd = std::string("/IM cellframe-node.exe /F");
long unsigned int res = runShellAdmin("taskkill.exe", cmd);
return res==0 ? true : false;
}
bool CServiceControl::restart()
{
stop();
start();
return true;
}
#endif
\ No newline at end of file
Subproject commit ac7a19608031dd5a8947dce8a034eddbb2c0aa93
#!/bin/bash -e
. /usr/share/debconf/confmodule
case "$1" in
reconfigure|configure)
;;
*)
echo "config called with unknown argument \`$1'" >&2
exit 1
;;
esac
#!/bin/bash -e
. /usr/share/debconf/confmodule
DAP_CHAINS_NAME="kelvin"
DAP_APP_NAME="$DAP_CHAINS_NAME-node"
DAP_PREFIX="/opt/$DAP_APP_NAME"
DAP_CFG_TPL="$DAP_PREFIX/share/configs/$DAP_APP_NAME.cfg.tpl"
DAP_CFG_TESTNET_TPL="$DAP_PREFIX/share/configs/network/$DAP_CHAINS_NAME-testnet.cfg.tpl"
# Store write config to new if present smth
DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg"
DAP_CFG_TESTNET="$DAP_PREFIX/etc/network/$DAP_CHAINS_NAME-testnet.cfg"
# Init node config
if [ -e "$DAP_CFG" ]; then
DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg.dpkg-new"
else
DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg"
fi
cat $DAP_CFG_TPL > $DAP_CFG || true
mkdir -p $DAP_PREFIX/var/lib/network/kelvin-testnet/zerochain/ || true
mkdir -p $DAP_PREFIX/var/lib/network/kelvin-testnet/plasma/ || true
mkdir -p $DAP_PREFIX/var/log || true
# Init testnet
if [ -e "$DAP_CFG_TESTNET" ]; then
DAP_CFG_TESTNET="$DAP_PREFIX/etc/network/$DAP_CHAINS_NAME-testnet.cfg.dpkg-new"
else
DAP_CFG_TESTNET="$DAP_PREFIX/etc/network/$DAP_CHAINS_NAME-testnet.cfg"
fi
#echo "cat $DAP_CFG_TESTNET_TPL > $DAP_CFG_TESTNET || true"
cat $DAP_CFG_TESTNET_TPL > $DAP_CFG_TESTNET || true
cat /etc/passwd| grep kelvin-node || adduser --system --no-create-home --group --home /opt/kelvin-node kelvin-node
if [ -e "/etc/systemd/user/$DAP_APP_NAME.service" ]; then
echo "Restart $DAP_APP_NAME to implement changes"
else
ln -sf $DAP_PREFIX/share/$DAP_APP_NAME.service /etc/systemd/user/$DAP_APP_NAME.service
systemctl --system enable $DAP_PREFIX/share/$DAP_APP_NAME.service
# systemctl --system start $DAP_APP_NAME
fi
#USERMAN=`users | awk '{print $1}'`
adduser --system --no-create-home --group --home /opt/kelvin-node kelvin-node
#usermod -aG $DAP_CHAINS_NAME `users | awk '{print $1}'`
for username in $(cat /etc/passwd | grep "/home" | cut -d ':' -f1); do
usermod -aG kelvin-node $username
done
mkdir -p $DAP_PREFIX/var/{run,lib/ca,lib/wallet,lib/global_db}
touch $DAP_PREFIX/var/run/kelvin-node.pid
#chown -R $USERMAN:$USERMAN $DAP_PREFIX
for filename in $(find $DAP_PREFIX); do
if [ -d $filename ]; then
chmod 0775 $filename
else
chmod 0664 $filename
fi
done
chmod 0774 $DAP_PREFIX/bin/*
echo "For start $DAP_APP_NAME - run 'systemctl start $DAP_APP_NAME'"
#! /bin/bash -e
if [ "$1" == "purge" ] && [ -e /usr/share/debconf/confmodule ] ; then
. /usr/share/debconf/confmodule
db_purge
fi
GROUP_RM="kelvin-node"
systemctl stop kelvin-node || true
systemctl disable kelvin-node || true
#for username in `cat /etc/passwd | grep "/home" | cut -d ':' -f1`; do
# gpasswd -d $username $GROUP_RM || true
#done
#rm -r /opt/kelvin-node || true
#groupdel kelvin-node || true
#userdel kelvin-node || true
Subproject commit 293cc6c4038ea85c6819d9f847ad3802b02162b5
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQSuBF2wVKURDADcrtceU38c39lQkRsIGUCc91dquVqrFmrNwhd36zfo6w1EjObg
IXyM7aDYm4lsnn/XwQo9m03JYsgyHtpg18h3taAkbbaSQ2CTFkRfPMZphaj2I1xM
+rm6VMPxSU4DpLwrpsfgx0xMs68RiiZbgluytIYn6mxfjC3vLU1dQuxqQ1f541tr
EzJtQi5xbZQZa8LgwYQ48KPhySViSzVD6EZmPKQAz5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PnIoBPszMv92BEVF/8x+i6n9u6TeFn
cjd731/1E5MJF17Xmv4ht9NEpcjtcO8HJL0iNhXorjvDAAMGDACLrx84OL3Fm576
4/0gAkUM/gHSNisGenqep5kYbOOhGfvgyETZcwRp1/Bm7hCrADqK+fWlMR0S+X6N
+gUycjgo2vyJOepmjTr2au8WO4Gy7zw03DMDhCTAij04zqryHnRRjIrsolwocRkY
CN6dlAl8DbFW4I/KV/8544katYhNGdYOq65PBoO87IaMu2p6OGqUFNOY19XJN+4e
eufutWGN5hocurPhh/gmrRPAc209KlcMPnB25Aj0CJqswiD/Nzp67MtmSL6oNf9u
0OIv23g9lLLvRYatMswO79wdqekKlm4+f/2VDMjnMl1gqzTdu0nZ6m2d+aCCPPck
ND7QoKyjfqQX4BMgkxBrt4d5Z+FHNTtb49eDgWfHoTJxYdqLq+eFZDEiG3XNbrEP
8JhrXO7+afGHOg+h4YUZmpX7TKaFI8tFiBDonOBwIaW0daoCvBi/QQa1Jv/8CsrX
P/EUMfxygiKtibhuEGAVsb2CY80axdTAT2A8jB2+rJoL1WVGK1SIfgQYEQoAJhYh
BDANtUaz69PDOZf93md9jb3bJJ/bBQJdsFSlAhsMBQkDwmcAAAoJEGd9jb3bJJ/b
Ze8A/0LFd9o7tG1tCX8IXqaXQ3Czf5T+QF3Ca2L/MENHa4uDAQCDJO09qp2aBtdK
11x5LzB8Cp46zmCeFgpq3KyfKj4v3w==
=MUUP
-----END PGP PUBLIC KEY BLOCK-----
[Unit]
Description=Cellframe DiagTool
After=network-online.target
Wants=network-online.target
[Service]
WorkingDirectory=/opt/cellframe-node/
ExecStart=/opt/cellframe-node/bin/cellframe-diagtool &
ExecStop=/bin/kill -SIGTERM $MAINPID
Restart=always
User=root
Group=root
RestartSec=10
LogNamespace=cellframe
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_IPC_LOCK CAP_KILL CAP_LEASE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_RAWIO CAP_SYSLOG CAP_WAKE_ALARM CAP_SYS_RESOURCE CAP_DAC_READ_SEARCH
[Install]
WantedBy=multi-user.target
[Unit]
Description=Cellframe Node
After=network-online.target
Wants=network-online.target
[Service]
WorkingDirectory=/opt/cellframe-node
ExecStart=/opt/cellframe-node/bin/cellframe-node &
ExecStop=/bin/kill -SIGTERM $MAINPID
Restart=always
User=root
Group=root
RestartSec=10
LogNamespace=cellframe
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_IPC_LOCK CAP_KILL CAP_LEASE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_RAWIO CAP_SYSLOG CAP_WAKE_ALARM CAP_SYS_RESOURCE CAP_DAC_READ_SEARCH
Environment="ASAN_OPTIONS=strict_string_checks=1:detect_invalid_pointer_pairs=2:debug=1:atexit=1:abort_on_error=1:log_path=asanlog.txt"
[Install]
WantedBy=multi-user.target
[Unit]
Description=Kelvin Node
After=network.target
Description=Cellframe Node
After=network-online.target
Wants=network-online.target
[Service]
Type=forking
OOMScoreAdjust=-1000
PIDFile=/opt/kelvin-node/var/run/kelvin-node.pid
WorkingDirectory=/opt/kelvin-node
ExecStart=/opt/kelvin-node/bin/kelvin-node -D
ExecStop=/opt/kelvin-node/bin/kelvin-node --stop
WorkingDirectory=/opt/cellframe-node
ExecStart=/opt/cellframe-node/bin/cellframe-node &
ExecStop=/bin/kill -SIGTERM $MAINPID
Restart=always
User=kelvin-node
Group=kelvin-node
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_IPC_LOCK CAP_KILL CAP_LEASE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_RAWIO CAP_SYSLOG CAP_WAKE_ALARM
User=root
Group=root
RestartSec=10
LogNamespace=cellframe
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_IPC_LOCK CAP_KILL CAP_LEASE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_RAWIO CAP_SYSLOG CAP_WAKE_ALARM CAP_SYS_RESOURCE CAP_DAC_READ_SEARCH
[Install]
[Install]
WantedBy=multi-user.target
[Unit]
Description=Cellframe Node
After=network-online.target
Wants=network-online.target
[Service]
WorkingDirectory=/opt/cellframe-node
ExecStart=/opt/cellframe-node/bin/cellframe-node &
ExecStop=/bin/kill -SIGTERM $MAINPID
Restart=always
User=root
Group=root
RestartSec=10
LogNamespace=cellframe
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_IPC_LOCK CAP_KILL CAP_LEASE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_RAWIO CAP_SYSLOG CAP_WAKE_ALARM CAP_SYS_RESOURCE CAP_DAC_READ_SEARCH
Environment="TSAN_OPTIONS="
[Install]
WantedBy=multi-user.target
[Unit]
Description=Cellframe Node
After=network-online.target
Wants=network-online.target
[Service]
WorkingDirectory=/opt/cellframe-node
ExecStart=/opt/cellframe-node/bin/cellframe-node &
ExecStop=/bin/kill -SIGTERM $MAINPID
Restart=always
User=root
Group=root
RestartSec=10
LogNamespace=cellframe
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_IPC_LOCK CAP_KILL CAP_LEASE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_RAWIO CAP_SYSLOG CAP_WAKE_ALARM CAP_SYS_RESOURCE CAP_DAC_READ_SEARCH
Environment="UBSAN_OPTIONS="
[Install]
WantedBy=multi-user.target
[Unit]
Description=CellframeNode Tray
PartOf=graphical-session.target
After=graphical-session.target
[Service]
Type=exec
Restart=no
ExecStart=/opt/cellframe-node/bin/cellframe-diagtool --tray
ExecStop=/bin/kill -SIGTERM $MAINPID
[Install]
WantedBy=graphical-session.target
\ No newline at end of file