From 7d0991bb4485d760a905242da146a62833836169 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 21 Apr 2026 13:52:49 +0100 Subject: [PATCH 1/6] Add example systemd service files Add the example systemd service files from the OpenEmbedded recipe[0]. The files are licenced under the same licence as the upstream project. Link[0]: https://git.openembedded.org/meta-openembedded/tree/meta-filesystems/dynamic-layers/meta-python/recipes-support/gpiod-sysfs-proxy/gpiod-sysfs-proxy Fixes: #3 Signed-off-by: Christopher Obbard --- share/gpiod-sysfs-proxy.init.in | 84 ++++++++++++++++++++++++++++++ share/gpiod-sysfs-proxy.service.in | 15 ++++++ share/run-gpio-sys.mount | 13 +++++ share/sys-class.mount | 16 ++++++ 4 files changed, 128 insertions(+) create mode 100644 share/gpiod-sysfs-proxy.init.in create mode 100644 share/gpiod-sysfs-proxy.service.in create mode 100644 share/run-gpio-sys.mount create mode 100644 share/sys-class.mount diff --git a/share/gpiod-sysfs-proxy.init.in b/share/gpiod-sysfs-proxy.init.in new file mode 100644 index 0000000..cba731c --- /dev/null +++ b/share/gpiod-sysfs-proxy.init.in @@ -0,0 +1,84 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: gpiod-sysfs-proxy +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 1 +# Short-Description: User-space, libgpiod-based compatibility layer for linux GPIO sysfs interface. +### END INIT INFO +# +# -*- coding: utf-8 -*- +# Debian init.d script for gpiod-sysfs-proxy +# Copyright (c) 2024 Bartosz Golaszewski + +# set -e + +# Source function library. +. /etc/init.d/functions + +PROG="/usr/bin/gpiod-sysfs-proxy" +NAME="gpiod-sysfs-proxy" +DESC="/sys/class/gpio compatibility layer" +MOUNTPOINT="@mountpoint@" + +test -x $PROG || exit 0 + +do_start() +{ + echo -n "Starting $DESC: " + + if [ "$MOUNTPOINT" = "/sys/class/gpio" ] && [ ! -e /sys/class/gpio ]; then + mkdir -p /run/gpio/sys /run/gpio/class/gpio /run/gpio/work + mount -t sysfs sysfs /run/gpio/sys -o nosuid,nodev,noexec + # Bail out if overlayfs is not available + set -e + mount -t overlay overlay /sys/class \ +-o upperdir=/run/gpio/class,lowerdir=/run/gpio/sys/class,workdir=/run/gpio/work,nosuid,nodev,noexec,relatime,ro + set +e + else + mkdir -p $MOUNTPOINT + fi + + $PROG $MOUNTPOINT -o nonempty -o allow_other -o default_permissions -o entry_timeout=0 -o attr_timeout=0 -f | logger -i $NAME & + echo "done" +} + +do_stop() +{ + echo -n "Stopping $DESC: " + + umount $MOUNTPOINT + + mountpoint -q /sys/class + if [ "$?" = "0" ]; then + umount /sys/class + umount /run/gpio/sys + rm -rf /run/gpio + fi + echo "done" +} + +case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; + status) + status $PROG + exit $? + ;; + restart) + do_stop + sleep 1 + do_start + ;; + *) + echo "Usage: /etc/init.d/$NAME {start|stop|status|restart}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/share/gpiod-sysfs-proxy.service.in b/share/gpiod-sysfs-proxy.service.in new file mode 100644 index 0000000..5f8c4f4 --- /dev/null +++ b/share/gpiod-sysfs-proxy.service.in @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2024 Bartosz Golaszewski + +[Unit] +Description=User-space, libgpiod-based compatibility layer for linux GPIO sysfs interface + +[Service] +RuntimeDirectory=gpio +Type=simple +ExecStart=/usr/bin/gpiod-sysfs-proxy @mountpoint@ -f -o nonempty -o allow_other -o default_permissions -o entry_timeout=0 -o attr_timeout=0 +ExecStop=/bin/umount @mountpoint@ +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 From 8bdeb3ab2a75996f9e62463a44fd3ee22d1f7ad5 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 21 Apr 2026 13:59:21 +0100 Subject: [PATCH 2/6] Document example systemd service files Signed-off-by: Christopher Obbard --- README.md | 5 +++++ 1 file changed, 5 insertions(+) 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 From 489531cd20d0e756af44755201ef19789745de3e Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 21 Apr 2026 17:27:28 +0100 Subject: [PATCH 3/6] Remove outdated sysvinit script The sysvinit script is no longer used and the systemd services is preferred to be used. Remove the sysvinit script. Signed-off-by: Christopher Obbard --- share/gpiod-sysfs-proxy.init.in | 84 --------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 share/gpiod-sysfs-proxy.init.in diff --git a/share/gpiod-sysfs-proxy.init.in b/share/gpiod-sysfs-proxy.init.in deleted file mode 100644 index cba731c..0000000 --- a/share/gpiod-sysfs-proxy.init.in +++ /dev/null @@ -1,84 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: gpiod-sysfs-proxy -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 1 -# Short-Description: User-space, libgpiod-based compatibility layer for linux GPIO sysfs interface. -### END INIT INFO -# -# -*- coding: utf-8 -*- -# Debian init.d script for gpiod-sysfs-proxy -# Copyright (c) 2024 Bartosz Golaszewski - -# set -e - -# Source function library. -. /etc/init.d/functions - -PROG="/usr/bin/gpiod-sysfs-proxy" -NAME="gpiod-sysfs-proxy" -DESC="/sys/class/gpio compatibility layer" -MOUNTPOINT="@mountpoint@" - -test -x $PROG || exit 0 - -do_start() -{ - echo -n "Starting $DESC: " - - if [ "$MOUNTPOINT" = "/sys/class/gpio" ] && [ ! -e /sys/class/gpio ]; then - mkdir -p /run/gpio/sys /run/gpio/class/gpio /run/gpio/work - mount -t sysfs sysfs /run/gpio/sys -o nosuid,nodev,noexec - # Bail out if overlayfs is not available - set -e - mount -t overlay overlay /sys/class \ --o upperdir=/run/gpio/class,lowerdir=/run/gpio/sys/class,workdir=/run/gpio/work,nosuid,nodev,noexec,relatime,ro - set +e - else - mkdir -p $MOUNTPOINT - fi - - $PROG $MOUNTPOINT -o nonempty -o allow_other -o default_permissions -o entry_timeout=0 -o attr_timeout=0 -f | logger -i $NAME & - echo "done" -} - -do_stop() -{ - echo -n "Stopping $DESC: " - - umount $MOUNTPOINT - - mountpoint -q /sys/class - if [ "$?" = "0" ]; then - umount /sys/class - umount /run/gpio/sys - rm -rf /run/gpio - fi - echo "done" -} - -case "$1" in - start) - do_start - ;; - stop) - do_stop - ;; - status) - status $PROG - exit $? - ;; - restart) - do_stop - sleep 1 - do_start - ;; - *) - echo "Usage: /etc/init.d/$NAME {start|stop|status|restart}" >&2 - exit 1 - ;; -esac - -exit 0 From 1fcbd31b7b51f4ba4bbf27bc37011c2a4568f261 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 21 Apr 2026 17:49:11 +0100 Subject: [PATCH 4/6] Assume default mountpoint for the systemd service Assume the default target of /sys/class/gpio for the mountpoint so we don't have to template the systemd service at install time. Signed-off-by: Christopher Obbard --- ...iod-sysfs-proxy.service.in => gpiod-sysfs-proxy.service} | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) rename share/{gpiod-sysfs-proxy.service.in => gpiod-sysfs-proxy.service} (50%) diff --git a/share/gpiod-sysfs-proxy.service.in b/share/gpiod-sysfs-proxy.service similarity index 50% rename from share/gpiod-sysfs-proxy.service.in rename to share/gpiod-sysfs-proxy.service index 5f8c4f4..516e107 100644 --- a/share/gpiod-sysfs-proxy.service.in +++ b/share/gpiod-sysfs-proxy.service @@ -4,11 +4,13 @@ [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 @mountpoint@ -f -o nonempty -o allow_other -o default_permissions -o entry_timeout=0 -o attr_timeout=0 -ExecStop=/bin/umount @mountpoint@ +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] From d98077350d6f139e2e1abf711a2cccdc98a042dd Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 21 Apr 2026 17:50:22 +0100 Subject: [PATCH 5/6] Add service target.wants symlinks Signed-off-by: Christopher Obbard --- share/sysinit.target.wants/run-gpio-sys.mount | 1 + share/sysinit.target.wants/sys-class.mount | 1 + 2 files changed, 2 insertions(+) create mode 120000 share/sysinit.target.wants/run-gpio-sys.mount create mode 120000 share/sysinit.target.wants/sys-class.mount 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 From eb4522e1bde385e9ec78f0bf0622943e664e3a8f Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 21 Apr 2026 17:50:56 +0100 Subject: [PATCH 6/6] Install systemd service files Install the systemd service as part of the pyproject installation process. Signed-off-by: Christopher Obbard --- pyproject.toml | 11 +++++++++++ 1 file changed, 11 insertions(+) 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"