You are not logged in.
Hello,
I have an infinite compiled CPP program that has to be started as a service. I tried the following config, but it produces nothing:
[Unit]
Description=spicli-server
[Service]
ExecStart=/root/a.out
[Install]
WantedBy=multi-user.target
I enabled the service and started it.
This is what I get:
[root@osboxes ~]# systemctl start sserver2.service
[root@osboxes ~]# systemctl status s-server2.service
● s-server2.service - s-server2
Loaded: loaded (/etc/systemd/system/s-server2.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Wed 2020-08-26 15:54:00 EDT; 5s ago
Process: 622 ExecStart=/root/a.out (code=exited, status=0/SUCCESS)
Main PID: 622 (code=exited, status=0/SUCCESS)
Aug 26 15:54:00 osboxes systemd[1]: Started s-server2.
Aug 26 15:54:00 osboxes systemd[1]: s-server2.service: Succeeded.
This is a test program creating a file, but as a service, it does nothing. When I run it manually, everything is fine. Could you please help me?
Offline
It runs and exits successfully. What are you actually trying to do here, can you share the code?
Offline
This is the code, really simple. I can check its result if the file is created. When I run manually, there is no problem, but the service seems not doing anything. Everybody can execute this file. The final program to start is much more complicated, I just wanted to use it as test, but it failed
This is a simple program, there is no magic with daemons and etc, as it can be read on other forums. Am I doing something wrong? I do not know Linux well.
#include <stdio.h>
#include <fstream>
#include <sstream>
using namespace std;
int main()
{
std::stringstream logFileName;
logFileName << "_log.txt";
std::string logFileNameS = logFileName.str();
std::ofstream logFile;
logFile.open (logFileNameS);
logFile << " ----- SERVER STARTED. -----" << std::endl;
logFile.close();
return (0);
}
Last edited by kpeter (2020-08-26 21:22:51)
Offline
Where are you looking for the file? The working directory for a system instance of systemd is / if not specified otherwise.
FWIW seeing the hostname I don't think this is an actual Arch install, and you will probably have a generally better experience if you opt for one of the more beginner friendly distributions. Maybe read the man pages on systemd units and exec environments and so fort to have a general grasp of how this works.
Last edited by V1del (2020-08-26 21:53:18)
Offline
Or just don't use relative file names in executables meant to run as services.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Yes, that was the wrong path I was looking at. I do not know why I was getting errors first telling that executable is not fount under /usr/bin, now this is just working, and now I can find the file. This is an Arch install, but from OSBoxes.org, I do not like it, but it was a fast option to start with, however, it is slower than a copy installed by me. Thank you for your fast help.
Offline