~mil/sxmo-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
6 5

[PATCH sxmo-utils] postmarketOS: detect if on systemd and use systemd

Details
Message ID
<20241120071724.25403-1-anjan@momi.ca>
DKIM signature
pass
Download raw message
Patch: +46 -65
I want to give users the option to use systemd on postmarketOS.
This is a draft patch. How do we enable user services on systemd
distros? Do we use superd on systemd distros? I did a simple search and
replace here for systemctl/rc-service logic.
---
 .../sxmo_hook_restart_modem_daemons.sh        | 63 ++++++++-----------
 scripts/core/sxmo_bluetoothmenu.sh            | 13 ++--
 scripts/core/sxmo_bluetoothtoggle.sh          | 35 +++++------
 3 files changed, 46 insertions(+), 65 deletions(-)

diff --git a/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh b/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
index f48fcef..6d73da8 100755
--- a/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
+++ b/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
@@ -18,15 +18,12 @@ daemon_start() {
		sxmo_notify_user.sh "$1 is already running"
		return 0
	fi
	case "$SXMO_OS" in
		alpine|postmarketos)
			doas rc-service "$1" start
			;;
		arch|archarm|debian|nixos)
			[ "$1" = "modemmanager" ] && set -- ModemManager
			doas systemctl start "$1"
			;;
	esac
	if command -v systemctl > /dev/null; then
		[ "$1" = "modemmanager" ] && set -- ModemManager
		doas systemctl start "$1"
	else
		doas rc-service "$1" start
	fi
}

daemon_stop() {
@@ -38,15 +35,12 @@ daemon_stop() {
		sxmo_notify_user.sh "$1 is already stopped"
		return 0
	fi
	case "$SXMO_OS" in
		alpine|postmarketos)
			doas rc-service "$1" stop
			;;
		arch|archarm|nixos)
			[ "$1" = "modemmanager" ] && set -- ModemManager
			doas systemctl stop "$1"
			;;
	esac
	if command -v systemctl > /dev/null; then
		[ "$1" = "modemmanager" ] && set -- ModemManager
		doas systemctl stop "$1"
	else
		doas rc-service "$1" stop
	fi
}

daemon_isrunning() {
@@ -54,28 +48,23 @@ daemon_isrunning() {
		sxmo_log "$1 does not exist on the system"
		return 1
	fi
	case "$SXMO_OS" in
		alpine|postmarketos)
			rc-service "$1" status | grep -q started
			;;
		arch|archarm|debian|nixos)
			[ "$1" = "modemmanager" ] && set -- ModemManager
			systemctl is-active --quiet "$1"
			;;
	esac
	if command -v systemctl > /dev/null; then
		[ "$1" = "modemmanager" ] && set -- ModemManager
		systemctl is-active --quiet "$1"
	else
		rc-service "$1" status | grep -q started
	fi
}

daemon_exists() {
	case "$SXMO_OS" in
		alpine|postmarketos)
			[ -f /etc/init.d/"$1" ]
			;;
		arch|archarm|debian|nixos)
			[ "$1" = "modemmanager" ] && set -- ModemManager
			systemctl status "$1" > /dev/null 2>&1
			[ $? -ne 4 ]
			;;
	esac

	if command -v systemctl > /dev/null; then
		[ "$1" = "modemmanager" ] && set -- ModemManager
		systemctl status "$1" > /dev/null 2>&1
		[ $? -ne 4 ]
	else
		[ -f /etc/init.d/"$1" ]
	fi
}

if command -v eg25-manager > /dev/null; then
diff --git a/scripts/core/sxmo_bluetoothmenu.sh b/scripts/core/sxmo_bluetoothmenu.sh
index 8aaadc5..6879b2c 100755
--- a/scripts/core/sxmo_bluetoothmenu.sh
+++ b/scripts/core/sxmo_bluetoothmenu.sh
@@ -52,14 +52,11 @@ _device_list() {
}

_restart_bluetooth() {
	case "$SXMO_OS" in
		alpine|postmarketos)
			doas rc-service bluetooth restart
			;;
		arch|archarm|nixos)
			doas systemctl restart bluetooth
			;;
	esac
	if command -v systemctl > /dev/null; then
		doas systemctl restart bluetooth
	else
		doas rc-service bluetooth restart
	fi
}

_full_reconnection() {
diff --git a/scripts/core/sxmo_bluetoothtoggle.sh b/scripts/core/sxmo_bluetoothtoggle.sh
index f670f61..e00c1f7 100755
--- a/scripts/core/sxmo_bluetoothtoggle.sh
+++ b/scripts/core/sxmo_bluetoothtoggle.sh
@@ -9,29 +9,24 @@

on() {
	rfkill unblock bluetooth
	case "$SXMO_OS" in
		alpine|postmarketos)
			rc-service bluetooth start
			rc-update add bluetooth
			;;
		arch|archarm|nixos|debian)
			systemctl start bluetooth
			systemctl enable bluetooth
			;;
	esac

	if command -v systemctl > /dev/null; then
		systemctl start bluetooth
		systemctl enable bluetooth
	else
		rc-service bluetooth start
		rc-update add bluetooth
	fi
}

off() {
	case "$SXMO_OS" in
		alpine|postmarketos)
			rc-service bluetooth stop
			rc-update del bluetooth
			;;
		arch|archarm|nixos|debian)
			systemctl stop bluetooth
			systemctl disable bluetooth
			;;
	esac
	if command -v systemctl > /dev/null; then
		systemctl stop bluetooth
		systemctl disable bluetooth
	else
		rc-service bluetooth stop
		rc-update del bluetooth
	fi
	rfkill block bluetooth
}

-- 
2.45.2

[sxmo-utils/patches/test.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D5QTMJ7IZBZW.2P4B2OGDOWCU1@fra02>
In-Reply-To
<20241120071724.25403-1-anjan@momi.ca> (view parent)
DKIM signature
missing
Download raw message
sxmo-utils/patches/test.yml: SUCCESS in 23s

[postmarketOS: detect if on systemd and use systemd][0] from [Anjandev Momi][1]

[0]: https://lists.sr.ht/~mil/sxmo-devel/patches/56008
[1]: anjan@momi.ca

✓ #1371493 SUCCESS sxmo-utils/patches/test.yml https://builds.sr.ht/~mil/job/1371493
Manner Róbert <rmanni@gmail.com>
Details
Message ID
<2975f788-aee8-459c-97d4-58bb0a4441ff@gmail.com>
In-Reply-To
<20241120071724.25403-1-anjan@momi.ca> (view parent)
DKIM signature
pass
Download raw message
Hi,

I detect if on a system with systemd in use with this:

if [ -e /run/systemd/system ]; then
   echo Systemd is the init
fi

This is better than checking the existence of the tool because in some 
scenarios it might just be installed accidentally. Consider for example 
starting a debian based docker container with "bash" as pid1 process.

Of course, you might not need to support such cases :)

Robert

On 11/20/24 8:17 AM, Anjandev Momi wrote:
> I want to give users the option to use systemd on postmarketOS.
> This is a draft patch. How do we enable user services on systemd
> distros? Do we use superd on systemd distros? I did a simple search and
> replace here for systemctl/rc-service logic.
> ---
>   .../sxmo_hook_restart_modem_daemons.sh        | 63 ++++++++-----------
>   scripts/core/sxmo_bluetoothmenu.sh            | 13 ++--
>   scripts/core/sxmo_bluetoothtoggle.sh          | 35 +++++------
>   3 files changed, 46 insertions(+), 65 deletions(-)
> 
> diff --git a/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh b/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
> index f48fcef..6d73da8 100755
> --- a/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
> +++ b/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
> @@ -18,15 +18,12 @@ daemon_start() {
>   		sxmo_notify_user.sh "$1 is already running"
>   		return 0
>   	fi
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			doas rc-service "$1" start
> -			;;
> -		arch|archarm|debian|nixos)
> -			[ "$1" = "modemmanager" ] && set -- ModemManager
> -			doas systemctl start "$1"
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		[ "$1" = "modemmanager" ] && set -- ModemManager
> +		doas systemctl start "$1"
> +	else
> +		doas rc-service "$1" start
> +	fi
>   }
>   
>   daemon_stop() {
> @@ -38,15 +35,12 @@ daemon_stop() {
>   		sxmo_notify_user.sh "$1 is already stopped"
>   		return 0
>   	fi
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			doas rc-service "$1" stop
> -			;;
> -		arch|archarm|nixos)
> -			[ "$1" = "modemmanager" ] && set -- ModemManager
> -			doas systemctl stop "$1"
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		[ "$1" = "modemmanager" ] && set -- ModemManager
> +		doas systemctl stop "$1"
> +	else
> +		doas rc-service "$1" stop
> +	fi
>   }
>   
>   daemon_isrunning() {
> @@ -54,28 +48,23 @@ daemon_isrunning() {
>   		sxmo_log "$1 does not exist on the system"
>   		return 1
>   	fi
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			rc-service "$1" status | grep -q started
> -			;;
> -		arch|archarm|debian|nixos)
> -			[ "$1" = "modemmanager" ] && set -- ModemManager
> -			systemctl is-active --quiet "$1"
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		[ "$1" = "modemmanager" ] && set -- ModemManager
> +		systemctl is-active --quiet "$1"
> +	else
> +		rc-service "$1" status | grep -q started
> +	fi
>   }
>   
>   daemon_exists() {
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			[ -f /etc/init.d/"$1" ]
> -			;;
> -		arch|archarm|debian|nixos)
> -			[ "$1" = "modemmanager" ] && set -- ModemManager
> -			systemctl status "$1" > /dev/null 2>&1
> -			[ $? -ne 4 ]
> -			;;
> -	esac
> +
> +	if command -v systemctl > /dev/null; then
> +		[ "$1" = "modemmanager" ] && set -- ModemManager
> +		systemctl status "$1" > /dev/null 2>&1
> +		[ $? -ne 4 ]
> +	else
> +		[ -f /etc/init.d/"$1" ]
> +	fi
>   }
>   
>   if command -v eg25-manager > /dev/null; then
> diff --git a/scripts/core/sxmo_bluetoothmenu.sh b/scripts/core/sxmo_bluetoothmenu.sh
> index 8aaadc5..6879b2c 100755
> --- a/scripts/core/sxmo_bluetoothmenu.sh
> +++ b/scripts/core/sxmo_bluetoothmenu.sh
> @@ -52,14 +52,11 @@ _device_list() {
>   }
>   
>   _restart_bluetooth() {
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			doas rc-service bluetooth restart
> -			;;
> -		arch|archarm|nixos)
> -			doas systemctl restart bluetooth
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		doas systemctl restart bluetooth
> +	else
> +		doas rc-service bluetooth restart
> +	fi
>   }
>   
>   _full_reconnection() {
> diff --git a/scripts/core/sxmo_bluetoothtoggle.sh b/scripts/core/sxmo_bluetoothtoggle.sh
> index f670f61..e00c1f7 100755
> --- a/scripts/core/sxmo_bluetoothtoggle.sh
> +++ b/scripts/core/sxmo_bluetoothtoggle.sh
> @@ -9,29 +9,24 @@
>   
>   on() {
>   	rfkill unblock bluetooth
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			rc-service bluetooth start
> -			rc-update add bluetooth
> -			;;
> -		arch|archarm|nixos|debian)
> -			systemctl start bluetooth
> -			systemctl enable bluetooth
> -			;;
> -	esac
> +
> +	if command -v systemctl > /dev/null; then
> +		systemctl start bluetooth
> +		systemctl enable bluetooth
> +	else
> +		rc-service bluetooth start
> +		rc-update add bluetooth
> +	fi
>   }
>   
>   off() {
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			rc-service bluetooth stop
> -			rc-update del bluetooth
> -			;;
> -		arch|archarm|nixos|debian)
> -			systemctl stop bluetooth
> -			systemctl disable bluetooth
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		systemctl stop bluetooth
> +		systemctl disable bluetooth
> +	else
> +		rc-service bluetooth stop
> +		rc-update del bluetooth
> +	fi
>   	rfkill block bluetooth
>   }
>   
Details
Message ID
<D5QV88FKPAGV.21AWA785SYM8P@willowbarraco.fr>
In-Reply-To
<20241120071724.25403-1-anjan@momi.ca> (view parent)
DKIM signature
pass
Download raw message
At first glance, I think we need a safer way to know we really are using
systemd, and not openrc. I'll take time to dig into this topic probably
this week-end
Details
Message ID
<vbbmvhfzop5dvpyrhb2qm7vclaxbv6hsvmxa5umdoiaacevmsr@y4feec7mnebh>
In-Reply-To
<2975f788-aee8-459c-97d4-58bb0a4441ff@gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Wed, Nov 20, 2024 at 08:57:18AM +0100, Manner Róbert wrote:
> Hi,
> 
> I detect if on a system with systemd in use with this:
> 
> if [ -e /run/systemd/system ]; then
>   echo Systemd is the init
> fi
> 
> This is better than checking the existence of the tool because in some
> scenarios it might just be installed accidentally. Consider for example
> starting a debian based docker container with "bash" as pid1 process.

+1 for this (or something like it), covering more edge cases is better.

> Of course, you might not need to support such cases :)
> 
> Robert
Details
Message ID
<af4e6e1c-c0ba-4d84-b3ee-727522dee1b2@asgard.ch>
In-Reply-To
<D5QV88FKPAGV.21AWA785SYM8P@willowbarraco.fr> (view parent)
DKIM signature
pass
Download raw message
May I also suggest to use [ -d |/run/systemd/system/ ] because that's 
the same way `systemd-notify --booted` does it via sd_booted(3), 
see|||https://www.freedesktop.org/software/systemd/man/latest/sd_booted.html#Notes
Details
Message ID
<7drwiu342yzckjbr2nnob7zhac2gxxor3f724avnhvhrxsoqco@ujk4mccgozf4>
In-Reply-To
<20241120071724.25403-1-anjan@momi.ca> (view parent)
DKIM signature
pass
Download raw message
Other replies have pointed at the relevant systemd documentation, which
looks straight-forward to implement. I'm in favor of this patch with
that change implemented. Marking as needs revision for now.

Here's the link again just in case:
https://www.freedesktop.org/software/systemd/man/latest/sd_booted.html#Notes

On Tue, Nov 19, 2024 at 11:17:20PM -0800, Anjandev Momi wrote:
> I want to give users the option to use systemd on postmarketOS. This
> is a draft patch.

> How do we enable user services on systemd distros? Do we use superd on
> systemd distros?

We could either replace superd with systemd like in this patch
https://lists.sr.ht/~mil/sxmo-devel/%3C20220423225021.343171-1-aren@peacevolution.org%3E
There's a more recent version here (I think that's the latest rebase I
did, I've kinda lost track)
https://git.sr.ht/~aren/sxmo-utils/log/systemd

Or we could use superd (I think making it possible to switch service
managers is better)
https://lists.sr.ht/~mil/sxmo-devel/patches/32304
Up to date version at
https://github.com/dreemurrs-embedded/Pine64-Arch/blob/master/PKGBUILDS/sxmo/sxmo-utils/0001-avoid-conflicting-with-systemd-services.patch

This patch might also be relavent
sxmo-utils: start hook: Move always-on services into superd configuration
https://lists.sr.ht/~mil/sxmo-devel/patches/33707

> I did a simple search and replace here for systemctl/rc-service logic.
> ---
>  .../sxmo_hook_restart_modem_daemons.sh        | 63 ++++++++-----------
>  scripts/core/sxmo_bluetoothmenu.sh            | 13 ++--
>  scripts/core/sxmo_bluetoothtoggle.sh          | 35 +++++------
>  3 files changed, 46 insertions(+), 65 deletions(-)
> 
> diff --git a/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh b/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
> index f48fcef..6d73da8 100755
> --- a/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
> +++ b/configs/default_hooks/sxmo_hook_restart_modem_daemons.sh
> @@ -18,15 +18,12 @@ daemon_start() {
>  		sxmo_notify_user.sh "$1 is already running"
>  		return 0
>  	fi
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			doas rc-service "$1" start
> -			;;
> -		arch|archarm|debian|nixos)
> -			[ "$1" = "modemmanager" ] && set -- ModemManager
> -			doas systemctl start "$1"
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		[ "$1" = "modemmanager" ] && set -- ModemManager
> +		doas systemctl start "$1"
> +	else
> +		doas rc-service "$1" start
> +	fi
>  }
>  
>  daemon_stop() {
> @@ -38,15 +35,12 @@ daemon_stop() {
>  		sxmo_notify_user.sh "$1 is already stopped"
>  		return 0
>  	fi
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			doas rc-service "$1" stop
> -			;;
> -		arch|archarm|nixos)
> -			[ "$1" = "modemmanager" ] && set -- ModemManager
> -			doas systemctl stop "$1"
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		[ "$1" = "modemmanager" ] && set -- ModemManager
> +		doas systemctl stop "$1"
> +	else
> +		doas rc-service "$1" stop
> +	fi
>  }
>  
>  daemon_isrunning() {
> @@ -54,28 +48,23 @@ daemon_isrunning() {
>  		sxmo_log "$1 does not exist on the system"
>  		return 1
>  	fi
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			rc-service "$1" status | grep -q started
> -			;;
> -		arch|archarm|debian|nixos)
> -			[ "$1" = "modemmanager" ] && set -- ModemManager
> -			systemctl is-active --quiet "$1"
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		[ "$1" = "modemmanager" ] && set -- ModemManager
> +		systemctl is-active --quiet "$1"
> +	else
> +		rc-service "$1" status | grep -q started
> +	fi
>  }
>  
>  daemon_exists() {
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			[ -f /etc/init.d/"$1" ]
> -			;;
> -		arch|archarm|debian|nixos)
> -			[ "$1" = "modemmanager" ] && set -- ModemManager
> -			systemctl status "$1" > /dev/null 2>&1
> -			[ $? -ne 4 ]
> -			;;
> -	esac
> +
> +	if command -v systemctl > /dev/null; then
> +		[ "$1" = "modemmanager" ] && set -- ModemManager
> +		systemctl status "$1" > /dev/null 2>&1
> +		[ $? -ne 4 ]
> +	else
> +		[ -f /etc/init.d/"$1" ]
> +	fi
>  }
>  
>  if command -v eg25-manager > /dev/null; then
> diff --git a/scripts/core/sxmo_bluetoothmenu.sh b/scripts/core/sxmo_bluetoothmenu.sh
> index 8aaadc5..6879b2c 100755
> --- a/scripts/core/sxmo_bluetoothmenu.sh
> +++ b/scripts/core/sxmo_bluetoothmenu.sh
> @@ -52,14 +52,11 @@ _device_list() {
>  }
>  
>  _restart_bluetooth() {
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			doas rc-service bluetooth restart
> -			;;
> -		arch|archarm|nixos)
> -			doas systemctl restart bluetooth
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		doas systemctl restart bluetooth
> +	else
> +		doas rc-service bluetooth restart
> +	fi
>  }
>  
>  _full_reconnection() {
> diff --git a/scripts/core/sxmo_bluetoothtoggle.sh b/scripts/core/sxmo_bluetoothtoggle.sh
> index f670f61..e00c1f7 100755
> --- a/scripts/core/sxmo_bluetoothtoggle.sh
> +++ b/scripts/core/sxmo_bluetoothtoggle.sh
> @@ -9,29 +9,24 @@
>  
>  on() {
>  	rfkill unblock bluetooth
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			rc-service bluetooth start
> -			rc-update add bluetooth
> -			;;
> -		arch|archarm|nixos|debian)
> -			systemctl start bluetooth
> -			systemctl enable bluetooth
> -			;;
> -	esac
> +
> +	if command -v systemctl > /dev/null; then
> +		systemctl start bluetooth
> +		systemctl enable bluetooth
> +	else
> +		rc-service bluetooth start
> +		rc-update add bluetooth
> +	fi
>  }
>  
>  off() {
> -	case "$SXMO_OS" in
> -		alpine|postmarketos)
> -			rc-service bluetooth stop
> -			rc-update del bluetooth
> -			;;
> -		arch|archarm|nixos|debian)
> -			systemctl stop bluetooth
> -			systemctl disable bluetooth
> -			;;
> -	esac
> +	if command -v systemctl > /dev/null; then
> +		systemctl stop bluetooth
> +		systemctl disable bluetooth
> +	else
> +		rc-service bluetooth stop
> +		rc-update del bluetooth
> +	fi
>  	rfkill block bluetooth
>  }
>  
> -- 
> 2.45.2
> 
Reply to thread Export thread (mbox)