Last active
January 2, 2017 13:47
-
-
Save fpersson/1703321c6c62ee855c2ab01321d7fd0a to your computer and use it in GitHub Desktop.
Minimal sytemd app
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
cmake_minimum_required(VERSION 3.6) | |
project(testd) | |
set(CMAKE_CXX_STANDARD 11) | |
find_package(PkgConfig) | |
pkg_check_modules(SYSTEMD libsystemd REQUIRED) | |
IF(NOT SYSTEMD_FOUND) | |
message(FATAL_ERROR "ERROR: Systemd not found") | |
ENDIF(NOT SYSTEMD_FOUND) | |
set(SOURCE_FILES main.cpp) | |
add_executable(testd ${SOURCE_FILES}) | |
target_link_libraries(testd ${SYSTEMD_LIBRARIES}) |
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
* create test service in /etc/systemd/system | |
* activate service with sudo systemctl enable /etc/systemd/system/test.service | |
* start service with sudo systemctl start test.service | |
* debug journalctl -f -u test.service |
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
#include <iostream> | |
#include <systemd/sd-journal.h> | |
int main() { | |
std::cout << "Hello, World!" << std::endl; | |
sd_journal_print(LOG_NOTICE, "Hello, world"); | |
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
[Unit] | |
Description=A simple test | |
[Service] | |
ExecStart=/home/foo/bin/testd | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment