Can I flush the logs of only one app in Pm2?
Assuming my app id is 2
I tried
pm2 flush 2
but still it flushes all apps' logs.
It was a bug in pm2.
I submitted an issue and they fixed it.
To solve it on your side, run these commands:
$ npm install pm2#latest -g
$ pm2 update
And it should work with the latest release.
pm2 logs are located in .pm2/logs/
PM2 LOGS COMMANDS :
Show logs
pm2 logs appName|appId --lines=100
Show Error logs
pm2 logs appName|appId --err --lines=100
Empty log for specific app
pm2 flush appName|appId
Empty all log files
pm2 flush
Reload all logs
pm2 reloadLogs
You can flush log of specific app by mentioning name or id.
pm2 flush my_app_name // by name
pm2 flush my_app_id // by id
Try any one of the following commands to clear the logs in pm2,
pm2 flush
pm2 flush appName|appId
Related
I've got a nodejs server that is being managed to pm2, but it is running as a different user (www-data, via su). I need to start a second server run as my own user id, but when I try to start it, I get an access error as ~/.pm2 is owned by www-data, not myself. I tried using the --log option to pm2, but that doesn't let me set the global pm2 directory, just the log file.
How can I specify a different directory for pm2 to use?
The short answer is to set a different home directory for pm2...
$ export PM2_HOME=/your/pm2/home
$ <your pm2 commands>
Of course, whatever directory you wish to put the .pm2 directory into will have to be writable by the user as which you are invoking pm2.
The long answer would be to shut down the running server run by www-data and remove the ~/.pm2 directory from your home directory.
Then, when you start the pm2 process as the www-data user do it like this
$ su -c "PM2_HOME=/path/writable/by/www-data/user <pm2 commands>" www-data
Now, the existing pm2 server should be running as www-data with its runtime files in whatever directory you set up for the www-data user.
Which means you can now use your own home directory (by default) when you run any pm2 commands as you, without having to configure any PM2_HOME variable.
Please, do you know how resolve this issue ?
I searched everywhere without finding.
06:45 SELinux is preventing systemd from open access on the file /root/.pm2/pm2.pid. For complete SELinux messages run: sealert -l d84a5a0b-cfcf-4cb9-918a-c0952bf70600 setroubleshoot
06:45 pm2-root.service: Can't convert PID files /root/.pm2/pm2.pid O_PATH file descriptor to proper file descriptor: Permission denied systemd 2
06:45 Failed to start PM2 process manager.
I have executed this command : sealert -l d84a5a0b-cfcf-4cb9-918a-c0952bf70600 setroubleshoot
Messages d'audit bruts
type=AVC msg=audit(1591498085.184:7731): avc: denied { open } for pid=1 comm="systemd" path="/root/.pm2/pm2.pid" dev="dm-0" ino=51695937 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:admin_home_t:s0 tclass=file permissive=0
PM2 Version : 4.4.0
NODE version : 12.18.0
CentOS Version : 8
my systemd service :
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target
[Service]
Type=forking
User=root
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/sbin:/bin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/root/.pm2
PIDFile=/root/.pm2/pm2.pid
Restart=on-failure
ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill
[Install]
WantedBy=multi-user.target
Thank you
As said in the comments, I had the exact same issue.
To solve this, just run the following commands as root after trying to start the PM2 service (in your case, this start attempt would be systemctl start pm2-root)
ausearch -c 'systemd' --raw | audit2allow -M my-systemd
semodule -i my-systemd.pp
This looks pretty generic, but it works. These lines were suggested by SELinux itself. To get them, I had to run the command journalctl -xe after trying to start the service
Two options:
Edit the systemd file that starts pm2 and specify an alternative location for the pm2 PIDFile). You'll have to make two changes, one to tell pm2 where to place the PIDFile, and one to tell systemd where to look for it. Replace the existing PIDFile line with the following two lines
Environment=PM2_PID_FILE_PATH=/run/pm2.pid
PIDFile=/run/pm2.pid
Create an SELinux rule that allows this particular behavior. You can do that exactly as Backslash36 suggest in their answer. If you want to create the policy file yourself rather than through audit2allow,the following should work, although then you have to compile it to a usable .pp file yourself.
module pm2 1.0;
require {
type user_home_t;
type init_t;
class file read;
}
#============= init_t ==============
allow init_t user_home_t:file read;
My ecosystem.config.js file loads my environment great with this command:
pm2 start ecosystem.config.js
When I run any of these command, my environment is reloaded just fine:
pm2 reload myapp
pm2 restart myapp
pm2 reload ecosystem.config.js
pm2 restart ecosystem.config.js
Then I try to make sure I get my environment back after a reboot. If I run pm2 startup I get this:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u me --hp /home/me
After running that command, I can reboot my machine and my application is restarted automatically. However, I am missing my environment from the ecosystem.config.js file. Why? How do I make sure the environment from my ecosystem.config.js environment is loaded when the machine is rebooted? Thanks.
Dont forget to save your config! pm2 save
In case you want pm2 on startup with changed logs path:
pm2 delete all
pm2 start ecosystem.js
pm2 save
pm2 startup
I had the same issue. After executing the command suggested by pm2 startup, I found I had to first run pm2 delete all, then restart using pm2 start ecosystem.config.js. My environment is now loading as expected after rebooting.
May be worth sharing that a file named ecosystem.js, even if empty, needs to exist on the system in the user's home path so that pm2 can load it.
I am trying to connect with ejabberd server with following command
# ejabberdctl start
but, it gives me below error.
Failed RPC connection to the node ejabberd#localhost: nodedown
Please help me to figure out this. thank you
first you have to check the service, terminal code below.
ps aux | grep ejabberd
if any unwanted servicer running kill that,terminal code below.
eg.
kill 14056
and stop the ejabberd service ,terminal code below.
ejabberdctl stop
or
/sbin/ejabberdctl stop
close the terminal and reopen terminal and start the ejabberd service,terminal code below.
ejabberdctl start
or
/sbin/ejabberdctl start
you have to change your directory to the folder which contains ejabberdctl file:
cd /Applications/ejabberd/bin
Then you have to use this code to start ejabberd:
./ejabberdctl start
you can also use this to see the status of your ejabberd server:
./ejabberdctl status
first check if service is running or no then ./ejabberdctl start. If you still have errors you should post your log because I can't see what is happening on your machine
I'm using OpenShift Origin and developing a cartridge for the first time. When my bin/install and bin/control scripts are running I've noticed "Permission denied" errors when they try to access anything in the cartridge usr dir. In the node platform.log I see the offending command that OpenShift runs looks like this (where my bin/control start tries to run a script in usr):
/sbin/runuser -s /bin/sh 5351e627ee5a934f290001d2 -c "exec /usr/bin/runcon 'unconfined_u:system_r:openshift_t:s0:c0,c1004' /bin/sh -c \"set -e; /var/lib/openshift/5351e627ee5a934f290001d2/mycart/bin/control start \""
Since the usr dir is a symlink I originally thought it was related to that, but now I think it's related to selinux (which I don't know much about). If I do a "ls -Z" on my app's cartridge dir the files are "system_u:object_r:openshift_var_lib_t:s0:c0,c1004" but the contents of the usr dir are "unconfined_u:object_r:default_t:s0", so it doesn't match what's in the above command.
I used the oo-admin-cartridge command to install the cartridge to my Origin VM.
Any ideas on how to fix this?
What I ended up doing was running "chcon -R -u system_u -t bin_t usr/" before installing the cartridge with oo-admin-cartridge. Built-in cartridges are not affected by this problem (checked nodejs), so I feel like it might be a oo-admin-cartridge bug. I would expect it to massage the selinux permissions instead of using whatever I provide.