All Projects → juergenhoetzel → ocaml-systemd

juergenhoetzel / ocaml-systemd

Licence: other
OCaml module for native access to the systemd facilities

Programming Languages

ocaml
1615 projects
c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to ocaml-systemd

Go Systemd
Go bindings to systemd socket activation, journal, D-Bus, and unit files
Stars: ✭ 1,756 (+7881.82%)
Mutual labels:  systemd, journald
node-systemd-journald
Native bindings to journald
Stars: ✭ 26 (+18.18%)
Mutual labels:  systemd, journald
systemdlint
Systemd Linter
Stars: ✭ 16 (-27.27%)
Mutual labels:  systemd
systemdspawner
Spawn JupyterHub single-user notebook servers with systemd
Stars: ✭ 79 (+259.09%)
Mutual labels:  systemd
service-systemd
Setup a node.js app as systemd service.
Stars: ✭ 35 (+59.09%)
Mutual labels:  systemd
dotfiles
🏡 Personal dotfiles configuration
Stars: ✭ 73 (+231.82%)
Mutual labels:  systemd
gentoo-project-gnome-without-systemd
GNOME Without Systemd
Stars: ✭ 89 (+304.55%)
Mutual labels:  systemd
cya
Easy to use snapshot and restore utility for any Linux (Unix) OS and filesystem powered by BASH
Stars: ✭ 73 (+231.82%)
Mutual labels:  systemd
dron
What if cron and systemd had a baby?
Stars: ✭ 30 (+36.36%)
Mutual labels:  systemd
go-systemd-time
📅 Go implementation of systemd relative time adjustments
Stars: ✭ 21 (-4.55%)
Mutual labels:  systemd
logback-journal
systemd journal appender for Logback
Stars: ✭ 25 (+13.64%)
Mutual labels:  systemd
wimpy.deploy
Ansible role to automate immutable infrastructure scheduling one docker container on one EC2 instance
Stars: ✭ 21 (-4.55%)
Mutual labels:  systemd
erlang-systemd
systemd utilities for Erlang applications
Stars: ✭ 140 (+536.36%)
Mutual labels:  systemd
fuck systemd
A library to bring the joys of non-systemd users to systemd users
Stars: ✭ 19 (-13.64%)
Mutual labels:  systemd
subsystemctl
Utility to run systemd in WSL2 with a Linux namespace
Stars: ✭ 313 (+1322.73%)
Mutual labels:  systemd
buddy-linux
Do you remember "Wubi Ubuntu Installer"? This project is both a replacement and an improvement of Wubi. You will be able to install your Debian (or derived) distribution on a PC without repartitioning it, simply by using a secondary/external boot device (like a USB drive).
Stars: ✭ 17 (-22.73%)
Mutual labels:  systemd
sysdweb
Control systemd services through Web or REST API
Stars: ✭ 65 (+195.45%)
Mutual labels:  systemd
sysz
An fzf terminal UI for systemctl
Stars: ✭ 1,258 (+5618.18%)
Mutual labels:  systemd
amd-disable-c6
Systemd service to automatically disable the C6 power saving state on AMD Zen (Ryzen / Epyc) processors
Stars: ✭ 28 (+27.27%)
Mutual labels:  systemd
android-tether
Autostart Android USB tethering with udev + systemd + adb
Stars: ✭ 30 (+36.36%)
Mutual labels:  systemd

ocaml-systemd Build Status

OCaml library allowing interaction with systemd and journald

Journald Usage

open Journald

let () = journal_send_message Priority.INFO "Hello";

	 (* compile and link its compilation units with option -g to get CODE_FILE and CODE_LINE entries*)
	 journal_send_message_loc Priority.INFO "Hello with location";
	 (* compile and link its compilation units with option -g *)
	 journal_send ["CUSTOM_FIELD", "CUSTOM_VALUE"];
	 journal_send_loc ["CUSTOM_FIELD", "CUSTOM_VALUE with location"];

Performance

To get callstack info (required for the implicit CODE_FILE and CODE_LINE entries) you need to build your compilation units with debugging information.

Getting the callstack at runtime also results in an performance overhead, so there a 2 groups of journal functions:

Journal functions with location info

val journal_send_message_loc : Priority.t -> string -> unit
val journal_send_loc : (string * string) list -> unit

Journal functions without location info

val journal_send : (string * string) list -> unit
val journal_send_message : Priority.t -> string -> unit

Socket activation

No need for forking the process, binding/listening the sockets.

Also support for systemd watchdog functionality.

Complete Example: Lwt echo server using socket activation

open Daemon
open Daemon.State
open Lwt
open Lwt_unix
open Journald

let echo_server conn_fd =
  let in_channel = Lwt_io.of_fd ~mode:Lwt_io.input conn_fd in
  let out_channel = Lwt_io.of_fd ~mode:Lwt_io.output conn_fd in
  finalize (fun () -> Lwt_stream.iter_s (Lwt_io.write_line out_channel) (Lwt_io.read_lines in_channel))
	   (fun () -> close conn_fd)

let rec accept fd =
  Lwt_unix.accept (Lwt_unix.of_unix_file_descr fd)
  >>= (fun (conn_fd, _) ->
       async (fun _ -> echo_server conn_fd);
       accept fd)

let _ =
  (* Notify systemd software watchdog every second *)
  Lwt_engine.on_timer 1.0 true (fun _ -> notify Watchdog|>ignore);
  notify Ready |> ignore;
  match listen_fds () with
  | [] -> journal_send_message Priority.CRIT "No file descriptors passed by the system manager"
  | fd::_ -> journal_send_message Priority.INFO "socket activation succeded";
	     accept fd |> Lwt_main.run
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].