This adds basic systemd support, incl. socket activation.
If systemd build is disabled, there won't be any sign of it neither
during build nor after.
If systemd build is enabled (default), but systemd is not available,
no systemd stuff is installed, so there is no impact whatsoever.
OPTION(BUILD_LUA "build Lua plugin" ON)
OPTION(BUILD_EXAMPLES "build examples" ON)
+OPTION(ENABLE_SYSTEMD "systemd support" ON)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock")
)
INSTALL(FILES ubusmsg.h ubus_common.h libubus.h DESTINATION include)
+
+# FIXME: this works but certainly can be done better:
+SET(UBUSD_BINARY "${CMAKE_INSTALL_PREFIX}/sbin/ubusd")
+
+# do this after the installs so we have the proper paths
+IF(ENABLE_SYSTEMD)
+ INCLUDE(FindPkgConfig)
+ PKG_CHECK_MODULES(SYSTEMD systemd)
+ IF(SYSTEMD_FOUND)
+ ADD_SUBDIRECTORY(systemd)
+ ENDIF()
+ENDIF()
--- /dev/null
+CONFIGURE_FILE(ubus.socket.in ubus.socket)
+CONFIGURE_FILE(ubus.service.in ubus.service)
+
+# Cmakes pkgconfig support is very limited, so for now just hardcode
+SET(SYSTEMD_SYSUNIT_DIR "${SYSTEMD_PREFIX}/lib/systemd/system")
+INSTALL(FILES ${CMAKE_BINARY_DIR}/systemd/ubus.socket ${CMAKE_BINARY_DIR}/systemd/ubus.service
+ DESTINATION ${SYSTEMD_SYSUNIT_DIR})
--- /dev/null
+[Unit]
+Description=OpenWrt micro bus
+Requires=ubus.socket
+
+[Service]
+ExecStart=@UBUSD_BINARY@
--- /dev/null
+[Unit]
+Description=OpenWrt micro bus socket
+
+[Socket]
+ListenStream=@UBUS_UNIX_SOCKET@
+
+[Install]
+WantedBy=sockets.target