【发布时间】:2021-07-27 13:22:06
【问题描述】:
我有多个使用 supervisord 在 Ubuntu 后台运行的 .NET Core 程序(见下文)。该 supervisord.conf 位于 Hello-World 文件夹中。
[program:hello-world-1]
command = /all-hello-worlds/dotMemory-Cli-Linux/tools/dotMemory.sh start-net-core --service-input=null --trigger-max-snapshots=5 --trigger-delay=2m --trigger-timer=00:01:00 Hello-World-1.dll
directory = /all-hello-worlds/Hello-World-1
autostart = true
autorestart = unexpected
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
在每个 supervisord.conf 中,我使用:
dotMemory.sh start-net-core --trigger-delay=1m --trigger-timer=00:00:10 ./HelloWorld.dll
当 supervisord 在后台运行 .NET Core 程序时,我可以看到 dotMemory 打印消息说“Press Ctrl+C to end the profiling”
这些 .NET Core 程序捆绑在一个 Dorker 容器中,该容器运行 /usr/bin/supervisord -c /all-hello-worlds/supervisord.conf
这是另一个名为 supervisord.conf 的 supervisord.conf,位于 all-hello-worlds 文件夹中
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
nodaemon = true ; run in the background aka daemonizing
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /all-hello-worlds/*/supervisord.conf
您可以将 Ubuntu 中的文件夹结构可视化如下:
all-hello-worlds (root folder)
| --- dotMemory-Cli-Linux
| --- supervisord.conf
| --- Hello-World-1
| --- Hello-World-1.dll
| --- supervisord.conf
| --- Hello-World-2
| --- Hello-World-2.dll
| --- supervisord.conf
现在我很难将 Ctrl-C 命令发送到 supervisord Hello-World 进程。如果我使用supervisorctl stop Hello-World-1,dotMemory 无法正确保存 DMW 文件,我需要使用dotMemory recover 方法获取 DMW 文件(很麻烦)
如果我使用kill -SIGINT [dotMemory process ID],supervisord 会重新启动进程并且不会正确保存 DMW 文件。
有没有办法通过 supervisord 向后台运行的 dotMemory 发送 Ctrl-C 命令? 我在这里附加了 2 个 supervisord.conf 文件。
如果您需要我提供更多信息,请告诉我。 谢谢。
【问题讨论】:
-
如果由于某种原因 dotMemory 实际上需要控制字符而不是 SIGINT,您可以尝试
echo '\x3' > /proc/{pid}/fd/0。通常这不会起作用,因为进程需要 SIGINT 并忽略控制字符。 -
编辑:忘记了 echo 命令中的
-e开关。但是,我使用 dotnet 应用程序进行了快速测试,它似乎没有触发Console.ReadKey。 -
@MrPaulch,你的意思是
echo '\x3' > /proc/{pid}/fd/0还是echo -e '\x3' > /proc/{pid}/fd/0? -
如果 Anna 的帖子回答了您的问题,请接受它作为答案。谢谢。
标签: .net supervisord dotmemory