Supervisord loading old config - linux

I'm using Supervisord to queue my Laravel jobs. Today I updated the config files and did the usual supervisorctl reread and supervisorctl update. Nevertheless, i didn't get any updated config files.
whereis supervisord results in supervisord: /usr/bin/supervisord /etc/supervisord.conf
whereis supervisor results in `` (empty response)
The /etc/supervisord.conf has the following
[include]
files=/var/www/vhosts/myfirstdomain/myfolder/ms_super.conf
files=/var/www/vhosts/myseconddomain/myfolder/th_super.conf
The path is correct and the files are setup exactly the same. I changed my PHP code for the worker and had to restart the service.
My struggle is that it's not updating, and I tried reload and restart all, it keeps running the old config file. I believe it's stored somewhere as cache or something.
My package manager is yum. I really appreciate your help.

Related

PM2 Flush not clearing logs

I run a Ubuntu server which is suddenly full because of pm2 logs taking 16GB. I tried pm2 flush. But this only clears the folder which took 4GB.
As root the ".pm2" folder is cleared but not logs folder. As my own user the folder is cleared but under the wrong username.
Here is showed running pm2 flush in root and admin user.
How do i clear it?
you should try pm2 flush <app_name> it will remove the default output and error logs from .pm2/logs
the above command does not flush the merge logs for the specified app_name
Hope I'm not too late. Alright, long story short.
The problem was within the code, the arguments passed aren't implemented correctly to deal with whatever logical comparison or verification they wanted. So as a result, the logs aren't being flushed.
I created an PR, which you can access here. I think it will take some time for the maintainers to review the pull. It may not even get merged at all.
Anyways, if you want to apply and test the updated code to your system. You need to find where your PM2 package files are located.
To do this, just run the commands according to the package manager that you used to install pm2.
Note: If you installed pm2 using sudo, you must ran the commands with sudo too.
yarn => yarn global dir
npm => npm root -g
After that, cd into the directory path that the command returned.
Then cd into <..PATH..>/node_modules/pm2/lib/API. You should see a file named LogManagement.js. Use sudo cp to make a copy of that file. So if there's any problem, you can still turn back.
Following, go to this github link, and replace the entire LogManagement.js with the copied code.
Done! You should be able to run pm2 flush "My App" or something like pm2 flush 1 as usual.

Autostart a node.js script using init.d in Debian

I have a little node application on a server (node mailer) that I run by going to its source folder and executing npm start. I figured the best way to run this automatically would be to create a my_script.sh file and drop it in the init.d directory of my debian box. Inside the file (below the !#/bin/bash line), the code to execute is
'/opt/mycode/source/npm start'
I save the line to the .sh file and restarted the machine, but so far haven't got it to work. My question is: is this even how you start a script like this (using that command and an .sh file)? It does start normally when I do it manually (when I navigate to it and run npm start in the terminal). I included the single quotes around it because of the space between npm start. Also, if I want to verify that it worked, which process would I look for other than just pinging my smtp mailer? Finally, I know I need to run:
update-rc.d my_script.sh defaults
but I was also confused at to whether I had done this correctly either (is it just the name of the file that goes there or the file plus the extension)?
The script that you leave on the init.d folder should not have any extension and should have functions to start, stop and get the status of the service (your application).
I'll leave a link with an example as well as with some basis in order to build the Linux service script.
I would suggest reloading the daemon with systemctl daemon-reload in order to refresh the Linux service files once you add a new one.

How to run node.js process with forever logging on ubuntu reboot?

There was a topic how to run process with forever and logging.
How to run node.js process with forever and logging?
How to do this in crontab?
Currently I have this in crontab:
#reboot . $HOME/.bashrc
#reboot forever start /path/my_server.js
And in my home directory .bashrc there is a line
export DEBUG=*
Node server starts. But it does not make logs as if I would start manually.
How to fix that?
Update:
Cron is for the same user as if I started manually.
I guess you should use source $HOME/.bashrc
Edit:
You can use https://github.com/chovy/node-startup which it is a boilerplate for an init script, just change few things there and copy to init.d and then with the command update-rc.d node-app defaults the process will start whenver you reboot, no need for cron.
you find the manual in the repository. very easy

PM2 resurrect not working on reboot - dump.pm2 being emptied

I'm trying to configure PM2 to daemonize a simple node.js server on centos. The init.d script executes, and there are no errors, but pm2 list returns an empty list, and the server is not starting.
Originally, I was attempting to start the process as a different user (for those interested, this can be done with modifications to pm2-init.sh). But due to the complication, I decided to first try to get it to run as root.
The strange symptom of the problem is that the dump.pm2 file is being emptied by some process, thus the pm2 resurrect has nothing to do. I set up pm2 to run on reboot as follows
$ pm2 startup centos
$ pm2 start /path/to/my/server.js
$ pm2 save
At this point, dump.pm2 had a large JSON object in it and the server is running. Then, running:
$ reboot
... wait and log back in
$ pm2 list
It was empty again, and so was the dump.pm2!
I'm not sure what process is clearing this file. I've tried reinstalling and re-running the startup script to no avail. Any help is greatly appreciated.
As a temporary workaround, I set the dump file as immutable:
$ chattr +i /path/to/my/dump.pm2
This worked. Although not ideal, it is what I will use until I can determine why the dump.pm2 file is being emptied.

Keeping node.js running

During development it would be great to have node.js restarted automatically when changes occur in the applications directory. When the application is in production, node could be start just like normally. When the server is rebooted with or without intention, node needs obviously to be restarted.
I've heard about and tried both forever and supervisor. Supervisor works good, but I can't make it to start during boot. Forever on the other hand ignores any changes in my directory.
Are there alternatives that are available that would do all this for me?
Thanks
Here's what I ended up doing:
Below code was put in /etc/init/myApplication.conf:
# Enter below
respawn
console none
start on runlevel [2345]
stop on runlevel [06]
script
sudo always /var/www/backend/app.js > /var/www/backend/nodelog.log
end script
Always checks for changes in my node directory while this script ensures that always is started on boot.
I've recently started using Foreman to manage my apps. You can export from Foreman to Upstart which should solve your problem with handling reboots, etc. in a production environment (although I haven't done this myself yet.)
For automatically updating files on change, check out always. (Then run always from your local Procfile through Foreman - that's my setup.)
I don't think you are likely to find anything that automatically starts node on boot, but depending on your OS, this isn't very difficult. Could you tell us what your OS is?

Resources