Skip to content
Snippets Groups Projects
Commit 82d48a93 authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov
Browse files

[+] Debian files

[+] Default configs
[*] New main.c
parent 59429151
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,36 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 11)
SET (CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET (CPACK_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
SET (DESTDIR "/opt/${PROJECT_NAME}")
SET( CPACK_GENERATOR "DEB")
SET( CPACK_PACKAGE_NAME "${PROJECT_NAME}")
SET( CPACK_PACKAGE_VERSION_MAJOR 0)
SET( CPACK_PACKAGE_VERSION_MINOR 1)
SET( CPACK_PACKAGE_VERSION_PATCH 1)
SET( CPACK_SYSTEM_NAME "debian-9.5-amd64")
SET( CPACK_DEBIAN_PACKAGE_MAINTAINER "Dmitriy Gerasimov <naeper@ldemlabs.net>" )
SET( CPACK_DEBIAN_PACKAGE_DESCRIPTION_SUMMARY "Kelvin Blockchain Node software" )
SET( CPACK_DEBIAN_PACKAGE_DESCRIPTION "DAP server" )
SET( CPACK_DEBIAN_PACKAGE_SECTION "extra")
SET( CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64" )
SET( CPACK_DEBIAN_PACKAGE_DEPENDS "debconf (>=1.5), dpkg (>=1.17), bash (>=4)")
SET( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
SET( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${CMAKE_CURRENT_SOURCE_DIR}/../debian/postinst;${CMAKE_CURRENT_SOURCE_DIR}/../debian/postrm;${CMAKE_CURRENT_SOURCE_DIR}/../debian/templates;${CMAKE_CURRENT_SOURCE_DIR}/../debian/config;")
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../dist/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*")
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ )
INCLUDE(CPack)
add_definitions ("-DDAP_SERVER")
add_definitions ("-DNODE_NETNAME=\"kelvin\"")
add_subdirectory(libdap)
add_subdirectory(libdap-server-core)
......@@ -41,8 +70,7 @@ include_directories("${INCLUDE_DIRECTORIES} ${dap_core_server_INCLUDE_DIRS}")
#add_definitions ("${dap_stream_DEFINITIONS}")
file(GLOB SERVER_SRCS *.c)
set(SOURCES sources/main.c sources/node_manager.c )
set(HEADERS sources/node_manager.h)
set(SOURCES sources/main.c )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
......
[general]
port = 49123
#!/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_APP_NAME="kelvin-node"
DAP_PREFIX="/opt/$DAP_APP_NAME"
DAP_CFG_TPL="$DAP_PREFIX/share/$DAP_APP_NAME.cfg.tpl"
# Store write config to new if present smth
DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg"
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
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
systemctl --system start $DAP_APP_NAME
fi
#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
\ No newline at end of file
#!/usr/bin/make -f
override_dh_fixperms:
dh_fixperms -X/opt/kelvin-node
override_dh_auto_install:
dh_auto_install -- prefix=/opt/kelvin-node
%:
# dh $@ --with=systemd
dh $@
[network]
listen_address=0.0.0.0
listen_port=8003
[resources]
pid_path=/opt/kelvin-node/run/kelvin-node.pid
log_file=/opt/kelvin-node/log/kelvin-node.log
[www]
www_root=/opt/dapserver/www
main_url_enabled=true
[configure]
TTL_session_key=600
[blockchain]
network-type=testing
wallets=/opt/kelvin-node/var/wallets/
default-wallet=defaul
t
\ No newline at end of file
[Unit]
Description=Demlabs Applications Protocol Server
After=network.target
[Service]
Type=forking
OOMScoreAdjust=-1000
PIDFile=/opt/dapserver/run/dapserver.pid
WorkingDirectory=/opt/dapserver/
ExecStart=/opt/dapserver/bin/DapServer -D
ExecStop=/opt/dapserver/bin/DapServer --stop
[Install]
WantedBy=multi-user.target
/*
Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc
All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
#include <unistd.h>
#include <sys/types.h>
#include <getopt.h>
#include <signal.h>
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
#define LOG_TAG "main"
DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
#include "dap_server.h"
#include "dap_http.h"
#include "dap_http_folder.h"
#include "dap_enc.h"
#include "dap_enc_ks.h"
#include "dap_enc_http.h"
You should have received a copy of the GNU Lesser General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef DAP_MOD_SERVER_LIST
#include "mods/serverlist/server_list.h"
#endif
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "uthash.h"
#include "dap_http.h"
#include "stream_session.h"
#include "stream.h"
#include "node_manager.h"
#include "stream_ctl.h"
#include "dap_stream_ch_vpn.h"
#include "dap_common.h"
#include "db_http.h"
#include "db_http_file.h"
#include "auth/db_auth.h"
#include "dap_server_client.h"
#include "db_core.h"
#include "dap_http_simple.h"
#include "dap_process_manager.h"
#include "sig_unix_handler.h"
#include "dap_server_config.h"
#include "dap_traffic_track.h"
#define SERVER_FILENAME NODE_NETNAME "-node"
#define SERVER_PREFIX="/opt/"SERVER_FILENAME
#define CONFIG_DIR_PATH SERVER_PREFIX"/etc"
#define DEFAULT_PID_FILE_PATH SERVER_PREFIX"/run/dapserver.pid"
#define ENC_HTTP_URL "/enc_init"
#define STREAM_URL "/stream_url"
#define SLIST_URL "/nodelist"
#define MAIN_URL "/"
void parse_args(int argc, const char * argv[]);
void exit_if_server_already_running(void);
static dap_config_t * g_config;
int main(int argc, const char * argv[])
{
dap_server_t * sh; // DAP Server instance
int rc;
if((g_config = dap_server_config_init(CONFIG_DIR_PATH)) == NULL) {
log_it(L_CRITICAL,"Can't init general configurations module");
return -1;
}
if(dap_common_init(SERVER_FILENAME"_logs.txt")!=0){
log_it(L_CRITICAL,"Can't init common functions module");
return -2;
}
/*struct ev_loop *repeat_loop;
ev_timer timeout_watcher;
parse_args(argc, argv);
static void repeat_cb (EV_P_ ev_timer *w, int revents){
puts("repeat");
}*/
// change to dap_config_get_item_int_default when it's will be possible
size_t thread_cnt = (size_t)sysconf(_SC_NPROCESSORS_ONLN);
const char *s_thrd_cnt = dap_config_get_item_str(g_config, "configure", "threads_cnt");
if(s_thrd_cnt != NULL)
thread_cnt = (size_t)atoi(s_thrd_cnt);
if(dap_server_init(thread_cnt)!=0){
log_it(L_CRITICAL,"Can't init socket server module");
return -4;
}
if(dap_http_init()!=0){
log_it(L_CRITICAL,"Can't init http server module");
return -5;
}
if(dap_http_folder_init()!=0){
log_it(L_CRITICAL,"Can't init http server module");
return -55;
}
if(dap_enc_init() !=0){
log_it(L_CRITICAL,"Can't init encryption module");
return -56;
}
if(dap_enc_ks_init() !=0){
log_it(L_CRITICAL,"Can't init encryption key storage module");
return -57;
}
if(enc_http_init() !=0){
log_it(L_CRITICAL,"Can't init encryption http session storage module");
return -58;
}
if(stream_init() != 0 ){
log_it(L_CRITICAL,"Can't init stream server module");
return -6;
}
int main(int argc, char **argv) {
if (stream_ctl_init() != 0 ){
log_it(L_CRITICAL,"Can't init stream control module");
return -7;
}
/* repeat_loop = EV_DEFAULT;
ev_timer_init (&timeout_watcher, repeat_cb, 3, 3);
ev_timer_start (repeat_loop, &timeout_watcher);
ev_run (repeat_loop, 0);*/
if ( dap_http_simple_module_init() != 0 ) {
log_it(L_CRITICAL,"Can't init http simple module");
return -9;
}
if (sig_unix_handler_init(dap_config_get_item_str_default(g_config,
"resources",
"pid_path",
DEFAULT_PID_FILE_PATH)) != 0) {
log_it(L_CRITICAL,"Can't init sig unix handler module");
return -9;
}
printf("Kelvin Node version 0.1 \n");
if (argc > 1)
{
char *l_config_name = strdup(argv[1]);
save_process_pid_in_file(dap_config_get_item_str_default(g_config,
"resources",
"pid_path",
SERVER_PREFIX"/run/dapserver.pid"));
sh = dap_server_listen((dap_config_get_item_str_default(g_config,
"network",
"listen_address",
"0.0.0.0")),
dap_config_get_item_int32(g_config, "network", "listen_port"), // TODO DEFAULT PORT
DAP_SERVER_TCP);
if(sh) {
bool is_traffick_track_enable = // TODO change to get_item_bool_feault
strcmp(dap_config_get_item_str_default(g_config, "traffic_track", "enable", "false"), "true") == 0;
if(is_traffick_track_enable) {
time_t timeout = // TODO add default timeout (get_item_int32_default)
dap_config_get_item_int32(g_config, "traffic_track", "callback_timeout");
dap_traffic_track_init(sh, timeout);
dap_traffic_callback_set(db_auth_traffic_track_callback);
}
// Init HTTP-specific values
dap_http_new(sh,SERVER_FILENAME "DAPServer/1.0 (QNX)");
dap_http_folder_add(DAP_HTTP(sh), "/",
dap_config_get_item_str_default(g_config,
"resources",
"www_root",
"/opt/dapserver/www"));
server_list_add_proc(DAP_HTTP(sh), SLIST_URL);
db_http_add_proc(DAP_HTTP(sh), DB_URL);
db_http_file_proc_add(DAP_HTTP(sh), DB_HTTP_FILE_URL);
stream_add_proc_http(DAP_HTTP(sh), STREAM_URL);
stream_ctl_add_proc(DAP_HTTP(sh), CTL_URL);
enc_http_add_proc(DAP_HTTP(sh), ENC_HTTP_URL);
ch_sf_init(dap_config_get_item_str_default(g_config, "network", "vpn_addr", "10.0.0.0"),
dap_config_get_item_str_default(g_config, "network", "vpn_mask", "255.255.255.0"));
// Endless loop for server's requests processing
rc = dap_server_loop(sh);
// After loop exit actions
log_it(rc?L_CRITICAL:L_NOTICE,"Server loop stopped with return code %d",rc);
// Deinit modules
stream_deinit();
stream_ctl_deinit();
db_http_deinit();
dap_http_folder_deinit();
dap_http_deinit();
dap_server_deinit();
db_core_deinit();
dap_enc_ks_deinit();
dap_common_deinit();
server_list_module_deinit();
return rc*10;
}
}
node_manager_init();
void parse_args(int argc, const char * argv[]) {
int opt, option_index = 0, is_daemon = 0;
struct option long_options[] = {
{"stop", 0, NULL, 0},
{0, 0, NULL, 0} // mast be a last element
};
while ((opt = getopt_long(argc, (char *const *)argv, "D0",
long_options, &option_index)) != -1) {
switch (opt) {
case 0: { // --stop
pid_t pid = get_pid_from_file(dap_config_get_item_str_default(g_config,
"resources",
"pid_path",
DEFAULT_PID_FILE_PATH));
if (pid == 0) {
log_it(L_ERROR, "Can't read pid from file");
exit(-20);
} else if(kill_process(pid)) {
log_it(L_INFO, "Server successfully stopped");
exit(0);
}
log_it(L_WARNING, "Server not stopped. Maybe he is not running now?");
exit(-21);
}
case 'D':
log_it(L_INFO, "Daemonize server starting...");
exit_if_server_already_running();
is_daemon = 1;
daemonize_process();
break;
default:
log_it(L_WARNING, "Unknown option from command line");
}
}
// node_manager_t* manager = new_node_manager(l_config_name);
// node_manager_start(manager);
node_manager_start_stream();
if(!is_daemon)
exit_if_server_already_running();
}
node_manager_deinit();
free(l_config_name);
void exit_if_server_already_running(void) {
pid_t pid = get_pid_from_file(dap_config_get_item_str(g_config, "resources", "pid_path"));
if (pid != 0 && is_process_running(pid)) {
log_it(L_WARNING, "Proccess %d is running, don't allow "
"to run more than one copy of DapServer, exiting...", pid);
exit(-2);
}
else
puts("Please, specify config file path.");
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment