PM2 Flush not clearing logs - linux

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.

Related

Supervisord loading old config

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.

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.

why can't i run meteor in root mode?

I am installing meteor by shell script in root mode. When I try to build app it is prompting
*You are attempting to run Meteor as the "root" user. If you are developing, this is almost certainly not what you want to do and will likely result in incorrect file
permissions. However, if you are running this in a build process (CI, etc.) or you are absolutely sure you know what you are doing, add the --unsafe-perm flag to
this command to proceed.*
I am running other things with shell script which needs root mode. Any help appreciated
You are attempting to run Meteor as the "root" user.
If you are developing, this is almost certainly not what you want to do and will likely result in incorrect file permissions.
However, if you are running this in a build process (CI, etc.) or you are absolutely sure you know what you are doing, add the
--unsafe-perm
flag to this command to proceed.

NodeJS installation to jenkins : npm not found

Maybe someone can tell me what I missed installing nodeJS to jenkins, because when I want to execute shell script npm update I get error npm: not found.
I installed jenkins nodejs plugin then added installer:
After I created job with prams:
What I need to do more, to have accessible npm in any jenkins job?
It works for me. The only difference is that where you have a text box that reads "0.12.7", I have a popup menu that reads "Node.js 0.12.7". Maybe something has gone wrong and you should delete the installer and add it back?
Windows users, did you restart?
Do keep in mind that you need to restart active processes after installing npm.
During installation the folder of your npm.cmd is added to the PATH variable. However, active applications don't refresh their PATH variable automatically. That also holds for your active Jenkins service (and its child processes). They are still running with an old version of your PATH variable.
In other words, you need to restart the Jenkins service (or restart your entire system). Once restarted, Jenkins will have an updated PATH variable, and it will be able to find the npm.cmd processes and others.
What's wrong with using absolute paths?
Using the full path is not a solid solution. A package.json file can contain references to other cli processes (e.g. node, ng, react-scripts, npm-run-all, ...). You will probably have similar issues there. There is no way to keep up and reference all of them with full paths.

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.

Resources