{"id":20636942,"url":"https://github.com/juergenhoetzel/ocaml-systemd","last_synced_at":"2025-07-04T16:36:06.609Z","repository":{"id":31010765,"uuid":"34569217","full_name":"juergenhoetzel/ocaml-systemd","owner":"juergenhoetzel","description":"OCaml module for native access to the systemd facilities","archived":false,"fork":false,"pushed_at":"2022-11-20T12:08:16.000Z","size":70,"stargazers_count":21,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T01:51:37.818Z","etag":null,"topics":["journald","ocaml","socket-activation","systemd"],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juergenhoetzel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-25T13:19:52.000Z","updated_at":"2024-11-05T00:31:18.000Z","dependencies_parsed_at":"2023-01-14T18:09:56.169Z","dependency_job_id":null,"html_url":"https://github.com/juergenhoetzel/ocaml-systemd","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juergenhoetzel%2Focaml-systemd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juergenhoetzel%2Focaml-systemd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juergenhoetzel%2Focaml-systemd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juergenhoetzel%2Focaml-systemd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juergenhoetzel","download_url":"https://codeload.github.com/juergenhoetzel/ocaml-systemd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249161104,"owners_count":21222468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["journald","ocaml","socket-activation","systemd"],"created_at":"2024-11-16T15:12:34.909Z","updated_at":"2025-04-15T21:50:21.147Z","avatar_url":"https://github.com/juergenhoetzel.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ocaml-systemd [![Build Status](https://api.travis-ci.org/juergenhoetzel/ocaml-systemd.svg)](https://travis-ci.org/juergenhoetzel/ocaml-systemd/)\n\nOCaml library allowing interaction with systemd and journald\n\n# Journald Usage\n\n```OCaml\nopen Journald\n\nlet () = journal_send_message Priority.INFO \"Hello\";\n\n\t (* compile and link its compilation units with option -g to get CODE_FILE and CODE_LINE entries*)\n\t journal_send_message_loc Priority.INFO \"Hello with location\";\n\t (* compile and link its compilation units with option -g *)\n\t journal_send [\"CUSTOM_FIELD\", \"CUSTOM_VALUE\"];\n\t journal_send_loc [\"CUSTOM_FIELD\", \"CUSTOM_VALUE with location\"];\n```\n\n## Performance\n\nTo get callstack info (required for the implicit\n`CODE_FILE` and `CODE_LINE` entries) you need to build your\ncompilation units with\ndebugging information.\n\nGetting the callstack at runtime also results in an performance overhead, so there a 2 groups of journal functions:\n\n### Journal functions with location info\n\n```OCaml\nval journal_send_message_loc : Priority.t -\u003e string -\u003e unit\nval journal_send_loc : (string * string) list -\u003e unit\n```\n\n### Journal functions without location info\n\n```OCaml\nval journal_send : (string * string) list -\u003e unit\nval journal_send_message : Priority.t -\u003e string -\u003e unit\n```\n\n# Socket activation\n\nNo need for forking the process, binding/listening the sockets.\n\nAlso support for systemd watchdog functionality.\n\n## Complete Example: Lwt echo server using socket activation\n\n```Ocaml\nopen Daemon\nopen Daemon.State\nopen Lwt\nopen Lwt_unix\nopen Journald\n\nlet echo_server conn_fd =\n  let in_channel = Lwt_io.of_fd ~mode:Lwt_io.input conn_fd in\n  let out_channel = Lwt_io.of_fd ~mode:Lwt_io.output conn_fd in\n  finalize (fun () -\u003e Lwt_stream.iter_s (Lwt_io.write_line out_channel) (Lwt_io.read_lines in_channel))\n\t   (fun () -\u003e close conn_fd)\n\nlet rec accept fd =\n  Lwt_unix.accept (Lwt_unix.of_unix_file_descr fd)\n  \u003e\u003e= (fun (conn_fd, _) -\u003e\n       async (fun _ -\u003e echo_server conn_fd);\n       accept fd)\n\nlet _ =\n  (* Notify systemd software watchdog every second *)\n  Lwt_engine.on_timer 1.0 true (fun _ -\u003e notify Watchdog|\u003eignore);\n  notify Ready |\u003e ignore;\n  match listen_fds () with\n  | [] -\u003e journal_send_message Priority.CRIT \"No file descriptors passed by the system manager\"\n  | fd::_ -\u003e journal_send_message Priority.INFO \"socket activation succeded\";\n\t     accept fd |\u003e Lwt_main.run\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuergenhoetzel%2Focaml-systemd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuergenhoetzel%2Focaml-systemd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuergenhoetzel%2Focaml-systemd/lists"}