Commit 501d58b0 authored by Martin Vala's avatar Martin Vala Committed by Branislav Beke

Resolve "Systemd rewrite"

parent 39e309c1
......@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "2")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_VERSION_RELEASE "0.0")
set(CPACK_PACKAGE_VERSION_RELEASE "0.4")
include(cmake/cmake_base.cmake)
......@@ -72,6 +72,7 @@ add_subdirectory(src/test)
add_subdirectory(doc)
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr")
INSTALL(FILES etc/salsa.service DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/system/)
INSTALL(FILES etc/salsa.conf DESTINATION /etc/sysconfig/)
INSTALL(FILES etc/${PROJECT_NAME}@.service DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/system/)
INSTALL(FILES etc/${PROJECT_NAME} DESTINATION /etc/sysconfig/)
INSTALL(FILES etc/config.json DESTINATION /etc/${PROJECT_NAME}/)
endif (CMAKE_INSTALL_PREFIX STREQUAL "/usr")
Name: @PROJECT_NAME@
Name: @PROJECT_NAME@
Version: @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@
Release: @CPACK_PACKAGE_VERSION_RELEASE@%{?dist}
Summary: SALSA - Scalable Adaptive Large Structures Analysis
......@@ -21,13 +21,21 @@ BuildRequires: protobuf-devel
SALSA - Scalable Adaptive Large Structures Analysis
%package devel
Summary: Development files and static library for the ZeroMQ library
Summary: Development files and static library for the SALSA
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}, pkgconfig
%description devel
This package contains SALSA related development libraries and header files.
%package doc
Summary: Documentation
Group: Documentation
Requires: %{name} = %{version}-%{release}, pkgconfig
%description doc
This package contains SALSA documentation.
%prep
%setup -q
......@@ -45,26 +53,29 @@ make install DESTDIR=%{buildroot}
cd ../
%post
%systemd_post %{name}.service
%systemd_post %{name}@*.service
%preun
%systemd_preun %{name}.service
%systemd_preun %{name}@*.service
# Restarting %{name}.service (maybe we don't want it)
%postun
%systemd_postun_with_restart %{name}.service
%systemd_postun_with_restart %{name}@*.service
%files
%{_bindir}/*
%doc /usr/share/doc/%{name}/
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}.conf
%{_unitdir}/%{name}.service
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/config.json
%{_unitdir}/%{name}@.service
%files devel
%defattr(-,root,root,-)
%{_includedir}/*
%{_libdir}/
%files doc
%doc /usr/share/doc/%{name}/
%changelog
# Extra options
SALSA_OPTS=""
# Debug mode
#SALSA_OPTS="--debug"
# Salsa interface
#SALSA_INTERFACE=""
#SALSA_INTERFACE="eth0"
# Worker only
SALSA_OPTS="-w"
# Manager only
#SALSA_OPTS="-m -p tcp://*:10000"
# Manager and worker
#SALSA_OPTS="-m -w -p tcp://*:10000"
[Unit]
Description=SALSA Service
Description=SALSA Service %I
After=network.target
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/salsa.conf
ExecStart=/usr/bin/salsa $SALSA_OPTS
EnvironmentFile=/etc/sysconfig/salsa
ExecStart=/usr/bin/salsa -c /etc/%p/config.json -n %I $SALSA_OPTS
Restart=on-abort
[Install]
......
......@@ -2,15 +2,17 @@ syntax = 'proto3';
package Salsa;
message TaskInfo {
uint32 clientID = 1;
string jobID = 2;
uint32 taskID = 3;
string targetNode = 4;
message TaskInfo
{
uint32 clientID = 1;
uint32 groupID = 2;
string jobID = 3;
uint32 taskID = 4;
string targetNode = 5;
string data = 5;
repeated string logTargets = 6;
string data = 6;
repeated string logTargets = 7;
uint64 status = 7;
uint64 returnCode = 8;
uint64 status = 8;
uint64 returnCode = 9;
}
......@@ -112,6 +112,7 @@ int main(int argc, char ** argv)
}
Salsa::TaskInfo * ji = new Salsa::TaskInfo();
ji->set_clientid(getuid());
ji->set_groupid(getgid());
ji->set_jobid(salsa_jobid);
ji->set_taskid(id);
ji->set_data(command);
......@@ -128,6 +129,13 @@ int main(int argc, char ** argv)
zyre_set_header(feeder, "X-SALSA-NODE-TYPE", "%s", salsa_type.c_str());
zyre_set_header(feeder, "X-SALSA-UID", "%d", getuid());
const char * zyreInterface = getenv("SALSA_INTERFACE");
if (zyreInterface && strcmp(zyreInterface, ""))
{
SPD_INFO("Using SALSA_INTERFACE [{}]", zyreInterface);
zyre_set_interface(feeder, zyreInterface);
}
if (discoveryUrl.empty())
zyre_set_port(feeder, port);
else
......
......@@ -402,6 +402,13 @@ std::shared_ptr<Salsa::Node> create_root_node( //
SPD_WARN("Unknown transport [{}], using [default]...", props.mType);
}
const char * zyreInterface = getenv("SALSA_INTERFACE");
if (zyreInterface && strcmp(zyreInterface, ""))
{
SPD_INFO("Using SALSA_INTERFACE [{}]", zyreInterface);
zyre_set_interface(pSocketZyre->zyre(), zyreInterface);
}
pSocketZyre->connect(); // Connect to socket
pNodeZyre->addSocket(pSocketZyre); // Add socket to zyre node
......
......@@ -91,6 +91,15 @@ void ActorZmq::SalsaActorForkFn(zsock_t * pPipe, void *)
char * pCommand = zframe_strdup(pFrame);
SPD_TRACE("PA: got Command [{}]", pCommand);
pFrame = zmsg_next(pReceived);
// GET UID from message
char * pUid = zframe_strdup(pFrame);
SPD_TRACE("PA: got UID [{}]", pUid);
pFrame = zmsg_next(pReceived);
// GET GID from message
char * pGid = zframe_strdup(pFrame);
SPD_TRACE("PA: got GID [{}]", pGid);
pFrame = zmsg_next(pReceived);
// GET Upsream uuid from message
char * pWorker = zframe_strdup(pFrame);
......@@ -141,6 +150,26 @@ void ActorZmq::SalsaActorForkFn(zsock_t * pPipe, void *)
pid = fork();
if (pid == 0)
{
// TODDO this needs to be improved if we cannot set UUID
if (getuid() == 0)
{
SPD_TRACE(
"PA Child: uid [{}]->[{}] guid [{}]->[{}]", getuid(), pUid, getgid(), pGid);
if (setgid(atoi(pGid)) == -1)
{
SPD_ERROR("Problem setting GUI to process !!! ");
return;
}
if (setuid(atoi(pUid)) == -1)
{
SPD_ERROR("Problem setting UID to process !!! ");
return;
}
SPD_TRACE("PA Child: uid [{}] guid [{}]", getuid(), getgid());
}
SPD_TRACE("PA Child: Running command [{}]", pCommand);
// FORK Child handler
unsigned int iCount = 0;
......@@ -158,8 +187,8 @@ void ActorZmq::SalsaActorForkFn(zsock_t * pPipe, void *)
} while (tmp);
ppCommand[iCount] = nullptr;
SPD_TRACE("PA Child: Sleeping for 100ms");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// SPD_TRACE("PA Child: Sleeping for 100ms");
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
SPD_TRACE("PA Child: Configuring pipes");
......@@ -238,6 +267,8 @@ void ActorZmq::SalsaActorForkFn(zsock_t * pPipe, void *)
} // END FORK handling
free(pCommand);
free(pUid);
free(pGid);
free(pWorker);
free(pUpsream);
free(pClient);
......
......@@ -32,6 +32,8 @@ bool TaskExecutorForkZmq::run(std::string worker, std::string upstream)
zmsg_t * outMsg = zmsg_new();
zmsg_addstrf(outMsg, "%s", mTaskState->task()->data().c_str());
zmsg_addstrf(outMsg, "%d", mTaskState->task()->clientid());
zmsg_addstrf(outMsg, "%d", mTaskState->task()->groupid());
zmsg_addstr(outMsg, worker.c_str());
zmsg_addstr(outMsg, upstream.c_str());
zmsg_addstr(outMsg, mTaskState->task()->jobid().c_str());
......
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