Skip to content

morfredus/morfTemplateService

Repository files navigation

morfTemplateService

Read in another language: English (this document) · Français.

Version C++ Qt Build License

Reusable skeleton for morfSystem services. Clone it, code the business logic in modules, and you get - for free - an HTTP API, a JSON config loader, a LAN announce (morfBeacon), a systemd service and a Windows service, all working first try.

It is distilled from morfSensor and morfNotify: same architecture, no domain code.

What you get out of the box

  • IModule extension point - plug your business logic as one or more modules (a sensor, a notifier, a collector…). A working ExampleModule ships as a starting point.
  • HTTP API (GET + POST) - GET /status (morfBeacon-compatible), GET /healthz, GET /modules, GET /modules/{id}, and a POST /example showing body parsing.
  • Config - JSON file with a modules list; a factory turns it into modules.
  • LAN announce - morfBeacon heartbeat (bundled, no external dependency).
  • Service install - scripts/linux/ (systemd) and scripts/windows/ (Task Scheduler), copying binary + config to a fixed location.
  • Clone helper - scripts/new-service.sh / .ps1 scaffolds a renamed project.

Bootstrap a new service

scripts/new-service.sh morfwatch morfWatch     # Linux/macOS
# scripts\new-service.ps1 morfwatch morfWatch  # Windows

Creates ../morfWatch with every name replaced (morfTemplateServicemorfWatch, morftemplatemorfwatch, MORFTEMPLATEMORFWATCH). It compiles as-is. Then:

  1. Code your logic in src/ExampleModule.* (rename it) - implement IModule.
  2. Register your type(s) in src/ModuleFactory.cpp + knownTypes().
  3. Adapt the HTTP routes (src/HttpServer.cpp) and CMake source list.
  4. Update the comments / config / docs.

Build

Only needs Qt 6 (Core, Network). morfBeacon is vendored under third_party/morf/beacon.

cmake --preset mingw        # or linux / linux-arm64
cmake --build --preset mingw

Run

./build-mingw/service/morftemplate.exe          # 'example' module fallback
curl http://127.0.0.1:8901/modules

Install as a service

# Any platform: Linux, Windows, Raspberry Pi
sudo ./service.py install      # build if needed, install, start
sudo ./service.py update       # rebuild, replace the binary, restart
sudo ./service.py uninstall    # deregister, keeping your configuration
./service.py status            # what the system says about it

One entry point everywhere. What this service is -- its name, its directory, its configurations -- is declared in service.json beside it; the four install steps live once for the whole parc, and only the service manager differs by platform (systemd, Windows, launchd).

Documentation

French documentation in docs/fr/: architecture, and a step-by-step guide to turn this template into your service.

License

GPL-3.0-only - © 2026 morfredus (Frédéric Biron).

About

Reusable skeleton for morfSystem services. Clone it, write the business logic in modules, and get an HTTP API, a JSON config loader, LAN announcement, a systemd unit and a Windows service - working first try.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages