Rework delayed.target
authorINSUN PYO <insun.pyo@samsung.com>
Fri, 19 Jul 2019 08:23:57 +0000 (17:23 +0900)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Wed, 10 Jan 2024 22:18:36 +0000 (23:18 +0100)
start delayed.service --> finish default.target --> start all of delayed.service -->
finish delayed.target --> StartupFinished

Change-Id: I2f291ea8b5f535157eec4f105f2c37b0cea448c9

16 files changed:
Makefile.am
packaging/systemd.spec
packaging/wait-default-target.sh [new file with mode: 0644]
packaging/wait-delayed-target.sh [new file with mode: 0644]
packaging/wait_systemd_startupfinished.sh [deleted file]
units/booting-done.service [new file with mode: 0644]
units/delayed.service [deleted file]
units/delayed.target
units/system-default-target-done.service [new file with mode: 0644]
units/system-delayed-target-done.service [new file with mode: 0644]
units/system-delayed-target-trigger.service [new file with mode: 0644]
units/user/delayed.service [deleted file]
units/user/delayed.target
units/user/user-default-target-done.service [new file with mode: 0644]
units/user/user-delayed-target-done.service [new file with mode: 0644]
units/user/user-delayed-target-trigger.service [new file with mode: 0644]

index 4d345d3..346c7b9 100644 (file)
@@ -269,6 +269,7 @@ SHUTDOWN_TARGET_WANTS =
 LOCAL_FS_TARGET_WANTS =
 MULTI_USER_TARGET_WANTS =
 GRAPHICAL_TARGET_WANTS =
+DELAYED_TARGET_WANTS=
 RESCUE_TARGET_WANTS =
 SYSINIT_TARGET_WANTS =
 SOCKETS_TARGET_WANTS =
@@ -276,6 +277,7 @@ BUSNAMES_TARGET_WANTS =
 TIMERS_TARGET_WANTS =
 USER_SOCKETS_TARGET_WANTS =
 USER_DEFAULT_TARGET_WANTS =
+USER_DELAYED_TARGET_WANTS =
 USER_BUSNAMES_TARGET_WANTS =
 
 SYSTEM_UNIT_ALIASES =
@@ -287,6 +289,7 @@ install-target-wants-hook:
        what="$(LOCAL_FS_TARGET_WANTS)" && wants=local-fs.target && dir=$(systemunitdir) && $(add-wants)
        what="$(MULTI_USER_TARGET_WANTS)" && wants=multi-user.target && dir=$(systemunitdir) && $(add-wants)
        what="$(GRAPHICAL_TARGET_WANTS)" && wants=graphical.target && dir=$(systemunitdir) && $(add-wants)
+       what="$(DELAYED_TARGET_WANTS)" && wants=delayed.target && dir=$(systemunitdir) && $(add-wants)
        what="$(RESCUE_TARGET_WANTS)" && wants=rescue.target && dir=$(systemunitdir) && $(add-wants)
        what="$(SYSINIT_TARGET_WANTS)" && wants=sysinit.target && dir=$(systemunitdir) && $(add-wants)
        what="$(SOCKETS_TARGET_WANTS)" && wants=sockets.target && dir=$(systemunitdir) && $(add-wants)
@@ -294,6 +297,7 @@ install-target-wants-hook:
        what="$(SLICES_TARGET_WANTS)" && wants=slices.target && dir=$(systemunitdir) && $(add-wants)
        what="$(USER_SOCKETS_TARGET_WANTS)" && wants=sockets.target && dir=$(userunitdir) && $(add-wants)
        what="$(USER_DEFAULT_TARGET_WANTS)" && wants=default.target && dir=$(userunitdir) && $(add-wants)
+       what="$(USER_DELAYED_TARGET_WANTS)" && wants=delayed.target && dir=$(userunitdir) && $(add-wants)
 
 install-busnames-target-wants-hook:
        what="$(BUSNAMES_TARGET_WANTS)" && wants=busnames.target && dir=$(systemunitdir) && $(add-wants)
@@ -531,10 +535,18 @@ dist_systemunit_DATA += \
 
 dist_systemunit_DATA += \
        units/delayed.target \
-       units/delayed.service
+       units/booting-done.service \
+       units/system-delayed-target-trigger.service \
+       units/system-default-target-done.service \
+       units/system-delayed-target-done.service
 
 GRAPHICAL_TARGET_WANTS += \
-       delayed.service
+       system-delayed-target-trigger.service \
+       system-default-target-done.service
+
+DELAYED_TARGET_WANTS += \
+       booting-done.service \
+       system-delayed-target-done.service
 
 dist_systemunit_DATA_busnames += \
        units/busnames.target
@@ -587,10 +599,16 @@ dist_userunit_DATA = \
 
 dist_userunit_DATA += \
        units/user/delayed.target \
-       units/user/delayed.service
+       units/user/user-delayed-target-trigger.service \
+       units/user/user-default-target-done.service \
+       units/user/user-delayed-target-done.service
 
 USER_DEFAULT_TARGET_WANTS += \
-       delayed.service
+       user-delayed-target-trigger.service \
+       user-default-target-done.service
+
+USER_DELAYED_TARGET_WANTS += \
+       user-delayed-target-done.service
 
 nodist_userunit_DATA = \
        units/user/systemd-exit.service
index 346a327..95248d6 100644 (file)
@@ -25,7 +25,8 @@ Source0:        https://github.com/systemd/systemd/archive/v%{version}.tar.gz
 Source1:        pamconsole-tmp.conf
 Source2:        %{name}-rpmlintrc
 Source3:        test-runner.c
-Source4:        wait_systemd_startupfinished.sh
+Source4:        wait-default-target.sh
+Source5:        wait-delayed-target.sh
 Source1001:     systemd.manifest
 BuildRequires:  gperf
 BuildRequires:  intltool >= 0.40.0
@@ -306,7 +307,9 @@ ln -sf ./libsystemd.pc %{buildroot}%{_libdir}/pkgconfig/libsystemd-journal.pc
 ln -sf ./libsystemd.pc %{buildroot}%{_libdir}/pkgconfig/libsystemd-login.pc
 
 # Delayed target
-install -m 0755 %{SOURCE4} %{buildroot}%{_bindir}/wait_systemd_startupfinished.sh
+install -m 0755 %{SOURCE4} %{buildroot}%{_bindir}/wait-default-target.sh
+install -m 0755 %{SOURCE5} %{buildroot}%{_bindir}/wait-delayed-target.sh
+
 
 # end of install
 %pre
@@ -537,8 +540,12 @@ fi
 %{_prefix}/lib/systemd/network/99-default.link
 %exclude %{_prefix}/lib/systemd/system-preset/90-systemd.preset
 %{_prefix}/lib/systemd/user/delayed.target
-%{_prefix}/lib/systemd/user/delayed.service
-%{_prefix}/lib/systemd/user/default.target.wants/delayed.service
+%{_prefix}/lib/systemd/user/user-delayed-target-trigger.service
+%{_prefix}/lib/systemd/user/default.target.wants/user-delayed-target-trigger.service
+%{_prefix}/lib/systemd/user/user-default-target-done.service
+%{_prefix}/lib/systemd/user/default.target.wants/user-default-target-done.service
+%{_prefix}/lib/systemd/user/user-delayed-target-done.service
+%{_prefix}/lib/systemd/user/delayed.target.wants/user-delayed-target-done.service
 
 %{_prefix}/lib/systemd/libsystemd-shared-231.so
 %{_prefix}/lib/systemd/libsystemd-shared.so
@@ -592,7 +599,8 @@ fi
 
 %{_localstatedir}/log/journal
 
-%{_bindir}/wait_systemd_startupfinished.sh
+%{_bindir}/wait-default-target.sh
+%{_bindir}/wait-delayed-target.sh
 
 %files -n libsystemd
 %manifest %{name}.manifest
diff --git a/packaging/wait-default-target.sh b/packaging/wait-default-target.sh
new file mode 100644 (file)
index 0000000..c8e3e97
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+for loop in {1..30}
+do
+    echo $1: ${loop}/30
+
+    if [ -f /run/systemd/system/graphical.target.done -a -f /run/user/5001/systemd/default.target.done ]
+    then
+        echo $1: "System and User Default Target Done"
+        # Do nothing, service unit do next step.
+
+        exit 0
+    fi
+
+    /usr/bin/sleep 1
+done
+
+# timeout
+#########################################################################################################
+echo $1: "Default Target 30 Seconds Timeout"
+# Do nothing, service unit do next step.
+
+exit 0
diff --git a/packaging/wait-delayed-target.sh b/packaging/wait-delayed-target.sh
new file mode 100644 (file)
index 0000000..b84378d
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+for loop in {1..30}
+do
+    echo ${loop}/30
+
+    if [ -f /run/systemd/system/delayed.target.done -a -f /run/user/5001/systemd/delayed.target.done -a -f /run/systemd/system/graphical.target.done -a -f /run/user/5001/systemd/default.target.done ]
+    then
+        echo "System and User Delayed Target Done"
+        /usr/bin/vconftool set -t int  memory/sysman/booting_status 1 -f
+        /usr/bin/dbus-send --type=signal --system /org/tizen/system org.tizen.system.Booting.BootingDone int32:1
+
+        exit 0
+    fi
+
+    /usr/bin/sleep 1
+done
+
+# timeout
+#########################################################################################################
+echo "Delayed Target 30 Seconds Timeout"
+/usr/bin/vconftool set -t int  memory/sysman/booting_status 3 -f
+/usr/bin/dbus-send --type=signal --system /org/tizen/system org.tizen.system.Booting.BootingDone int32:3
+
+exit 0
diff --git a/packaging/wait_systemd_startupfinished.sh b/packaging/wait_systemd_startupfinished.sh
deleted file mode 100644 (file)
index 73d6f3d..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-IS_USER_SESSION=" "
-if [ "$1" = "--user" ]
-then
-       IS_USER_SESSION="--user"
-fi
-
-WAIT_CMD="/usr/bin/systemctl "${IS_USER_SESSION}" is-system-running"
-EXEC_CMD="/usr/bin/systemctl --no-block "${IS_USER_SESSION}" start delayed.target"
-
-echo "Wait CMD:" ${WAIT_CMD}
-echo "Exec CMD:" ${EXEC_CMD}
-
-while [ 1 ]
-do
-       STATE=$($WAIT_CMD)
-       echo ${STATE}
-
-       if [ ${STATE} = "running" -o ${STATE} = "degraded" ]
-       then
-               $($EXEC_CMD)
-               exit 0;
-       fi
-
-       /usr/bin/sleep 1
-done
-
diff --git a/units/booting-done.service b/units/booting-done.service
new file mode 100644 (file)
index 0000000..f4591d3
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Description=All Delayed Target Booting Done Service
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+[Service]
+User=system_fw
+Group=system_fw
+ExecStart=/usr/bin/wait-delayed-target.sh
+RemainAfterExit=yes
+SmackProcessLabel=System
diff --git a/units/delayed.service b/units/delayed.service
deleted file mode 100644 (file)
index 62f92c7..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=Trigger System Delayed services
-Requires=graphical.target
-After=graphical.target
-DefaultDependencies=no
-RefuseManualStart=yes
-RefuseManualStop=yes
-
-[Service]
-ExecStart=/usr/bin/wait_systemd_startupfinished.sh
-RemainAfterExit=yes
-SmackProcessLabel=System
index 606868e..1730dda 100644 (file)
@@ -1,2 +1,2 @@
 [Unit]
-Description=System Delayed Services
+Description=System Delayed Target
diff --git a/units/system-default-target-done.service b/units/system-default-target-done.service
new file mode 100644 (file)
index 0000000..9ce2cd8
--- /dev/null
@@ -0,0 +1,16 @@
+[Unit]
+Description=System Default Target Done Service
+After=graphical.target
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+[Service]
+Type=oneshot
+User=system_fw
+Group=system_fw
+ExecStart=/usr/bin/touch /run/systemd/system/graphical.target.done
+RemainAfterExit=yes
+SecureBits=keep-caps
+Capabilities=cap_dac_override=i
+SmackProcessLabel=System
diff --git a/units/system-delayed-target-done.service b/units/system-delayed-target-done.service
new file mode 100644 (file)
index 0000000..03195b2
--- /dev/null
@@ -0,0 +1,16 @@
+[Unit]
+Description=System Delayed Target Done Service
+After=delayed.target
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+[Service]
+Type=oneshot
+User=system_fw
+Group=system_fw
+ExecStart=/usr/bin/touch /run/systemd/system/delayed.target.done
+RemainAfterExit=yes
+SecureBits=keep-caps
+Capabilities=cap_dac_override=i
+SmackProcessLabel=System
diff --git a/units/system-delayed-target-trigger.service b/units/system-delayed-target-trigger.service
new file mode 100644 (file)
index 0000000..e98808e
--- /dev/null
@@ -0,0 +1,17 @@
+[Unit]
+Description=System Delayed Target Trigger Service
+After=basic.target
+Wants=wait-mount@opt-usr.service
+After=wait-mount@opt-usr.service
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+[Service]
+# At least one service must remain, and systemd will not enter the Startupfinished state.
+# So this unit, which is oneshot type, becomes that one service.
+Type=oneshot
+ExecStart=/usr/bin/wait-default-target.sh System
+ExecStart=/usr/bin/systemctl --no-block start delayed.target
+RemainAfterExit=yes
+SmackProcessLabel=System
diff --git a/units/user/delayed.service b/units/user/delayed.service
deleted file mode 100644 (file)
index 8ed5a99..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-[Unit]
-Description=Trigger User Delayed Services
-Requires=default.target
-After=default.target
-DefaultDependencies=no
-RefuseManualStart=yes
-RefuseManualStop=yes
-
-[Service]
-ExecStart=/usr/bin/wait_systemd_startupfinished.sh --user
-RemainAfterExit=yes
index ae06405..420deee 100644 (file)
@@ -1,2 +1,2 @@
 [Unit]
-Description=User Delayed Services
+Description=User Delayed Target
diff --git a/units/user/user-default-target-done.service b/units/user/user-default-target-done.service
new file mode 100644 (file)
index 0000000..e7c3d82
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Description=User Default Target Done Service
+After=default.target
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/touch /run/user/5001/systemd/default.target.done
+RemainAfterExit=yes
diff --git a/units/user/user-delayed-target-done.service b/units/user/user-delayed-target-done.service
new file mode 100644 (file)
index 0000000..3a9b51e
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Description=User Delayed Target Done Service
+After=delayed.target
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/touch /run/user/5001/systemd/delayed.target.done
+RemainAfterExit=yes
diff --git a/units/user/user-delayed-target-trigger.service b/units/user/user-delayed-target-trigger.service
new file mode 100644 (file)
index 0000000..5619c3d
--- /dev/null
@@ -0,0 +1,16 @@
+[Unit]
+Description=User Delayed Target Trigger Service
+After=basic.target
+DefaultDependencies=no
+Wants=wait-mount@opt-usr.service
+After=wait-mount@opt-usr.service
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+[Service]
+# At least one service must remain, and systemd will not enter the Startupfinished state.
+# So this unit, which is oneshot type, becomes that one service.
+Type=oneshot
+ExecStart=/usr/bin/wait-default-target.sh User
+ExecStart=/usr/bin/systemctl --no-block --user start delayed.target
+RemainAfterExit=yes