I'm not sure if it's possible, but I want to connect to existing application to see what logs it produce in realtime. Is it possible to do so from Linux terminal?
If you know the pid of the process (it should be in the start up logs, or retrieved via a ps aux | grep <port> call) you should be able to tail it via tail -f /proc/<pid>/fd/2. Command found from here
Related
I have a problem when launching a Nodejs script that listens in one of the HTTP ports. Sometimes, even if I stop the script, the used HTTP port stays "in use", making it impossible to use it another time. Today, i've set up NGINX in my linux and all the HTTP ports were "in use". I was obliged to restart my computer to solve the problem.
I wanted to know why is this happening ? What can i do to prevent it ? and in case an HTTP port stays "in use", how can i close it to be able to use again ?
Thanks for your help.
This is applicable only on Linux and MacOS, you can list all your used ports like that:
sudo lsof -i -P -n | grep LISTEN
Read more here about how to check if a port is in use: https://www.cyberciti.biz/faq/unix-linux-check-if-port-is-in-use-command/
You can also list the node processes:
top | grep node
or
ps -ef | grep node
Then you can kill the node processes like that:
killall node
Make sure that when you want to stop the server you are pressing CTRL + C
I am trying create a bunch of pods, services and deployment using Kubernetes, but keep hitting the following errors when I run the kubectl describe command.
for "POD" with RunContainerError: "runContainer: API error (500): Cannot start container bbdb58770a848733bf7130b1b230d809fcec3062b2b16748c5e4a8b12cc0533a: [8] System error: too many open files in system\n"
I have already terminated all pods and try restarting the machine, but it doesn't solve the issue. I am not an Linux expert, so I am just wondering how shall find all the open files and close them?
You can confirm which process is hogging file descriptors by running:
lsof | awk '{print $2}' | sort | uniq -c | sort -n
That will give you a sorted list of open FD counts with the pid of the process. Then you can look up each process w/
ps -p <pid>
If the main hogs are docker/kubernetes, then I would recommend following along on the issue that caesarxuchao referenced.
I am trying create a bunch of pods, services and deployment using Kubernetes, but keep hitting the following errors when I run the kubectl describe command.
for "POD" with RunContainerError: "runContainer: API error (500): Cannot start container bbdb58770a848733bf7130b1b230d809fcec3062b2b16748c5e4a8b12cc0533a: [8] System error: too many open files in system\n"
I have already terminated all pods and try restarting the machine, but it doesn't solve the issue. I am not an Linux expert, so I am just wondering how shall find all the open files and close them?
You can confirm which process is hogging file descriptors by running:
lsof | awk '{print $2}' | sort | uniq -c | sort -n
That will give you a sorted list of open FD counts with the pid of the process. Then you can look up each process w/
ps -p <pid>
If the main hogs are docker/kubernetes, then I would recommend following along on the issue that caesarxuchao referenced.
I have 6 services nodejs running in one server. Sometimes I need to kill one of them, but when I execute:
ps aux | grep node
All the 6 services appears with the same name. I dont know which one of them to kill.
There are some way to diff. them?
You can use PM2 to manage your nodejs applications. It can also help you in restarting the node process once server is rebooted.
If you know the port of your services and linux, this could help:
sudo netstat -tulpn
I wish to start a web app in a linux server-- and then monitor its performance periodically using top command.
However top requires the pid (for getting stats of a specific app/process)-- and what I wish to know is, is it possible to obtain the pid programmatically? In such a way, that I login to that server via SSH, run shell commands to determine the PID of that process, and finally run the shell command for top passing that PID as a parameter?
Which programming language ?
try
ps -ef | awk '{if ($8 ~ /<nameOfApp>/) print $2;}' > /tmp/tmpFile_
you could then read off the PID from tmpFile_ and call
top -p <PID>