0

I have a containerized unimrcp server and it is running as kubernetes pod. When I go inside container and do ps -ef its output is like this:

[root@unimrcp-0 fd]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0 99 13:13 ?        01:07:38 ./unimrcpserver
root        75     1  0 13:13 ?        00:00:00 [arping] <defunct>
root        76     1  0 13:13 ?        00:00:00 [arping] <defunct>
root       154     0  0 13:14 pts/0    00:00:00 /bin/bash
root       209   154  0 14:21 pts/0    00:00:00 ps -ef

Also if I do cat /proc/[pid]/fd/1 then I am seeing some corrupted output like this:

unknown command: ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒

Why there is no controlling terminal attached with the process. I have disabled the Unimrcp from logging to stdout. Also the CPU utilization is 99%. Can someone please help to solve this?

This is the entrypoint of the container

#!/bin/sh
source /ip-conf.sh; set_control_media_network "UNIMRCP"
CONTROL_IP=$(get_control_ipv4)
MEDIA_IP=$(get_media_ipv4)
LOG_LEVEL=$(echo $LOG_LEVEL | tr -s " " | xargs)
LOG_OUTPUT=$(echo $LOG_OUTPUT | tr -s " " | xargs)
LOG_HEADERS=$(echo $LOG_HEADERS | tr -s " " | xargs)
sed -i 's+<priority>.*</priority>+''<priority>'$LOG_LEVEL'</priority>+g' 
/usr/local/unimrcp/conf/logger.xml
sed -i 's+<output>.*</output>+''<output>'$LOG_OUTPUT'</output>+g' 
/usr/local/unimrcp/conf/logger.xml
sed -i 's+<headers>.*</headers>+''<headers>'$LOG_HEADERS'</headers>+g' 
/usr/local/unimrcp/conf/logger.xml
sed -i 's+<!-- <ip>.*</ip> -->+''<ip>'$CONTROL_IP'</ip>+g' 
/usr/local/unimrcp/conf/unimrcpserver.xml
sed -i 's+<!-- <rtp-ip>.*</rtp-ip> -->+''<rtp-ip>'$MEDIA_IP'</rtp-ip>+g' 
/usr/local/unimrcp/conf/unimrcpserver.xml 
cd /usr/local/unimrcp/bin/
exec ./unimrcpserver

This is the output of the ls -l at the /proc/1/fd/ inside the unimrcp container

total 0
lrwx------ 1 root root 64 Jan  2 12:04 0 -> /dev/null
l-wx------ 1 root root 64 Jan  2 12:04 1 -> pipe:[17601930]
l-wx------ 1 root root 64 Jan  2 12:04 10 -> pipe:[17605635]
lrwx------ 1 root root 64 Jan  2 12:04 11 -> socket:[17605636]
lrwx------ 1 root root 64 Jan  2 12:04 12 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Jan  2 12:04 13 -> anon_inode:[eventfd]
lrwx------ 1 root root 64 Jan  2 12:04 14 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Jan  2 12:04 15 -> anon_inode:[eventfd]
lrwx------ 1 root root 64 Jan  2 12:04 16 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Jan  2 12:04 17 -> socket:[17602110]
lrwx------ 1 root root 64 Jan  2 12:04 18 -> socket:[17602111]
lrwx------ 1 root root 64 Jan  2 12:04 19 -> anon_inode:[eventpoll]
l-wx------ 1 root root 64 Jan  2 12:04 2 -> pipe:[17601931]
lrwx------ 1 root root 64 Jan  2 12:04 20 -> socket:[17603083]
lrwx------ 1 root root 64 Jan  2 12:04 21 -> socket:[17603084]
lr-x------ 1 root root 64 Jan  2 12:04 22 -> /dev/urandom
lrwx------ 1 root root 64 Jan  2 12:04 23 -> socket:[17603087]
lrwx------ 1 root root 64 Jan  2 12:04 24 -> socket:[17603088]
l-wx------ 1 root root 64 Jan  2 12:04 3 -> 
/usr/local/unimrcp/log/unimrcpserver_2020.01.02_12.04.08.988860.log
lrwx------ 1 root root 64 Jan  2 12:04 4 -> anon_inode:[eventpoll]
lr-x------ 1 root root 64 Jan  2 12:04 5 -> pipe:[17605633]
l-wx------ 1 root root 64 Jan  2 12:04 6 -> pipe:[17605633]
lrwx------ 1 root root 64 Jan  2 12:04 7 -> socket:[17605634]
lrwx------ 1 root root 64 Jan  2 12:04 8 -> anon_inode:[eventpoll]
lr-x------ 1 root root 64 Jan  2 12:04 9 -> pipe:[17605635]
user3553913
  • 101
  • 3

2 Answers2

1

You need to double quote your variable expansions.

In the command

sed -i 's+<headers>.*</headers>+''<headers>'$LOG_HEADERS'</headers>+g' /usr/local/unimrcp/conf/logger.xml

the variable expansion $LOG_HEADERS is unquoted. This means that if the variable LOG_HEADERS contains spaces, it will be split into multiple words (and each word will additionally undergo filename globbing).

This means that if $LOG_HEADERS is the string A B C, you will get the command

sed -i 's+<headers>.*</headers>+''<headers>'A B C'</headers>+g' /usr/local/unimrcp/conf/logger.xml

In this command, B, C</headers>+g and /usr/local/unimrcp/conf/logger.xml will be taken as pathnames of files to process, and the sed expression s+<headers>.*</headers>+<headers>A to apply to those files contains a syntax error.

Always double quote any variable expansions. There are instances where double quoting an expansion is not needed, but it's much easier to remember to always use double quotes.

Your command would look like either

sed -i 's+<headers>.*</headers>+''<headers>'"$LOG_HEADERS"'</headers>+g' /usr/local/unimrcp/conf/logger.xml

or

sed -i "s+<headers>.*</headers>+<headers>$LOG_HEADERS</headers>+g" /usr/local/unimrcp/conf/logger.xml

(in fact, there would be only a single sed command as you can easily string together several edits in one invocation by either separating each expression with ;, or giving them in separate -e 'expression' arguments).

You also need to double quote the expansions when you're using them with echo.

Also note that parsing XML is much easier and more robust with an XML parser. To replace the contents of a <header> tag, you might, for example, use

$ cat file.xml
<root>
<header>hello</header>
</root>
$ xmlstarlet ed -u '//header' -v "new data" file.xml
<?xml version="1.0"?>
<root>
  <header>new data</header>
</root>

Questions and answers relating to quoting:

Apart from that, your script lacks the initial #-character on the very first line, and you seem to ignore whether your cd successfully changes the working directory or not (do you really want to set the working directory to /usr/local/unimrcp/bin by the way?).

Kusalananda
  • 333,661
  • I have the # in my script. but it got missed while copying here. cd is changing the directory to /usr/local/unimrcp/bin . – user3553913 Jan 02 '20 at 07:29
  • I tried above suggestion still it is giving me the same error – user3553913 Jan 02 '20 at 10:25
  • @user3553913 Sorry, what error? Your question does not mention an error at all. – Kusalananda Jan 02 '20 at 10:33
  • I am still getting those Junk characters sent to the stdout. Infact in the configuration file logger.xml I have prevented the application from printing it to the stdout. I have configured only to log to a file. But still this unimrcp process is writing these junk chars to stdout – user3553913 Jan 02 '20 at 10:59
  • @user3553913 I'm assuming that you still have some quoting issues in your script then. You may want to resort to more traditional debugging techniques, like making sure that each individual edit with sed to your configuration file looks OK. – Kusalananda Jan 02 '20 at 11:57
  • Thanks, but the configurations that I am setting through the script are inserted properly into the logger.xml. The problem is with the process's stdout is bound to wrong pipe. This is the output of the ls -l – user3553913 Jan 02 '20 at 12:20
  • total 0 lrwx------ 1 root root 64 Jan 2 12:04 0 -> /dev/null l-wx------ 1 root root 64 Jan 2 12:04 1 -> pipe:[17601930] l-wx------ 1 root root 64 Jan 2 12:04 10 -> pipe:[17605635] lrwx------ 1 root root 64 Jan 2 12:04 11 -> socket:[17605636] lrwx------ 1 root root 64 Jan 2 12:04 12 -> anon_inode:[eventpoll] lrwx------ 1 root root 64 Jan 2 12:04 13 -> anon_inode:[eventfd] lrwx------ 1 root root 64 Jan 2 12:04 14 -> anon_inode:[eventpoll] lrwx------ 1 root root 64 Jan 2 12:04 15 -> anon_inode:[eventfd] – user3553913 Jan 02 '20 at 12:21
  • @user3553913 Well, you don't redirect the output of the process in the code that you show us, so the issue lies elsewhere. Either in the program itself, or in whatever is calling the script. – Kusalananda Jan 02 '20 at 12:49
  • script is called like this ENTRYPOINT . ./unimrcp_entrypoint.sh This is the docker entrypoint. The issue is because the process is not attached to any terminal. ps -ef shows TTY as ?. This Unimrcp is the first process that will be spawned by the OS. – user3553913 Jan 02 '20 at 13:28
0

Issue was because of process not having TTY attached to it. TTY is the device used by the process to interact for the purpose of input and output. Since there was no TTY, Unimrcp process used its fd 1 (stdout) for its one of the thread communications (fd 1 was attached the process's pipe). Hence there were some junk characters sent to stdout (do not know exactly why?).

After attaching the tty to the process, process fd 1 pointed to /dev/pts/0 which is the pseudo terminal. Now I am able to see the logs in readble format.

Added these lines to pod yaml file. which solved the issue

containers: - name: unimrcp tty: true stdin: true

user3553913
  • 101
  • 3