There’s a process control system I use called Supervisord.
It allows you to start a process. The same, if the process falls, tries to start it again, according to what you set up.
You can install it on Linux like this:
sudo apt install supervisor
Then you need to start the service
sudo service supervisor start
After that, you can start using the supervisor
to manage your processes.
First, you need to create a configuration file for it in the folder /etc/supervisor/conf.d
with the extent .conf
.
For example nome-do-programa-ou-comando.conf
:
[program:nome-do-programa]
autorestart=true
autostart=true
command=php /meu/script/php_socket.php
numprocs=1
process_name=socket
redirect_stderr=true
stdout_logfile=/tmp/projeto.log
user=wallace
Then you can use the command sudo supervisorclt update
. Most likely, the file you have configured will be displayed.
In doing so, your process will be initiated.
If you need to modify the file, you can do it normally, without stopping the supervisor
.
What you need to do is execute the command sudo supervisorctl reread
to recognize the changes made and then use the command sudo supervisorclt update
to start the process again with the new changes.
While understanding the basics of Supervisor, here at the company was very helpful in ensuring that the process responsible for running queues never fell. Rare cases I had trouble using the Supervisor.
We had a similar problem here and it was memory overflow. We restarted the VM and it was ok for a few days until it started again. We decided to change the memory management in the VM. I do not know if it is your case, but it is something to investigate.
– Diego
Interesting @Diego, it makes sense because I monitor the VPS using htop and shows very peak, but server oscillation, in case confirm me something please, Socket keeps open or need to close it and always open when necessary?
– Luiz Augusto Neto
What is the purpose of using the socket? Doing some parallel process or something? I ask this, because in most cases (according to my knowledge), the socket must be opened to perform the processing and, when returning the data, closed. But there are exceptions.
– Gabriel Heming
@Gabrielheming is using socket for both chat communication and real-time notifications of my application. Now for the use of chat I’ve thought about migrating to google’s Firebase, is a good idea or is this relative?
– Luiz Augusto Neto
I had similar problems with the soket.io service, so I started using Forever and definitely solved: https://www.npmjs.com/package/forever
– lstonon
Luiz, you would have to give more details, if you have something in the error log, configuration details and everything else, even to see if it is a programming or support problem.
– Bacco