diff --git a/README.md b/README.md index 49352f2..f53125f 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,11 @@ For a complete list of available command-line options, please run: gpiod-sysfs-proxy --help ``` +## Integration + +To integrate with systemd, there are sample service files under the `share` +directory. + ## Caveats Due to how FUSE works, there are certain limitations to the level of diff --git a/pyproject.toml b/pyproject.toml index 5b70aa1..6ea4362 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,17 @@ authors = [ Homepage = "https://github.com/brgl/gpiod-sysfs-proxy" Issues = "https://github.com/brgl/gpiod-sysfs-proxy/issues" +[tool.setuptools.data-files] +"lib/systemd/system" = [ + "share/gpiod-sysfs-proxy.service", + "share/run-gpio-sys.mount", + "share/sys-class.mount", +] +"lib/systemd/system/sysinit.target.wants" = [ + "share/sysinit.target.wants/run-gpio-sys.mount", + "share/sysinit.target.wants/sys-class.mount", +] + [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" diff --git a/share/gpiod-sysfs-proxy.service b/share/gpiod-sysfs-proxy.service new file mode 100644 index 0000000..516e107 --- /dev/null +++ b/share/gpiod-sysfs-proxy.service @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2024 Bartosz Golaszewski + +[Unit] +Description=User-space, libgpiod-based compatibility layer for linux GPIO sysfs interface + +# There are two standard locations for the mountpoint `/sys/class/gpio` and `/run/gpio`. +# This example service uses the former. +[Service] +RuntimeDirectory=gpio +Type=simple +ExecStart=/usr/bin/gpiod-sysfs-proxy /sys/class/gpio -f -o nonempty -o allow_other -o default_permissions -o entry_timeout=0 -o attr_timeout=0 +ExecStop=/bin/umount /sys/class/gpio +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/share/run-gpio-sys.mount b/share/run-gpio-sys.mount new file mode 100644 index 0000000..a924cb9 --- /dev/null +++ b/share/run-gpio-sys.mount @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2024 Bartosz Golaszewski + +[Unit] +Description=Remount of sysfs for gpiod-sysfs-proxy +ConditionPathExists=!/sys/class/gpio + +[Mount] +DirectoryMode=0700 +What=sysfs +Where=/run/gpio/sys +Type=sysfs +Options=nosuid,nodev,noexec diff --git a/share/sys-class.mount b/share/sys-class.mount new file mode 100644 index 0000000..e3e3ce8 --- /dev/null +++ b/share/sys-class.mount @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2024 Bartosz Golaszewski + +[Unit] +Description=Overlay on top of /sys/class adding the gpio class directory +Before=gpiod-sysfs-proxy.service +After=run-gpio-sys.mount +ConditionPathExists=!/sys/class/gpio + +[Mount] +RuntimeDirectory=gpio/class/gpio +DirectoryMode=0755 +What=overlay +Where=/sys/class +Type=overlay +Options=upperdir=/run/gpio/class,lowerdir=/run/gpio/sys/class,workdir=/run/gpio/work,ro,nosuid,nodev,noexec,relatime diff --git a/share/sysinit.target.wants/run-gpio-sys.mount b/share/sysinit.target.wants/run-gpio-sys.mount new file mode 120000 index 0000000..040aa2d --- /dev/null +++ b/share/sysinit.target.wants/run-gpio-sys.mount @@ -0,0 +1 @@ +../run-gpio-sys.mount \ No newline at end of file diff --git a/share/sysinit.target.wants/sys-class.mount b/share/sysinit.target.wants/sys-class.mount new file mode 120000 index 0000000..3831ba4 --- /dev/null +++ b/share/sysinit.target.wants/sys-class.mount @@ -0,0 +1 @@ +../sys-class.mount \ No newline at end of file