[RFC] initscripts: Add switch to start processes in background

Message ID 20210727085900.2253-1-michael.tremer@ipfire.org
State Accepted
Commit 0c7ba6523fdcf495d90b7d3f15065f712ec36e1c
Headers
Series [RFC] initscripts: Add switch to start processes in background |

Commit Message

Michael Tremer July 27, 2021, 8:59 a.m. UTC
  Since systemd, many programs no longer behave like a well-behaved
daemon. To avoid any extra solutions, this patch adds a -b switch which
will start a program in the background and throw away any output.

The behaviour remains unchanged for any other programs.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 src/initscripts/system/functions | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
  

Comments

Holger Sunke July 28, 2021, 5:31 p.m. UTC | #1
This works for me, thank you.

Am 27.07.21 um 10:59 schrieb Michael Tremer:
> Since systemd, many programs no longer behave like a well-behaved
> daemon. To avoid any extra solutions, this patch adds a -b switch which
> will start a program in the background and throw away any output.
> 
> The behaviour remains unchanged for any other programs.
> 
> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
> ---
>   src/initscripts/system/functions | 17 +++++++++++++++--
>   1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions
> index d610a524d..e44a2b4a1 100644
> --- a/src/initscripts/system/functions
> +++ b/src/initscripts/system/functions
> @@ -436,6 +436,7 @@ getpids()
>   #*******************************************************************************
>   loadproc()
>   {
> +	local background=""
>   	local pidfile=""
>   	local forcestart=""
>   	local nicelevel=""
> @@ -448,6 +449,10 @@ loadproc()
>     while true
>   	do
>   		case "${1}" in
> +			-b)
> +				background="1"
> +				shift 1
> +				;;
>   			-f)
>   				forcestart="1"
>   				shift 1
> @@ -506,8 +511,16 @@ loadproc()
>   		cmd="nice -n "${nicelevel}" ${cmd}"
>   	fi
>   
> -	${cmd}
> -	evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
> +	if [ -n "${background}" ]; then
> +		(
> +			${cmd} &>/dev/null
> +		) &
> +		evaluate_retval
> +	else
> +		${cmd}
> +		evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
> +	fi
> +
>   	return 0
>   }
>   
>
  
Michael Tremer Aug. 4, 2021, 2:34 p.m. UTC | #2
Cool. Thanks for the feedback.

@Arne: Please merge this patch.

-Michael

> On 28 Jul 2021, at 19:31, Holger Sunke <holger.sunke@posteo.de> wrote:
> 
> This works for me, thank you.
> 
> Am 27.07.21 um 10:59 schrieb Michael Tremer:
>> Since systemd, many programs no longer behave like a well-behaved
>> daemon. To avoid any extra solutions, this patch adds a -b switch which
>> will start a program in the background and throw away any output.
>> The behaviour remains unchanged for any other programs.
>> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
>> ---
>>  src/initscripts/system/functions | 17 +++++++++++++++--
>>  1 file changed, 15 insertions(+), 2 deletions(-)
>> diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions
>> index d610a524d..e44a2b4a1 100644
>> --- a/src/initscripts/system/functions
>> +++ b/src/initscripts/system/functions
>> @@ -436,6 +436,7 @@ getpids()
>>  #*******************************************************************************
>>  loadproc()
>>  {
>> +	local background=""
>>  	local pidfile=""
>>  	local forcestart=""
>>  	local nicelevel=""
>> @@ -448,6 +449,10 @@ loadproc()
>>    while true
>>  	do
>>  		case "${1}" in
>> +			-b)
>> +				background="1"
>> +				shift 1
>> +				;;
>>  			-f)
>>  				forcestart="1"
>>  				shift 1
>> @@ -506,8 +511,16 @@ loadproc()
>>  		cmd="nice -n "${nicelevel}" ${cmd}"
>>  	fi
>>  -	${cmd}
>> -	evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
>> +	if [ -n "${background}" ]; then
>> +		(
>> +			${cmd} &>/dev/null
>> +		) &
>> +		evaluate_retval
>> +	else
>> +		${cmd}
>> +		evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
>> +	fi
>> +
>>  	return 0
>>  }
>>
  

Patch

diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions
index d610a524d..e44a2b4a1 100644
--- a/src/initscripts/system/functions
+++ b/src/initscripts/system/functions
@@ -436,6 +436,7 @@  getpids()
 #*******************************************************************************
 loadproc()
 {
+	local background=""
 	local pidfile=""
 	local forcestart=""
 	local nicelevel=""
@@ -448,6 +449,10 @@  loadproc()
   while true
 	do
 		case "${1}" in
+			-b)
+				background="1"
+				shift 1
+				;;
 			-f)
 				forcestart="1"
 				shift 1
@@ -506,8 +511,16 @@  loadproc()
 		cmd="nice -n "${nicelevel}" ${cmd}"
 	fi
 
-	${cmd}
-	evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
+	if [ -n "${background}" ]; then
+		(
+			${cmd} &>/dev/null
+		) &
+		evaluate_retval
+	else
+		${cmd}
+		evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
+	fi
+
 	return 0
 }