You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .devcontainer/bin/init-dev-container.sh
+18-21Lines changed: 18 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,24 @@ startInBackgroundIfNotRunning()
8
8
{
9
9
log "Starting $1."
10
10
echo -e "\n** $(date) **"| sudoIf tee -a /tmp/$1.log > /dev/null
11
-
if [ !-f"/tmp/$1.pid" ] ||! ps -p $(cat /tmp/$1.pid)> /dev/null;then
12
-
($2 sh -c "while :; do echo [\$(date)] Process started.; $3; echo [\$(date)] Process exited!; sleep 5; done 2>&1"| sudoIf tee -a /tmp/$1.log > /dev/null &echo"$!"| sudoIf tee /tmp/$1.pid > /dev/null)
13
-
log "$1 started."
11
+
if! pidof $1> /dev/null;then
12
+
keepRunningInBackground "$@"
14
13
else
15
14
echo"$1 is already running."| sudoIf tee -a /tmp/$1.log > /dev/null
16
15
log "$1 is already running."
17
16
fi
18
17
}
19
18
19
+
# Keep command running in background
20
+
keepRunningInBackground()
21
+
{
22
+
($2 sh -c "while :; do echo [\$(date)] Process started.; $3; echo [\$(date)] Process exited!; sleep 5; done 2>&1"| sudoIf tee -a /tmp/$1.log > /dev/null &echo"$!"| sudoIf tee /tmp/$1.pid > /dev/null)
23
+
while! pidof $1> /dev/null;do
24
+
sleep 1
25
+
done
26
+
log "$1 started."
27
+
}
28
+
20
29
# Use sudo to run as root when required
21
30
sudoIf()
22
31
{
@@ -47,7 +56,7 @@ log "** SCRIPT START **"
47
56
48
57
# Start dbus.
49
58
log 'Running "/etc/init.d/dbus start".'
50
-
if [ -f"/var/run/dbus/pid" ] &&!ps -p $(cat /var/run/dbus/pid)> /dev/null;then
59
+
if [ -f"/var/run/dbus/pid" ] &&!pidof dbus-daemon > /dev/null;then
51
60
sudoIf rm -f /var/run/dbus/pid
52
61
fi
53
62
sudoIf /etc/init.d/dbus start 2>&1| sudoIf tee -a /tmp/dbus-daemon-system.log > /dev/null
0 commit comments