Skip to content

Commit 35822f3

Browse files
ryncsnjohannbg
authored andcommitted
fix(memstrack): drop bash runtime requirement
Use nohup instead of disown, and let systemd track the service properly. This makes the scripts POSIX compatible and bash is no longer needed. Signed-off-by: Kairui Song <[email protected]>
1 parent b3d2dcb commit 35822f3

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

modules.d/99memstrack/memstrack-start.sh

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
# Mount kernel debug fs so debug tools can work.
33
# memdebug=4 and memdebug=5 requires debug fs to be mounted.
44
# And there is no need to umount it.
@@ -20,8 +20,6 @@ is_debugfs_ready() {
2020
}
2121

2222
prepare_debugfs() {
23-
local trace_base
24-
2523
trace_base=$(get_trace_base)
2624
# old debugfs interface case.
2725
if ! [ -d "$trace_base/tracing" ]; then
@@ -44,10 +42,10 @@ fi
4442
if [ -n "$DEBUG_MEM_LEVEL" ]; then
4543
if [ "$DEBUG_MEM_LEVEL" -ge 5 ]; then
4644
echo "memstrack - will report kernel module memory usage summary and top allocation stack"
47-
memstrack --report module_summary,module_top --notui --throttle 80 -o /.memstrack &
45+
nohup memstrack --report module_summary,module_top --notui --throttle 80 -o /.memstrack > /dev/null &
4846
elif [ "$DEBUG_MEM_LEVEL" -ge 4 ]; then
4947
echo "memstrack - will report memory usage summary"
50-
memstrack --report module_summary --notui --throttle 80 -o /.memstrack &
48+
nohup memstrack --report module_summary --notui --throttle 80 -o /.memstrack > /dev/null &
5149
else
5250
exit 0
5351
fi
@@ -61,9 +59,7 @@ if [ $RET -ne 0 ]; then
6159
exit $RET
6260
fi
6361

62+
echo $PID > /run/memstrack.pid
63+
6464
# Wait a second for memstrack to setup everything, avoid missing any event
6565
sleep 1
66-
67-
echo $PID > /run/memstrack.pid
68-
# bash specific - non posix
69-
disown

modules.d/99memstrack/memstrack.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ConditionKernelCommandLine=|rd.memdebug=4
77
ConditionKernelCommandLine=|rd.memdebug=5
88

99
[Service]
10-
Type=simple
10+
Type=forking
1111
ExecStart=/bin/memstrack-start
1212
PIDFile=/run/memstrack.pid
1313
StandardInput=null

modules.d/99memstrack/module-setup.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ check() {
1111
}
1212

1313
depends() {
14-
echo systemd bash
14+
echo systemd
1515
return 0
1616
}
1717

1818
install() {
19-
inst_multiple pgrep pkill
19+
inst_multiple pgrep pkill nohup
2020
inst "/bin/memstrack" "/bin/memstrack"
2121

2222
inst "$moddir/memstrack-start.sh" "/bin/memstrack-start"

0 commit comments

Comments
 (0)