-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
162 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <exception> | ||
#include <iostream> | ||
#include <signal.h> | ||
#include <systemd/sd-daemon.h> | ||
|
||
#include "daemonizer.hpp" | ||
|
||
namespace yess | ||
{ | ||
int Daemonizer::run(int (*cb)(int argc, char **argv), int argc, char **argv) | ||
{ | ||
int result = 1; | ||
try { | ||
sd_notify(0, "READY=1"); | ||
std::cerr << std::string("Yess daemon has successfully started up.") | ||
<< std::endl | ||
<< std::flush; | ||
|
||
// start program | ||
result = cb(argc, argv); | ||
|
||
sd_notify(0, "STOPPING=1"); | ||
std::cerr << std::string("Yess daemon has been successfully shut down.") | ||
<< std::endl | ||
<< std::flush; | ||
} catch (std::exception &ex) { | ||
sd_notifyf( | ||
0, "STATUS=Failed to start up: %s\n ERRNO=%i", ex.what(), result); | ||
return result; | ||
} | ||
result = 0; | ||
return result; | ||
} | ||
} // namespace yess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
namespace yess | ||
{ | ||
class Daemonizer | ||
{ | ||
public: | ||
// static int run(int (*cb)(const int &argc, const char **arbv)); | ||
static int run(int (*cb)(int argc, char **argv), int argc, char **argv); | ||
/* | ||
static int run(int (*cb)(const int &argc, const char **arbv), | ||
const int &argc, | ||
const char **argv); | ||
*/ | ||
}; | ||
} // namespace yess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
#include "daemonizer.hpp" | ||
#include "server.hpp" | ||
#include <iostream> | ||
|
||
void sayhello_loop() | ||
{ | ||
while (1) { | ||
std::cout << "hello\n"; | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
yess::Server server(argc, argv); | ||
return server.run(); | ||
/* | ||
yess::Server server(argc, argv); | ||
return server.run(); | ||
*/ | ||
// daemonize(sayhello_loop, "yess"); | ||
yess::Daemonizer::run( | ||
[](int argc, char **argv) { | ||
yess::Server server(argc, argv); | ||
return server.run(); | ||
}, | ||
argc, | ||
argv); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Yess service | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/bin/yess --daemon | ||
Restart=on-failure | ||
KillMode=process | ||
WatchdogSec=6 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |