From 25c0dd16ca6d153efaed4e11a44dc508ec3e679c Mon Sep 17 00:00:00 2001 From: zacharias Date: Fri, 20 Jun 2025 13:14:00 +0200 Subject: [PATCH] added service and timer files, aswell as Arch PKGBUILD updated version in main.cpp to be a dependency from cmake --- CMakeLists.txt | 2 ++ PKGBUILD | 24 ++++++++++++++++++++++++ arduino-watchdog-heartbeat.service | 8 ++++++++ arduino-watchdog-heartbeat.timer | 8 ++++++++ main.cpp | 8 ++++++-- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 PKGBUILD create mode 100644 arduino-watchdog-heartbeat.service create mode 100644 arduino-watchdog-heartbeat.timer diff --git a/CMakeLists.txt b/CMakeLists.txt index b99f260..a05b9ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.31) project(home_lab_watchdog_keepalive) +add_definitions(-DVERSION=${VERSION}) + set(CMAKE_CXX_STANDARD 20) add_executable(home_lab_watchdog_keepalive main.cpp diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..01d1055 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,24 @@ +# PKGBUILD +pkgname=arduino_watchdog +pkgrel=1 +pkgdesc="Arduino based external watchdog to keep server online" +arch=('any') +license=('MIT') +makedepends=('cmake: build system used') +depends=('systemd>=257.6') +source=('git://git.server.4zellen.se/Zacharias/home-lab_watchdog_keepalive.git') +maintainer="Zacharias Zellén " +url="https://git.server.4zellen.se/Zacharias/home-lab_watchdog_keepalive.git" + + +build() { + cd "$srcdir/home-lab_watchdog_keepalive" + + cmake -B build -S . -DVERSION="\"$pkgver\"" + make -C build +} + +pkgver() { + cd "$srcdir/home-lab_watchdog_keepalive" + git describe --tags | sed 's/^v//;s/-/+/g' +} \ No newline at end of file diff --git a/arduino-watchdog-heartbeat.service b/arduino-watchdog-heartbeat.service new file mode 100644 index 0000000..ab39b22 --- /dev/null +++ b/arduino-watchdog-heartbeat.service @@ -0,0 +1,8 @@ +[Unit] +Description=Run the Heartbeat for Arduinoi based server watchdog + +[Service] +Type=oneshot +User=arduino_watchdog +ExecStart=/usr/bin/arduino-watchdog -b +Nice=0 \ No newline at end of file diff --git a/arduino-watchdog-heartbeat.timer b/arduino-watchdog-heartbeat.timer new file mode 100644 index 0000000..be5a7f0 --- /dev/null +++ b/arduino-watchdog-heartbeat.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Heartbeat timer for Arduino based watchdog + +[Timer] +OnUnitActiveSec=5min + +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/main.cpp b/main.cpp index a308b76..92e0cf7 100644 --- a/main.cpp +++ b/main.cpp @@ -2,8 +2,11 @@ #include #include #include "str_utils.h" +#include -const char* VERSION = "0.0.1-DEV"; +#ifndef VERSION +#define VERSION "unknown-DEV" +#endif bool shortHand(const char* str, char shortHand); @@ -31,7 +34,8 @@ int main(const int argc, char** argv) { return -1; } std::cout << "Initialization :)" << std::endl; - // TODO: Add init system + + } else if (strcmp(arg, "--heartbeat") == 0 || shortHand(arg, 'b')) { // TODO: Send heartbeat