Browse Source

make, meson: Some configurable options in compile time

DEFAULT_AUTO_RESTART, DEFAULT_START_TIMEOUT and DEFAULT_STOP_TIMEOUT are new options
available in compile time for configuring some default options. Default values are in brackets:

DEFAULT_AUTO_RESTART: Enable/disable auto-restart for services by default [true]
DEFAULT_START_TIMEOUT: Default start-timeout for services [60]
DEFAULT_STOP_TIMEOUT: Default stop-timeout for services [10]

Signed-off-by: Mobin "Hojjat" Aydinfar <mobin@mobintestserver.ir>
Mobin 10 months ago
parent
commit
a8b3602963

+ 9 - 0
BUILD

@@ -126,6 +126,15 @@ USE_INITGROUPS=1|0
     Whether to initialize supplementary groups for run-as services. The C API for this is not
     in POSIX, but is in practice supported on just about every relevant system, so it is enabled
     by default. If it is not supported on yours, you can explicitly disable it.
+DEFAULT_AUTO_RESTART=true|false
+    Enable/disable auto-restart for services by default. It's true by default.
+DEFAULT_START_TIMEOUT=XXX
+    Specifies the time in seconds allowed for the service to start. If the service takes longer
+    than this, its process group enters the "stopping" state. It's 60 seconds by default.
+DEFAULT_STOP_TIMEOUT=XXX
+    Specifies the time in seconds allowed for the service to stop. If the service takes longer than
+    this, its process group is sent a SIGKILL signal which should cause it to terminate immediately.
+    It's 10 seconds by default.
 
 
 Running test suite

+ 18 - 0
BUILD_MESON

@@ -137,6 +137,24 @@ Custom options:
  man-pages                 : Building Dinit's man-pages.
                              Available values : true, false
                              Default value : true
+
+ default-auto-restart      : Enable/disable auto-restart for services by default.
+                             Available values : true, false
+                             Default value : true
+
+ default-start-timeout     : Default start-timeout for services by default.
+                             Specifies the time in seconds allowed for the service to start.
+                             If the service takes longer than this, its process group enters
+                             the "stopping" state.
+                             Available values : any positive integer
+                             Default value : 60
+
+ default-stop-timeout      : Default stop-timeout for services by default.
+                             Specifies the time in seconds allowed for the service to stop.
+                             If the service takes longer than this, its process group is sent
+                             a SIGKILL signal which should cause it to terminate immediately.
+                             Available values : any positive integer
+                             Default value : 10
                              
  support-cgroups           : Enable Cgroups supprot.
                              Available values : enabled, disabled, auto

+ 3 - 0
build/Makefile

@@ -11,6 +11,9 @@ includes/mconfig.h: ../mconfig tools/mconfig-gen.cc version.conf
 	$(MAKE) -C tools mconfig-gen
 	./tools/mconfig-gen SBINDIR=$(SBINDIR) SYSCONTROLSOCKET=$(SYSCONTROLSOCKET) \
 		SHUTDOWN_PREFIX=$(SHUTDOWN_PREFIX) VERSION=$(VERSION) \
+		DEFAULT_AUTO_RESTART=$(DEFAULT_AUTO_RESTART) \
+		DEFAULT_START_TIMEOUT=$(DEFAULT_START_TIMEOUT) \
+		DEFAULT_STOP_TIMEOUT=$(DEFAULT_STOP_TIMEOUT) \
 		$(if $(SUPPORT_CGROUPS),SUPPORT_CGROUPS=$(SUPPORT_CGROUPS),) \
 		$(if $(USE_UTMPX),USE_UTMPX=$(USE_UTMPX),) \
 		$(if $(USE_INITGROUPS),USE_INITGROUPS=$(USE_INITGROUPS),) > includes/mconfig.h

+ 9 - 0
build/tools/mconfig-gen.cc

@@ -77,6 +77,15 @@ int main(int argc, char **argv)
     if (vars.find("SUPPORT_CGROUPS") != vars.end()) {
         cout << "#define SUPPORT_CGROUPS " << vars["SUPPORT_CGROUPS"] << "\n";
     }
+    if (vars.find("DEFAULT_AUTO_RESTART") != vars.end()) {
+	cout << "#define DEFAULT_AUTO_RESTART " << vars["DEFAULT_AUTO_RESTART"] << "\n";
+    }
+    if (vars.find("DEFAULT_START_TIMEOUT") != vars.end()) {
+	cout << "#define DEFAULT_START_TIMEOUT " << vars["DEFAULT_START_TIMEOUT"] << "\n";
+    }
+    if (vars.find("DEFAULT_STOP_TIMEOUT") != vars.end()) {
+    cout << "#define DEFAULT_STOP_TIMEOUT " << vars["DEFAULT_STOP_TIMEOUT"] << "\n";
+    }
 
     cout << "\n// Constants\n";
     cout << "\nconstexpr static char DINIT_VERSION[] = " << stringify(vars["VERSION"]) << ";\n";

+ 7 - 0
configs/mconfig.Darwin

@@ -19,3 +19,10 @@ BUILD_SHUTDOWN=no
 
 # Notes:
 #   -flto (optional) : Use link-time optimisation
+
+
+# Service defaults.
+
+DEFAULT_AUTO_RESTART=true
+DEFAULT_START_TIMEOUT=60
+DEFAULT_STOP_TIMEOUT=10

+ 7 - 0
configs/mconfig.FreeBSD

@@ -25,3 +25,10 @@ BUILD_SHUTDOWN=no
 #   -fsanitize=address,undefined :  Apply sanitizers (during unit tests)
 #
 # Old versions of FreeBSD had issues with -fno-plt/-fno-rtti.
+
+
+# Service defaults.
+
+DEFAULT_AUTO_RESTART=true
+DEFAULT_START_TIMEOUT=60
+DEFAULT_STOP_TIMEOUT=10

+ 7 - 0
configs/mconfig.Linux

@@ -34,3 +34,10 @@ TEST_LDFLAGS=$(LDFLAGS) $(TEST_CXXFLAGS)
 # Features.
 
 SUPPORT_CGROUPS=1
+
+
+# Service defaults.
+
+DEFAULT_AUTO_RESTART=true
+DEFAULT_START_TIMEOUT=60
+DEFAULT_STOP_TIMEOUT=10

+ 11 - 0
configs/mconfig.Linux.sh

@@ -106,8 +106,19 @@ FEATURE_SETTINGS=$(
   echo "SUPPORT_CGROUPS=1"
 )
 
+SERVICE_DEFAULTS=$(
+  echo ""
+  echo ""
+  echo "# Service defaults"
+  echo ""
+  echo "DEFAULT_AUTO_RESTART=true"
+  echo "DEFAULT_START_TIMEOUT=60"
+  echo "DEFAULT_STOP_TIMEOUT=10"
+)
+
 (
   echo "$INST_PATH_OPTS"
   echo "$GENERAL_BUILD_SETTINGS" 
   echo "$FEATURE_SETTINGS"
+  echo "$SERVICE_DEFAULTS"
 ) >> ../mconfig

+ 7 - 0
configs/mconfig.OpenBSD

@@ -19,3 +19,10 @@ BUILD_SHUTDOWN=no
 
 # Notes:
 #   -fno-rtti (optional) : Dinit does not require C++ Run-time Type Information
+
+
+# Service defaults.
+
+DEFAULT_AUTO_RESTART=true
+DEFAULT_START_TIMEOUT=60
+DEFAULT_STOP_TIMEOUT=10

+ 16 - 0
configure

@@ -141,6 +141,10 @@ Optional options:
   --disable-utmpx               Disable manipulating the utmp/utmpx database via the related POSIX functions
   --enable-initgroups           Enable initialization of supplementary groups for run-as [default]
   --disable-initgroups          Disable initialization of supplementary groups for run-as
+  --enable-auto-restart         Enable auto-restart for services by default [Enabled]
+  --disable-auto-restart        Disable auto-restart for services by default
+  --default-start-timeout=sec   Default start-timeout for services [60]
+  --default-stop-timeout=sec    Default stop-timeout for services [10]
 
 Build variables:
   Note: build variables can be passed in the environment, or as $0 argument (as "var=VALUE").
@@ -208,6 +212,8 @@ for arg in "$@"; do
         --exec-prefix=*) EPREFIX="${arg#*=}" && shift;;
         --sbindir=*) SBINDIR="${arg#*=}" && shift ;;
         --mandir=*) MANDIR="${arg#*=}" && shift ;;
+        --default-start-timeout=*) DEFAULT_START_TIMEOUT="${arg#*=}" && shift ;;
+        --default-stop-timeout=*) DEFAULT_STOP_TIMEOUT="${arg#*=}" && shift ;;
         --syscontrolsocket=*) SYSCONTROLSOCKET="${arg#*=}" && shift ;;
         --shutdown-prefix=*) SHUTDOWN_PREFIX="${arg#*=}" && shift ;;
         --enable-shutdown|--enable-shutdown=yes) BUILD_SHUTDOWN=yes ;;
@@ -218,6 +224,8 @@ for arg in "$@"; do
         --disable-utmpx|--enable-utmpx=no) USE_UTMPX=0 ;;
         --enable-initgroups|--enable-initgroups=yes) USE_INITGROUPS=1 ;;
         --disable-initgroups|--enable-initgroups=no) USE_INITGROUPS=0 ;;
+        --enable-auto-restart|--enable-auto-restart=yes) DEFAULT_AUTO_RESTART=true ;;
+        --disable-auto-restart|--enable-auto-restart=no) DEFAULT_AUTO_RESTART=false ;;
         CXX=*|CXX_FOR_BUILD=*|CXXFLAGS_FOR_BUILD=*|CPPFLAGS_FOR_BUILD=*\
         |LDFLAGS_FOR_BUILD=*|CXXFLAGS=*|CXXFLAGS_EXTRA=*|TEST_CXXFLAGS=*\
         |TEST_CXXFLAGS_EXTRA|LDFLAGS=*|LDFLAGS_EXTRA=*|TEST_LDFLAGS=*\
@@ -239,6 +247,9 @@ done
 : "${CPPFLAGS:=""}"
 : "${LDFLAGS_EXTRA:=""}"
 : "${TEST_LDFLAGS_EXTRA:=""}"
+: "${DEFAULT_AUTO_RESTART:="true"}"
+: "${DEFAULT_START_TIMEOUT:="60"}"
+: "${DEFAULT_STOP_TIMEOUT:="10"}"
 if [ "$PLATFORM" = "Linux" ]; then
     : "${BUILD_SHUTDOWN:="yes"}"
     : "${SUPPORT_CGROUPS:="1"}"
@@ -368,6 +379,11 @@ SUPPORT_CGROUPS=$SUPPORT_CGROUPS
 
 # Optional settings
 SHUTDOWN_PREFIX=${SHUTDOWN_PREFIX:-}
+
+# Service defaults
+DEFAULT_AUTO_RESTART=$DEFAULT_AUTO_RESTART
+DEFAULT_START_TIMEOUT=$DEFAULT_START_TIMEOUT
+DEFAULT_STOP_TIMEOUT=$DEFAULT_STOP_TIMEOUT
 _EOF
 if [ -n "${USE_UTMPX:-}" ]; then
     echo "USE_UTMPX=$USE_UTMPX" >> mconfig

+ 3 - 1
doc/manpages/Makefile

@@ -36,7 +36,9 @@ dinit-monitor.8: dinit-monitor.8.m4
 	m4 -DVERSION=$(VERSION) -DMONTH=$(MONTH) -DYEAR=$(YEAR) dinit-monitor.8.m4 > dinit-monitor.8
 
 dinit-service.5: dinit-service.5.m4
-	m4 -DVERSION=$(VERSION) -DMONTH=$(MONTH) -DYEAR=$(YEAR) dinit-service.5.m4 > dinit-service.5
+	m4 -DVERSION=$(VERSION) -DMONTH=$(MONTH) -DYEAR=$(YEAR) -DDEFAULT_AUTO_RESTART=$(DEFAULT_AUTO_RESTART)\
+	   -DDEFAULT_START_TIMEOUT=$(DEFAULT_START_TIMEOUT)\
+	   -DDEFAULT_STOP_TIMEOUT=$(DEFAULT_STOP_TIMEOUT) dinit-service.5.m4 > dinit-service.5
 
 shutdown.8: shutdown.8.m4
 	m4 -DVERSION=$(VERSION) -DMONTH=$(MONTH) -DYEAR=$(YEAR) -DSHUTDOWN_PREFIX=$(SHUTDOWN_PREFIX) shutdown.8.m4 > shutdown.8

+ 5 - 3
doc/manpages/dinit-service.5.m4

@@ -170,7 +170,9 @@ That means this path is static and cannot itself have variable substitutions (se
 Indicates whether the service should automatically restart if it stops, including due to
 unexpected process termination or a dependency stopping.
 Note that if a service stops due to user request, automatic restart is inhibited.
-The default is to automatically restart.
+$$$ifelse(DEFAULT_AUTO_RESTART, true, The default is to automatically restart.,
+    The default is to not automatically restart.)
+@@@
 .TP
 \fBsmooth\-recovery\fR = {yes | true | no | false}
 Applies only to \fBprocess\fR and \fBbgprocess\fR services.
@@ -203,7 +205,7 @@ and enters the "stopping" state (this may be subject to a stop timeout, as
 specified via \fBstop\-timeout\fR, after which the process group will be
 terminated via SIGKILL).
 The timeout period begins only when all dependencies have been stopped.
-The default timeout is 60 seconds.
+The default timeout is $$$DEFAULT_START_TIMEOUT@@@ seconds.
 Specify a value of 0 to allow unlimited start time.
 .TP
 \fBstop\-timeout\fR = \fIXXX.YYY\fR
@@ -211,7 +213,7 @@ Specifies the time in seconds allowed for the service to stop.
 If the service takes longer than this, its process group is sent a SIGKILL signal
 which should cause it to terminate immediately.
 The timeout period begins only when all dependent services have already stopped.
-The default timeout is 10 seconds.
+The default timeout is $$$DEFAULT_STOP_TIMEOUT@@@ seconds.
 Specify a value of 0 to allow unlimited stop time.
 .TP
 \fBpid\-file\fR = \fIpath-to-file\fR

+ 3 - 0
doc/manpages/meson.build

@@ -14,6 +14,9 @@ foreach man: ['dinit-service.5', 'dinit.8', 'dinitcheck.8', 'dinitctl.8', 'dinit
             '-DMONTH='+month,
             '-DYEAR='+year,
             '-DSHUTDOWN_PREFIX='+shutdown_prefix,
+            '-DDEFAULT_AUTO_RESTART='+default_auto_restart,
+            '-DDEFAULT_START_TIMEOUT='+default_start_timeout,
+            '-DDEFAULT_STOP_TIMEOUT='+default_stop_timeout,
             '@INPUT@'
         ],
         capture: true,

+ 6 - 0
meson.build

@@ -34,6 +34,9 @@ man_pages = get_option('man-pages')
 support_cgroups = get_option('support-cgroups')
 use_utmpx = get_option('use-utmpx')
 use_initgroups = get_option('use-initgroups')
+default_auto_restart = get_option('default-auto-restart').to_string()
+default_start_timeout = get_option('default-start-timeout').to_string()
+default_stop_timeout = get_option('default-stop-timeout').to_string()
 # We have custom sbindir for install programs (/sbin instead of /usr/sbin/ by default)
 # By default: Prefix = /usr
 # By default: Sbin = /sbin
@@ -59,6 +62,9 @@ mconfig_data.set('DINIT_VERSION', '"' + meson.project_version() + '"')
 mconfig_data.set('SYSCONTROLSOCKET', '"' + dinit_control_socket_path + '"')
 mconfig_data.set('SBINDIR', '"' + sbindir + '"')
 mconfig_data.set('SHUTDOWN_PREFIX', '"' + shutdown_prefix + '"')
+mconfig_data.set('DEFAULT_AUTO_RESTART', default_auto_restart)
+mconfig_data.set('DEFAULT_START_TIMEOUT', default_start_timeout)
+mconfig_data.set('DEFAULT_STOP_TIMEOUT', default_stop_timeout)
 if support_cgroups.auto() and platform == 'linux' or support_cgroups.enabled()
     mconfig_data.set('SUPPORT_CGROUPS', '1') 
 endif

+ 18 - 0
meson_options.txt

@@ -58,6 +58,24 @@ option(
     value : true,
     description : 'Building & installing man-pages.'
 )
+option(
+    'default-auto-restart',
+    type : 'boolean',
+    value : true,
+    description : 'Enable/disable auto-restart for services by default.'
+)
+option(
+    'default-start-timeout',
+    type : 'integer',
+    value : 60,
+    description : 'Default start-timeout for services in seconds'
+)
+option(
+    'default-stop-timeout',
+    type : 'integer',
+    value : 10,
+    description : 'Default stop-timeout for services in seconds'
+)
 
 ## Linux specific options
 option(

+ 3 - 3
src/includes/load-service.h

@@ -814,7 +814,7 @@ class service_settings_wrapper
     unsigned max_log_buffer_sz = 4096;
     service_flags_t onstart_flags;
     int term_signal = SIGTERM;  // termination signal
-    bool auto_restart = true;
+    bool auto_restart = DEFAULT_AUTO_RESTART;
     bool smooth_recovery = false;
     string socket_path;
     int socket_perms = 0666;
@@ -827,8 +827,8 @@ class service_settings_wrapper
     timespec restart_interval = { .tv_sec = 10, .tv_nsec = 0 };
     int max_restarts = 3;
     timespec restart_delay = { .tv_sec = 0, .tv_nsec = 200000000 };
-    timespec stop_timeout = { .tv_sec = 10, .tv_nsec = 0 };
-    timespec start_timeout = { .tv_sec = 60, .tv_nsec = 0 };
+    timespec stop_timeout = { .tv_sec = DEFAULT_STOP_TIMEOUT, .tv_nsec = 0 };
+    timespec start_timeout = { .tv_sec = DEFAULT_START_TIMEOUT, .tv_nsec = 0 };
     std::vector<service_rlimits> rlimits;
 
     int readiness_fd = -1;      // readiness fd in service process