Skip to content

Instantly share code, notes, and snippets.

@fpersson
Last active January 2, 2017 13:47
Show Gist options
  • Save fpersson/1703321c6c62ee855c2ab01321d7fd0a to your computer and use it in GitHub Desktop.
Save fpersson/1703321c6c62ee855c2ab01321d7fd0a to your computer and use it in GitHub Desktop.
Minimal sytemd app
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})
* 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
#include <iostream>
#include <systemd/sd-journal.h>
int main() {
std::cout << "Hello, World!" << std::endl;
sd_journal_print(LOG_NOTICE, "Hello, world");
return 0;
}
[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