add systemd support
authorThomas Gstädtner <thomas@gstaedtner.net>
Mon, 4 Mar 2013 18:05:09 +0000 (19:05 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 4 Mar 2013 18:11:21 +0000 (19:11 +0100)
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.

CMakeLists.txt
systemd/CMakeLists.txt [new file with mode: 0644]
systemd/ubus.service.in [new file with mode: 0644]
systemd/ubus.socket.in [new file with mode: 0644]

index 01b43c0..22027ec 100644 (file)
@@ -5,6 +5,7 @@ ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
 
 OPTION(BUILD_LUA "build Lua plugin" ON)
 OPTION(BUILD_EXAMPLES "build examples" ON)
 
 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")
 
 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock")
@@ -38,3 +39,15 @@ INSTALL(TARGETS ubusd
 )
 
 INSTALL(FILES ubusmsg.h ubus_common.h libubus.h DESTINATION include)
 )
 
 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()
diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt
new file mode 100644 (file)
index 0000000..54b754b
--- /dev/null
@@ -0,0 +1,7 @@
+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})
diff --git a/systemd/ubus.service.in b/systemd/ubus.service.in
new file mode 100644 (file)
index 0000000..185a42f
--- /dev/null
@@ -0,0 +1,6 @@
+[Unit]
+Description=OpenWrt micro bus
+Requires=ubus.socket
+
+[Service]
+ExecStart=@UBUSD_BINARY@
diff --git a/systemd/ubus.socket.in b/systemd/ubus.socket.in
new file mode 100644 (file)
index 0000000..364beb7
--- /dev/null
@@ -0,0 +1,8 @@
+[Unit]
+Description=OpenWrt micro bus socket
+
+[Socket]
+ListenStream=@UBUS_UNIX_SOCKET@
+
+[Install]
+WantedBy=sockets.target