Is there a way to figure out why a PM2 process restarted if the error log is empty? - node.js

$ pm2 --version
1.1.1
Started a shell script with pm2. It was gonna run for about 12 hours. Went back to check on it the next day and it was only halfway done. But I checked the logs and it looked like it had started over. Checked pm2 ls and yes, it had, 3 times. That seemed strange since all it was doing was sending some curls and had been doing fine for hours.
So I went to look at the error output:
[collumj#serverName ~]$ ll /opt/xyz/.pm2/logs | grep util-perf-testing
-rw-r--r-- 1 collumj alskdjflkas 0 Oct 12 21:27 util-perf-testing-error-54.log
-rw-r--r-- 1 collumj alskdjflkas 0 Oct 12 21:38 util-perf-testing-error-59.log
-rw-r--r-- 1 collumj alskdjflkas 6.8K Oct 12 21:36 util-perf-testing-out-54.log
-rw-r--r-- 1 collumj alskdjflkas 15K Oct 13 00:00 util-perf-testing-out-59__2016-10-13_00-00-00.log
-rw-r--r-- 1 collumj alskdjflkas 166K Oct 14 00:00 util-perf-testing-out-59__2016-10-14_00-00-00.log
-rw-r--r-- 1 collumj alskdjflkas 384K Oct 14 17:16 util-perf-testing-out-59.log
The two error logs are completely empty.
Does PM2 keep any sort of internal logs about restarts? The output of the shell script doesn't show any reason for it to restart and the error logs are empty. I'm looking at a complete mystery as to why this shell script would have restarted 3 times.

PM2 will store the reasons for resets in its log, which can be accessed like so: tail --lines 100 ~/.pm2/pm2.log.

Related

r10k puppetfile install hang / stuck

So i'm trying to install a lot of module (66 in total) from a single Puppetfile and after every 7-9 modules installed the process hang up or it seem that it's stops working.
I found a temporal solution tot this problem, but it's a bit of a pain.
I have to kill the r10k process and remove the module that it was trying to install from the ~/.r10k/git folder
user#ubuntu:~$ ps -aux | grep r10k
user 20294 0.1 0.1 234032 30728 pts/1 Sl+ 13:03 0:00 /usr/bin/ruby2.5 /home/user/.ruby/bin/r10k puppetfile install -v
user 27143 0.0 0.0 26028 4004 ? Ss 13:15 0:00 git clone ssh://git#bitbucket.com:/bla/crashed-repository.git /home/user/Documents/Projects/repository --reference /home/ser/.r10k/git/ssh---git#bitbucket.com-7999-crashed-repository.git
user#ubuntu:~$ kill 20294
user#ubuntu:~$ kill 27143
user#ubuntu:~$ cd ~/.r10k/git/
user#ubuntu:~/.../git$ ls -la
total 8
drwxr-xr-x 37 user user 4096 ago 23 13:18 .
drwxr-xr-x 3 user user 4096 ago 23 12:46 ..
drwxr-xr-x 7 user user 4096 ago 23 12:46 ssh---git#bitbucket.com-7999-respository_one.git
drwxr-xr-x 7 user user 4096 ago 23 12:46 ssh---git#bitbucket.com-7999-respository_two.git
drwxr-xr-x 7 user user 4096 ago 23 12:46 ssh---git#bitbucket.com-7999-respository_three.git
drwxr-xr-x 7 user user 4096 ago 23 12:46 ssh---git#bitbucket.com-7999-respository_four.git
.
.
.
drwxr-xr-x 7 user user 4096 ago 23 12:46 ssh---git#bitbucket.com-7999-crashed-repository.git
user#ubuntu:~/.../git$ rm -r ssh---git#bitbucket.com-7999-crashed-repository.git
And after that run it again until it hang up again, and so on until all the modules are installed.
I've found a thread on the puppetlabs/r10k github that explains why this happens, but no solution to the problem.
If anyone know how to do a "try/catch" while installing multiple puppet modules so that this issue doesn't show up anymore i'll be very grateful.

Log4j Rolling File appender uses wrong logfile

my first question - Please Keep calm ;-)
our Problem is, that log4j uses the wrong logfile. Our configuration is a simple DailyRollingFileAppender
log4j.appender.dx4wsa=org.apache.log4j.DailyRollingFileAppender
log4j.appender.dx4wsa.File=${env.WFL_DIR}/log/dx4wsa-agents.log
log4j.appender.dx4wsa.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.dx4wsa.layout=org.apache.log4j.PatternLayout
log4j.appender.dx4wsa.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss}: %5p %-30c{1} %-50x %m%n
What we see is, that sometimes the logger uses old logfiles after rolling over. For example here
dx4wsa-agents.log.2016-10-12-18:12.10.2016 20:39:03: INFO VorgangLoeschen 21974690 Start executing agent on process instance = 21974690 and work item = 14f27076-f31f-48a7-849d-669189918730
You can see here, that this step is from 20:39:03 and the Logfile already rotated - it's the 18:00 Logfile. An "ls -ltr" Shows you the last Access.
-rw-r--r-- 1 tpdx4wf2 gpdoxis4 61944 Oct 12 17:59 dx4wsa-agents.log.2016-10-12-17
-rw-r--r-- 1 tpdx4wf2 gpdoxis4 51668039 Oct 12 17:59 dx4wsa-agents.log.2016-10-12-16
-rw-r--r-- 1 tpdx4wf2 gpdoxis4 40437528 Oct 12 19:59 dx4wsa-agents.log.2016-10-12-19
-rw-r--r-- 1 tpdx4wf2 gpdoxis4 1463292 Oct 12 20:54 dx4wsa-agents.log
-rw-r--r-- 1 tpdx4wf2 gpdoxis4 67702368 Oct 12 20:54 dx4wsa-agents.log.2016-10-12-18
Today we had a release and, stopped the Server, killed all Java-Threads deployed new Jar-Files and restarted the Server at 19:00!!! And log4j logged in the 18:00 file?

Openshift hourly cron job suddenly stopped working

Suddenly the hourly cron job on openshift stopped working.
I am using a free account and the cron was running fine until suddenly it just stopped working.
Minutely jobs on the other hand are running fine, given the following files
app-root/runtime/repo/.openshift/cron/minutely/cminut
#!/bin/bash
echo 'ping'
and
app-root/runtime/repo/.openshift/cron/hourly/chour
#!/bin/bash
echo 'pong'
as well as the following permissions
[xxx-xxxxxxx.rhcloud.com cron]\> ls -la hourly/
total 4
drwx------. 2 1234567 1234567 18 Jun 28 19:04 .
drwx------. 4 1234567 1234567 52 Jun 28 19:04 ..
-rwx--x--x. 1 1234567 1234567 24 Jun 28 19:04 chour
[xxx-xxxxxxx.rhcloud.com cron]\> ls -la minutely/
total 4
drwx------. 2 1234567 1234567 19 Jun 28 19:04 .
drwx------. 4 1234567 1234567 52 Jun 28 19:04 ..
-rwx------. 1 1234567 1234567 24 Jun 28 19:04 cminut
[xxx-xxxxxxx.rhcloud.com cron]\>
The minutely cron job runs fine and i can see the log file cron_minutely.log in $OPENSHIFT_LOG_DIR
For the hourly cron job i can not see the cron_hourly.log neither the job is executed
My previous attempts wen't trough uninstalling and re installing the cron cartridge as mentioned here but there was no success running the hourly cron job.
Is there any other way that i can debug this, or any openshift specific fix known in order to solve this?
After some desperate attempts and inspecting the cron job cartridge script cron_runjobs.sh
i came to note that whenever i runed the hourly cron via this script the log
":SKIPPED: $freq cron run for openshift user '$OPENSHIFT_GEAR_UUID"
popped up, such message was not fired for other crons (minutely, weekly...)
upon closer inspection i noticed that there were several processes with this script cron_runjobs.sh running on the server, after killing this processes and re-deploying the application the hourly cron job started again to work as expected.
I do not know why were these processes hanged and still running, maybe because i used sleep in the hourly cron before, although not sure if that was the reason.

Linux: Finding Newly Added Files

I am trying to obtain a backup of 'newly' added files to a Fedora system. Files can be copied through a Windows Samba share and appear to retain the original created timestamp. However, because it retains this timestamp I am having issues identifying which files were newly added to the system.
Currently, the only way I can think of doing this is to have a master list snapshot of all the files on the system at a specific time. Then when I perform the backup I compare the previous snapshot with a current snapshot. It would detect files that were removed from the system but it seems excessive and I was thinking there must be an easier way to backup newly added files.
Terry
Try using find. Something like this:
find . -ctime -10
That will give you a list of files and directories, starting from within your current directory, that has had its state changed within the last 10 days.
Example:
My Downloads directory looks like this:
kobus#akira:~/Downloads$ ll
total 2025284
drwxr-xr-x 4 kobus kobus 4096 Nov 4 11:25 ./
drwxr-xr-x 41 kobus kobus 4096 Oct 30 09:26 ../
-rw-rw-r-- 1 kobus kobus 8042383 Oct 28 14:08 apache-maven-3.3.3- bin.tar.gz
drwxrwxr-x 2 kobus kobus 4096 Oct 14 09:55 ELKImages/
-rw-rw-r-- 1 kobus kobus 1469054976 Nov 4 11:25 Fedora-Live-Workstation-x86_64-23-10.iso
-rw------- 1 kobus kobus 351004 Sep 21 14:07 GrokConstructor-master.zip
drwxrwxr-x 11 kobus kobus 4096 Jul 11 2014 jboss-eap-6.3/
-rw-rw-r-- 1 kobus kobus 183399393 Oct 19 16:26 jboss-eap-6.3.0-installer.jar
-rw-rw-r-- 1 kobus kobus 158177216 Oct 19 16:26 jboss-eap-6.3.0.zip
-rw-rw-r-- 1 kobus kobus 71680110 Oct 13 13:51 jre-8u60-linux-x64.tar.gz
-rw-r--r-- 1 kobus kobus 4680 Oct 12 12:34 nginx-release-centos-7-0.el7.ngx.noarch.rpm
-rw-r--r-- 1 kobus kobus 3479765 Oct 12 14:22 ngx_openresty-1.9.3.1.tar.gz
-rw------- 1 kobus kobus 16874455 Sep 15 16:49 Oracle_VM_VirtualBox_Extension_Pack-5.0.4-102546.vbox-extpack
-rw-r--r-- 1 kobus kobus 7505310 Oct 6 10:29 sublime_text_3_build_3083_x64.tar.bz2
-rw------- 1 kobus kobus 41467245 Sep 7 10:37 tagspaces-1.12.0-linux64.tar.gz
-rw-rw-r-- 1 kobus kobus 42658300 Nov 4 10:14 tagspaces-2.0.1-linux64.tar.gz
-rw------- 1 kobus kobus 70046668 Sep 15 16:49 VirtualBox-5.0-5.0.4_102546_el7-1.x86_64.rpm
Here's what the find returns:
kobus#akira:~/Downloads$ find . -ctime -10
.
./tagspaces-2.0.1-linux64.tar.gz
./apache-maven-3.3.3-bin.tar.gz
./Fedora-Live-Workstation-x86_64-23-10.iso
kobus#akira:~/Downloads$
Most unices do not have a concept of file creation time. You can't make ls print it because the information is not recorded. If you need creation time, use a version control system: define creation time as the check-in time.
If your unix variant has a creation time, look at its documentation. For example, on Mac OS X (the only example I know of¹), use ls -tU. Windows also stores a creation time, but it's not always exposed to ports of unix utilities, for example Cygwin ls doesn't have an option to show it. The stat utility can show the creation time, called “birth time” in GNU utilities, so under Cygwin you can show files sorted by birth time with stat -c '%W %n' * | sort -k1n.
Note that the ctime (ls -lc) is not the file creation time, it's the inode change time. The inode change time is updated whenever anything about the file changes (contents or metadata) except that the ctime isn't updated when the file is merely read (even if the atime is updated). In particular, the ctime is always more recent than the mtime (file content modification time) unless the mtime has been explicitly set to a date in the future.
"Newly added files, Fedora" : The below examples will show a list with date and time.
Example, all installed packages : $ rpm -qa --last
Example, the latest 100 packages : $ rpm -qa --last | head -100
Example, create a text file : $ rpm -qa --last | head -100 >> last-100-packages.txt

Automatically launching Firefox from terminal using at command

I am a beginner at linux and really enthusiastic to learn the OS. I am trying to launch Firefox(or any other software like Evince) from the command line as follows:
[root#localhost ~]# at 1637
[root#localhost ~]# at> firefox
[root#localhost ~]# at> ^d
The job gets scheduled without any error. But at the specified time it does not run.
I also tried giving the following path:
[root#localhost ~]# at 1637
[root#localhost ~]# at> /usr/bin/firefox
[root#localhost ~]# at> ^d
Still no result. But When I try to use echo to display a text on the screen it appears at the specified time as desired. What might be the issue?
I think you have not set DISPLAY. at will run in separate shell where display is not set.
try the following code.
dinesh:~$ at 2120
warning: commands will be executed using /bin/sh
at> export DISPLAY=:0
at> /usr/bin/firefox > firefox.log 2>&1
at> <EOT>
job 7 at Tue Mar 11 21:20:00 2014
If it is still failing check firefox.log for more information.
1) Its not always recommended to run things as root
2) You can also try ./firefox if you are in the current directory of firefox. In linux you need to pay attention to your path variable. Unless . (the current directory) is in your path you will have to type ./program if the program is in the same directory as you.
Also you need to pay attention to file permissions: In linux you have read-write-eXecute access.
ls -l will do a list of directories and show the file permissions:
drwxr-xr-x 10 user staff 340 Oct 6 2012 GlassFish_Server/
drwx------# 15 jeffstein staff 510 Oct 6 15:01 Google Drive/
drwxr-xr-x 20 jeffstein staff 680 May 14 2013 Kindle/
drwx------+ 67 jeffstein staff 2278 Jan 26 14:22 Library/
drwx------+ 19 jeffstein staff 646 Oct 23 18:28 Movies/
drwx------+ 15 jeffstein staff 510 Jan 3 20:29 Music/
drwx------+ 90 jeffstein staff 3060 Mar 9 20:23 Pictures/
drwxr-xr-x+ 6 jeffstein staff 204 Nov 3 21:16 Public/
drwxr-xr-x 22 jeffstein staff 748 Jan 14 2012 androidTools/
-rwxrwxrwx 1 jeffstein staff 1419 Aug 28 2013 color.sh*
This is an example of ls -l here you can see color.sh has -rwxrwxrwx that means that anybody can read or write or run the file.
Without actually knowing where you installed firefox however I can't be of more help but these are some small pointers which might help.
try finding where firefox is actually installed using "whereis firefox" command.
Then try using that path in at command.
In order to get directions on how to use a command type:
man at
this will display the "manual"
DESCRIPTION
The at and batch utilities read commands from standard input or a speci-
fied file. The commands are executed at a later time, using sh(1).
at executes commands at a specified time;
atq lists the user's pending jobs, unless the user is the superuser;
in that case, everybody's jobs are listed;
atrm deletes jobs;
batch executes commands when system load levels permit; in other words,
when the load average drops below _LOADAVG_MX (1.5), or the value
specified in the invocation of at run.
So obviously you need to schedule a job with at and you can see if it worked with atq
Read the manual and it should help - if i have more time I'll write you a quick example.

Resources