Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting script passing arguments on CentOS 7 returns an error #906

Closed
abernardobr opened this issue Dec 26, 2014 · 11 comments
Closed

Starting script passing arguments on CentOS 7 returns an error #906

abernardobr opened this issue Dec 26, 2014 · 11 comments
Labels

Comments

@abernardobr
Copy link

OS: CentOS Linux release 7.0.1406 (Core)
node version: v0.11.14
pm2 version: 0.12.2
start script: start.js
pm2 command: pm2 start start.js --name server –i max --error logs/server.err.log --output logs/server.out.log -- -s prod

Returns the following error:

usr/local/lib/node_modules/pm2/bin/pm2:82
  global.console = {};
                 ^
TypeError: Cannot set property console of #<Object> which has only a getter
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2/bin/pm2:82:18)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:124:16)
    at node.js:842:3

@Tjatse
Copy link
Collaborator

Tjatse commented Dec 26, 2014

@abernardobr What kind of system are you running on?

@abernardobr abernardobr changed the title Starting script passing arguments on CentoOS 7 returns an error Starting script passing arguments on CentOS 7 returns an error Dec 26, 2014
@abernardobr
Copy link
Author

I am using CentOS Linux release 7.0.1406 (Core)

@Tjatse
Copy link
Collaborator

Tjatse commented Dec 26, 2014

Sorry, I am not having read the content carefully, never mind.
I'll setup a new CentOS environment and gonna get a complete test, it seems too much problems with CentOS 7 these days.

@Tjatse Tjatse added the T: Bug label Dec 26, 2014
@abernardobr
Copy link
Author

@Tjatse there is also another error that I am running into on doing an "npm test"


#####################
# Watch for changes #
#####################

>server-watch.js

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

cp server-watch.bak.js server-watch.js

$pm2 start server-watch.js --watch
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process server-watch.js launched
┌──────────────┬────┬──────┬───────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode │ PID   │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼──────┼───────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0  │ fork │ 14445 │ online │         0 │ 0s     │ 13.535 MB   │  enabled │
└──────────────┴────┴──────┴───────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'process should be watched' 'watch: true' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should be watched

echo "console.log('test');" >> server-watch.js

sleep 1

cat server-watch.js
var http = require('http');

http.createServer(function(req, res) {
  res.writeHead(200);
  res.end('hey');
}).listen(8000);
console.log('test');
$pm2 list
┌──────────────┬────┬──────┬───────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode │ PID   │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼──────┼───────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0  │ fork │ 14445 │ online │         0 │ 2s     │ 13.535 MB   │  enabled │
└──────────────┴────┴──────┴───────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'process should have been restarted' 'restart_time: 1' 1
$pm2 prettylist | grep -o "$2" | wc -l
########   ✘ process should have been restarted
npm ERR! Test failed.  See above for more details.

@Tjatse
Copy link
Collaborator

Tjatse commented Dec 26, 2014

okay.

@abernardobr
Copy link
Author

@Tjatse any news? We are about to go to production with CentOS 7 and anything that will give more stability would be great. Tks.

@Tjatse
Copy link
Collaborator

Tjatse commented Dec 30, 2014

@abernardobr sorry, it took me too much time to get the ISO.
global.console problem has been fixed, you can wait for the next release or update your local codes manually, bin/pm2 L81:

if (process.argv.indexOf('-s') > -1) {
  for(var key in console){
    var code = key.charCodeAt(0);
    if(code >= 97 && code <= 122){
      console[key] = function(){};
    }
  }
}

The test failed because PM2 test suite ignoring the node_modules directory, that means if you installed PM2 via npm, your module will be stored in a directory like /usr/local/lib/node_modules/pm2, just try to cp it to another directory that does not contain node_modules path and make test again.

@abernardobr
Copy link
Author

OK great @Tjatse tks

The one that worries me the most is the first problem! For now I am using a grunt script to change my files instead of detecting via the script arguments.

But since we are using CentOS 7 it would be great to run all the tests to see that it is working fine. So I am going to run the tests and let you know.

@Tjatse Tjatse closed this as completed in 6ac15c3 Dec 31, 2014
Tjatse added a commit that referenced this issue Dec 31, 2014
@abernardobr
Copy link
Author

Got the fix. Tks @Tjatse.

@abernardobr
Copy link
Author

@Tjatse I have downloaded the latest version of pm2 and tried to run npm test again. Now in a directory that does not have in the path node_modules.

Intalled in /test/pm2

cd /test/pm2
npm install 
npm test
[root@ip-172-16-101-213 pm2]# npm test

> pm2@0.12.3 test /teste/pm2
> NODE_ENV=test bash test/index.sh && NODE_ENV=test bash test/main.sh


function fail {
  echo -e "######## \033[31m  ✘ $1\033[0m"
  $pm2 kill
  exit 1
}

function success {
  echo -e "\033[32m------------> ✔ $1\033[0m"
  $pm2 kill
}

function spec {
  [ $? -eq 0 ] || fail "$1"
  success "$1"
}

$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

# if [ $TRAVIS ]
# then
#   export DEBUG="pm2:*"
# fi

mocha ./test/programmatic/god.mocha.js
child_process: customFds option is deprecated, use stdio instead.
2015-01-05 14:50:16: [PM2][WORKER] Started with refreshing interval: 30000

2015-01-05 14:50:16: 
2015-01-05 14:50:16:   God
2015-01-05 14:50:16: No processes launched
2015-01-05 14:50:17:     ✓ should have right properties 
2015-01-05 14:50:17:     ✓ should report pm2 version 
2015-01-05 14:50:17:     Special functions for God
2015-01-05 14:50:17: No processes launched
2015-01-05 14:50:18: Starting execution sequence in -cluster mode- for app name:echo id:0
2015-01-05 14:50:19: App name:echo id:0 online
2015-01-05 14:50:19: Starting execution sequence in -cluster mode- for app name:echo id:1
2015-01-05 14:50:19: App name:echo id:1 online
2015-01-05 14:50:19: Proc is not defined anymore or is being killed
2015-01-05 14:50:19: App name:echo id:0 exited
2015-01-05 14:50:19: Process with pid 1585 killed
2015-01-05 14:50:19: App name:echo id:1 exited
2015-01-05 14:50:19: Process with pid 1592 killed
2015-01-05 14:50:20:       ✓ should kill a process by name (1370ms)
2015-01-05 14:50:20:     One process
2015-01-05 14:50:20: No processes launched
2015-01-05 14:50:21: Starting execution sequence in -cluster mode- for app name:echo id:2
2015-01-05 14:50:21: App name:echo id:2 online
2015-01-05 14:50:21: Starting execution sequence in -cluster mode- for app name:echo id:3
2015-01-05 14:50:21: App name:echo id:3 online
2015-01-05 14:50:21:       ✓ should fork one process 
2015-01-05 14:50:21:     Process State Machine
2015-01-05 14:50:21: App name:echo id:2 exited
2015-01-05 14:50:21: Process with pid 1617 killed
2015-01-05 14:50:21: App name:echo id:3 exited
2015-01-05 14:50:21: Process with pid 1620 killed
2015-01-05 14:50:22: Starting execution sequence in -cluster mode- for app name:echo id:4
2015-01-05 14:50:22: App name:echo id:4 online
2015-01-05 14:50:22: Starting execution sequence in -cluster mode- for app name:echo id:5
2015-01-05 14:50:22: App name:echo id:5 online
2015-01-05 14:50:22:       ✓ should start a process 
2015-01-05 14:50:22: App name:echo id:4 exited
2015-01-05 14:50:22: Process with pid 1633 killed
2015-01-05 14:50:22:       ✓ should stop a process and keep in database on state stopped 
2015-01-05 14:50:22: Starting execution sequence in -cluster mode- for app name:echo id:4
2015-01-05 14:50:22: App name:echo id:4 online
2015-01-05 14:50:22:       ✓ should restart the same process and set it as state online and be up 
2015-01-05 14:50:22: Proc is not defined anymore or is being killed
2015-01-05 14:50:23: App name:echo id:4 exited
2015-01-05 14:50:23: Process with pid 1648 killed
2015-01-05 14:50:23: App name:echo id:5 exited
2015-01-05 14:50:23: Process with pid 1636 killed
2015-01-05 14:50:23:       ✓ should stop this process by name and keep in db on state stopped (232ms)
2015-01-05 14:50:23: Starting execution sequence in -cluster mode- for app name:echo id:4
2015-01-05 14:50:23: App name:echo id:4 online
2015-01-05 14:50:23: Starting execution sequence in -cluster mode- for app name:echo id:5
2015-01-05 14:50:23: App name:echo id:5 online
2015-01-05 14:50:23:       ✓ should restart the same process by NAME and set it as state online and be up (196ms)
2015-01-05 14:50:23: App name:echo id:4 exited
2015-01-05 14:50:23: Process with pid 1666 killed
2015-01-05 14:50:23:       ✓ should stop and delete a process id 
2015-01-05 14:50:23: Starting execution sequence in -cluster mode- for app name:echo id:6
2015-01-05 14:50:23: App name:echo id:6 online
2015-01-05 14:50:23: Starting execution sequence in -cluster mode- for app name:echo id:7
2015-01-05 14:50:23: App name:echo id:7 online
2015-01-05 14:50:23: App name:echo id:5 exited
2015-01-05 14:50:23: Process with pid 1669 killed
2015-01-05 14:50:23: App name:echo id:6 exited
2015-01-05 14:50:23: Process with pid 1684 killed
2015-01-05 14:50:23: App name:echo id:7 exited
2015-01-05 14:50:23: Process with pid 1687 killed
2015-01-05 14:50:24:       ✓ should start stop and delete the process name from database (550ms)
2015-01-05 14:50:24:     Reload - cluster
2015-01-05 14:50:24: No processes launched
2015-01-05 14:50:25: Starting execution sequence in -cluster mode- for app name:child id:8
2015-01-05 14:50:25: App name:child id:8 online
2015-01-05 14:50:25: Starting execution sequence in -cluster mode- for app name:child id:9
2015-01-05 14:50:25: App name:child id:9 online
2015-01-05 14:50:25: Starting execution sequence in -cluster mode- for app name:child id:10
2015-01-05 14:50:25: App name:child id:10 online
2015-01-05 14:50:25: Starting execution sequence in -cluster mode- for app name:child id:11
2015-01-05 14:50:25: App name:child id:11 online
2015-01-05 14:50:25:       ✓ should launch app (391ms)
2015-01-05 14:50:25: -reload- Creating a new process waiting for connections
2015-01-05 14:50:25: Starting execution sequence in -cluster mode- for app name:child id:8
2015-01-05 14:50:25: App name:child id:8 online
2015-01-05 14:50:25: -reload- New worker listening
2015-01-05 14:50:25: -reload- Old worker disconnected
2015-01-05 14:50:25: Process with pid 1701 killed
2015-01-05 14:50:25: -reload- Creating a new process waiting for connections
2015-01-05 14:50:25: Starting execution sequence in -cluster mode- for app name:child id:9
2015-01-05 14:50:25: App name:child id:9 online
2015-01-05 14:50:25: -reload- New worker listening
2015-01-05 14:50:25: -reload- Old worker disconnected
2015-01-05 14:50:26: Process with pid 1704 killed
2015-01-05 14:50:26: -reload- Creating a new process waiting for connections
2015-01-05 14:50:26: Starting execution sequence in -cluster mode- for app name:child id:10
2015-01-05 14:50:26: App name:child id:10 online
2015-01-05 14:50:26: -reload- New worker listening
2015-01-05 14:50:26: -reload- Old worker disconnected
2015-01-05 14:50:26: Process with pid 1707 killed
2015-01-05 14:50:26: -reload- Creating a new process waiting for connections
2015-01-05 14:50:26: Starting execution sequence in -cluster mode- for app name:child id:11
2015-01-05 14:50:26: App name:child id:11 online
2015-01-05 14:50:26: -reload- New worker listening
2015-01-05 14:50:26: -reload- Old worker disconnected
2015-01-05 14:50:26: Process with pid 1718 killed
2015-01-05 14:50:26:       ✓ should restart the same process and set it as state online and be up (1005ms)
2015-01-05 14:50:26:     Multi launching
2015-01-05 14:50:26: App name:child id:8 exited
2015-01-05 14:50:26: Process with pid 1729 killed
2015-01-05 14:50:26: App name:child id:9 exited
2015-01-05 14:50:26: Process with pid 1748 killed
2015-01-05 14:50:26: App name:child id:10 exited
2015-01-05 14:50:26: Process with pid 1757 killed
2015-01-05 14:50:26: App name:child id:11 exited
2015-01-05 14:50:26: Process with pid 1766 killed
2015-01-05 14:50:27: Starting execution sequence in -cluster mode- for app name:child id:12
2015-01-05 14:50:27: App name:child id:12 online
2015-01-05 14:50:27: Starting execution sequence in -cluster mode- for app name:child id:13
2015-01-05 14:50:28: App name:child id:13 online
2015-01-05 14:50:28: Starting execution sequence in -cluster mode- for app name:child id:14
2015-01-05 14:50:28: App name:child id:14 online
2015-01-05 14:50:28:       ✓ should launch multiple processes depending on CPUs available (329ms)
2015-01-05 14:50:28: App name:child id:12 exited
2015-01-05 14:50:28: Process with pid 1782 killed
2015-01-05 14:50:28: App name:child id:13 exited
2015-01-05 14:50:28: Process with pid 1790 killed
2015-01-05 14:50:28: App name:child id:14 exited
2015-01-05 14:50:28: Process with pid 1797 killed
2015-01-05 14:50:29: Starting execution sequence in -cluster mode- for app name:child id:15
2015-01-05 14:50:29: App name:child id:15 online
2015-01-05 14:50:29: Starting execution sequence in -cluster mode- for app name:child id:16
2015-01-05 14:50:29: App name:child id:16 online
2015-01-05 14:50:29: Starting execution sequence in -cluster mode- for app name:child id:17
2015-01-05 14:50:29: App name:child id:17 online
2015-01-05 14:50:29: Starting execution sequence in -cluster mode- for app name:child id:18
2015-01-05 14:50:29: App name:child id:18 online
2015-01-05 14:50:29: Starting execution sequence in -cluster mode- for app name:child id:19
2015-01-05 14:50:29: App name:child id:19 online
2015-01-05 14:50:29: Starting execution sequence in -cluster mode- for app name:child id:20
2015-01-05 14:50:30: App name:child id:20 online
2015-01-05 14:50:30: Starting execution sequence in -cluster mode- for app name:child id:21
2015-01-05 14:50:30: App name:child id:21 online
2015-01-05 14:50:30: Starting execution sequence in -cluster mode- for app name:child id:22
2015-01-05 14:50:30: App name:child id:22 online
2015-01-05 14:50:30: Starting execution sequence in -cluster mode- for app name:child id:23
2015-01-05 14:50:30: App name:child id:23 online
2015-01-05 14:50:30: Starting execution sequence in -cluster mode- for app name:child id:24
2015-01-05 14:50:30: App name:child id:24 online
2015-01-05 14:50:30:       ✓ should start maximum processes depending on CPU numbers (840ms)
2015-01-05 14:50:30: App name:child id:15 exited
2015-01-05 14:50:30: Process with pid 1818 killed
2015-01-05 14:50:30: App name:child id:16 exited
2015-01-05 14:50:30: Process with pid 1821 killed
2015-01-05 14:50:30: App name:child id:17 exited
2015-01-05 14:50:30: Process with pid 1828 killed
2015-01-05 14:50:30: App name:child id:18 exited
2015-01-05 14:50:30: Process with pid 1835 killed
2015-01-05 14:50:31: App name:child id:19 exited
2015-01-05 14:50:31: Process with pid 1838 killed
2015-01-05 14:50:31: App name:child id:20 exited
2015-01-05 14:50:31: Process with pid 1849 killed
2015-01-05 14:50:31: App name:child id:21 exited
2015-01-05 14:50:31: Process with pid 1856 killed
2015-01-05 14:50:31: App name:child id:22 exited
2015-01-05 14:50:31: Process with pid 1863 killed
2015-01-05 14:50:31: App name:child id:23 exited
2015-01-05 14:50:31: Process with pid 1870 killed
2015-01-05 14:50:31: App name:child id:24 exited
2015-01-05 14:50:31: Process with pid 1873 killed
2015-01-05 14:50:32: Starting execution sequence in -cluster mode- for app name:child id:25
2015-01-05 14:50:32: App name:child id:25 online
2015-01-05 14:50:32: Starting execution sequence in -cluster mode- for app name:child id:26
2015-01-05 14:50:32: App name:child id:26 online
2015-01-05 14:50:32: Starting execution sequence in -cluster mode- for app name:child id:27
2015-01-05 14:50:32: App name:child id:27 online
2015-01-05 14:50:32:       ✓ should dump process list (261ms)
2015-01-05 14:50:33: App name:child id:25 exited
2015-01-05 14:50:33: Process with pid 1918 killed
2015-01-05 14:50:33: App name:child id:26 exited
2015-01-05 14:50:33: Process with pid 1921 killed
2015-01-05 14:50:33: App name:child id:27 exited
2015-01-05 14:50:33: Process with pid 1924 killed
2015-01-05 14:50:34: Starting execution sequence in -cluster mode- for app name:child id:28
2015-01-05 14:50:34: App name:child id:28 online
2015-01-05 14:50:34:       ✓ should handle arguments (544ms)
2015-01-05 14:50:34: App name:child id:28 exited
2015-01-05 14:50:34: Process with pid 1954 killed
2015-01-05 14:50:35:     Lock/Unlock system
2015-01-05 14:50:35: Starting execution sequence in -cluster mode- for app name:echo id:29
2015-01-05 14:50:36: App name:echo id:29 online
2015-01-05 14:50:36: Starting execution sequence in -cluster mode- for app name:echo id:30
2015-01-05 14:50:36: App name:echo id:30 online
2015-01-05 14:50:36:       ✓ should launch processes 
2015-01-05 14:50:36: Locking 29
2015-01-05 14:50:36: Locking 30
2015-01-05 14:50:36:       ✓ should lock a process 
2015-01-05 14:50:36:       ✓ should trying to relock fail 
2015-01-05 14:50:36: Unlocking 29
2015-01-05 14:50:36: Unlocking 30
2015-01-05 14:50:36:       ✓ should unlock processes 


2015-01-05 14:50:36:   21 passing (19s)

spec "God test"
------------> ✔ God test
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
mocha ./test/programmatic/satan.mocha.js
child_process: customFds option is deprecated, use stdio instead.


  Satan
[PM2] Spawning PM2 daemon
[PM2] Success
    ✓ should start Satan interaction (294ms)
Client ready
    ✓ should auto instancy itself, fire event and kill daemon 
    ✓ should have right properties 
    DAEMON
      - should have the right exposed methods via RPC
      ✓ should get an empty process list 
      ✓ should get an empty process list from system data 
      ✓ should launch a process (319ms)
      ✓ should list 4 processes 
      ✓ should list 4 processes via system data 
[PM2] Deleting all process
[PM2] deleteProcessId process id 0
[PM2] deleteProcessId process id 1
[PM2] deleteProcessId process id 2
[PM2] deleteProcessId process id 3


  8 passing (1s)
  1 pending

spec "Satan test"
------------> ✔ Satan test
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
mocha ./test/programmatic/programmatic.js
child_process: customFds option is deprecated, use stdio instead.


  PM2 programmatic calls
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Deleting all process
[PM2] [WARN] No process found
[PM2] Process /teste/pm2/test/fixtures/child.js launched
    ✓ should start a script 
[PM2] Process /teste/pm2/test/fixtures/child.js launched
    ✓ should start a script and force to launch it 
[PM2] Process /teste/pm2/test/fixtures/cron.js launched
    ✓ should start a script in a specified cwd 
[PM2] Process /teste/pm2/test/fixtures/child.js launched
    ✓ should notice error if wrong file passed (244ms)
[PM2] Process /teste/pm2/test/fixtures/child.js launched
    ✓ should start a script and force to launch it (279ms)
    ✓ should get pm2 version 
9
    ✓ should list processes 
[PM2] Deleting 2 process
[PM2] deleteProcessId process id 2
    ✓ should delete one process (171ms)
    ✓ should save/dump all processes 
[PM2] Deleting all process
[PM2] deleteProcessId process id 0
[PM2] deleteProcessId process id 1
[PM2] deleteProcessId process id 3
[PM2] deleteProcessId process id 4
[PM2] deleteProcessId process id 5
[PM2] deleteProcessId process id 6
[PM2] deleteProcessId process id 7
[PM2] deleteProcessId process id 8
    ✓ should delete processes (1014ms)
Process /teste/pm2/test/fixtures/child.js launched
Process /teste/pm2/test/fixtures/child.js launched
Process /teste/pm2/test/fixtures/child.js launched
Process /teste/pm2/test/fixtures/child.js launched
Process /teste/pm2/test/fixtures/child.js launched
Process /teste/pm2/test/fixtures/child.js launched
Process /teste/pm2/test/fixtures/child.js launched
Process /teste/pm2/test/fixtures/child.js launched
    ✓ should resurrect processes (978ms)
{ msg: 'pong' }
    ✓ should ping pm2 
[PM2] Process /teste/pm2/lib/HttpInterface.js launched
[PM2] Process launched
    ✓ should launch pm2 web API 
[PM2] Process child succesfully reloaded
[PM2] Process toto succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] [WARN] pm2-http-interface app can't be reloaded - restarting it
[PM2] restartProcessId process id 17
    ✓ should reload all (2280ms)
[PM2] Reloading process by name tota
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] Process tota succesfully reloaded
[PM2] All processes reloaded
    ✓ should reload only on2 (1619ms)
    ✓ should describe all process with name 
    Restart methods
[PM2] restartProcessId process id 9
[PM2] restartProcessId process id 10
[PM2] restartProcessId process id 11
[PM2] restartProcessId process id 12
[PM2] restartProcessId process id 13
[PM2] restartProcessId process id 14
[PM2] restartProcessId process id 15
[PM2] restartProcessId process id 16
[PM2] restartProcessId process id 17
      ✓ should restart all (1638ms)
[PM2] restartProcessId process id 11
[PM2] restartProcessId process id 12
[PM2] restartProcessId process id 13
[PM2] restartProcessId process id 14
[PM2] restartProcessId process id 15
[PM2] restartProcessId process id 16
      ✓ should restart process by name (1266ms)
[PM2] restartProcessId process id 11
      ✓ should restart process by id (224ms)
    Stop methods
[PM2] Stopping tota
[PM2] stopProcessId process id 11
[PM2] stopProcessId process id 12
[PM2] stopProcessId process id 13
[PM2] stopProcessId process id 14
[PM2] stopProcessId process id 15
[PM2] stopProcessId process id 16
      ✓ should stop process name (870ms)
[PM2] Stopping 12
[PM2] stopProcessId process id 12
      ✓ should stop process id 
[PM2] Stopping all
[PM2] stopProcessId process id 9
[PM2] stopProcessId process id 10
[PM2] stopProcessId process id 11
[PM2] stopProcessId process id 12
[PM2] stopProcessId process id 13
[PM2] stopProcessId process id 14
[PM2] stopProcessId process id 15
[PM2] stopProcessId process id 16
[PM2] stopProcessId process id 17
      ✓ should stop process all (535ms)
    start OR restart
[PM2] Deleting all process
[PM2] deleteProcessId process id 9
[PM2] deleteProcessId process id 10
[PM2] deleteProcessId process id 11
[PM2] deleteProcessId process id 12
[PM2] deleteProcessId process id 13
[PM2] deleteProcessId process id 14
[PM2] deleteProcessId process id 15
[PM2] deleteProcessId process id 16
[PM2] deleteProcessId process id 17
      ✓ should start (368ms)
[PM2] restartProcessId process id 18
[PM2] restartProcessId process id 19
[PM2] restartProcessId process id 20
[PM2] restartProcessId process id 21
echo 1
child 1
api-2 1
api-2 1
      ✓ should NOW restart action (1412ms)
[PM2] Deleting all process
[PM2] deleteProcessId process id 18
[PM2] deleteProcessId process id 19
[PM2] deleteProcessId process id 20
[PM2] deleteProcessId process id 21
      ✓ should reset status (468ms)
      ✓ should start with specific environment variables depending on the env type (333ms)
[PM2] Deleting all process
[PM2] deleteProcessId process id 22
[PM2] deleteProcessId process id 23
[PM2] deleteProcessId process id 24
[PM2] deleteProcessId process id 25


  26 passing (16s)

spec "Programmatic test"
------------> ✔ Programmatic test
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
mocha ./test/programmatic/json_validation.mocha.js
child_process: customFds option is deprecated, use stdio instead.


  JSON validation tests
    ✓ should fail when passing wrong json 
    ✓ should succeed while passing right json 


  2 passing (13ms)

spec "JSON validation test"
------------> ✔ JSON validation test
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

mocha ./test/interface/interactor.daemonizer.mocha.js
child_process: customFds option is deprecated, use stdio instead.


  Daemonizer interactor
    ✓ should try get set keys but get error because nothing exposed 
    ✓ should work with env variables and create file 
    ✓ should retrieve data from file without env variable 
    ✓ should set new keys and write in configuration file 
    ✓ should work with object passed instead of direct params 


  5 passing (17ms)

spec "Remote interactor keys save verification"
------------> ✔ Remote interactor keys save verification
[PM2] Spawning PM2 daemon
[Keymetrics.io] Using (Public key: XXXP3) (Private key: XXXS3)
[Keymetrics.io][ERROR] Wrong public key (Public: XXXP3) (Secret: XXXS3) (Machine name: ip-172-16-101-213.ec2.internal)
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
mocha ./test/interface/remote.mocha.js
child_process: customFds option is deprecated, use stdio instead.


  Test remote PM2 actions
2015-01-05 14:50:58: [PM2][WORKER] Started with refreshing interval: 30000
2015-01-05 14:50:58: [[[[ PM2/God daemon launched ]]]]
2015-01-05 14:50:58: BUS system [READY] on port /root/.pm2/pub.sock
2015-01-05 14:50:58: RPC interface [READY] on port /root/.pm2/rpc.sock
PM2 forked
Launching interactor
[Keymetrics.io] Using (Public key: osef) (Private key: osef)
Interactor forked
Got new connection in Mock server
2015-01-05 14:50:59: Starting execution sequence in -cluster mode- for app name:child id:0
2015-01-05 14:50:59: App name:child id:0 online
2015-01-05 14:50:59: Starting execution sequence in -cluster mode- for app name:child id:1
2015-01-05 14:50:59: App name:child id:1 online
2015-01-05 14:50:59: Starting execution sequence in -cluster mode- for app name:child id:2
2015-01-05 14:50:59: App name:child id:2 online
2015-01-05 14:50:59: Starting execution sequence in -cluster mode- for app name:child id:3
2015-01-05 14:50:59: App name:child id:3 online
[PM2] Process ./test/fixtures/child.js launched
Sending command {"_type":"ask"}
    ✓ should send ask, receive ask:rep and identify agent 
Sending command {"_type":"trigger:pm2:action","method_name":"restart","parameters":{"name":"child"}}
2015-01-05 14:51:00: Locking 0
2015-01-05 14:51:00: Locking 1
2015-01-05 14:51:00: Locking 2
2015-01-05 14:51:00: Locking 3
2015-01-05 14:51:00: App name:child id:0 exited
2015-01-05 14:51:00: Process with pid 2741 killed
2015-01-05 14:51:00: Starting execution sequence in -cluster mode- for app name:child id:0
2015-01-05 14:51:00: App name:child id:0 online
2015-01-05 14:51:00: App name:child id:1 exited
2015-01-05 14:51:00: Process with pid 2748 killed
2015-01-05 14:51:00: Starting execution sequence in -cluster mode- for app name:child id:1
2015-01-05 14:51:00: App name:child id:1 online
2015-01-05 14:51:00: App name:child id:2 exited
2015-01-05 14:51:00: Process with pid 2755 killed
2015-01-05 14:51:00: Starting execution sequence in -cluster mode- for app name:child id:2
2015-01-05 14:51:00: App name:child id:2 online
2015-01-05 14:51:00: App name:child id:3 exited
2015-01-05 14:51:00: Process with pid 2767 killed
2015-01-05 14:51:00: Starting execution sequence in -cluster mode- for app name:child id:3
2015-01-05 14:51:00: App name:child id:3 online
2015-01-05 14:51:01: Unlocking 0
2015-01-05 14:51:01: Unlocking 1
2015-01-05 14:51:01: Unlocking 2
2015-01-05 14:51:01: Unlocking 3
    ✓ should act on PM2 (1119ms)
Sending command {"_type":"trigger:pm2:action","method_name":"restart","parameters":{"name":"UNKNOWN APP"}}
    ✓ should act on PM2 but handle failure 
Sending command {"_type":"trigger:pm2:action","method_name":"reload","parameters":{"name":"child"}}
2015-01-05 14:51:01: Locking 0
2015-01-05 14:51:01: Locking 1
2015-01-05 14:51:01: Locking 2
2015-01-05 14:51:01: Locking 3
2015-01-05 14:51:01: -reload- Creating a new process waiting for connections
2015-01-05 14:51:01: Starting execution sequence in -cluster mode- for app name:child id:0
2015-01-05 14:51:01: App name:child id:0 online
2015-01-05 14:51:01: -reload- New worker listening
2015-01-05 14:51:01: -reload- Old worker disconnected
2015-01-05 14:51:01: Process with pid 2794 killed
2015-01-05 14:51:01: -reload- Creating a new process waiting for connections
2015-01-05 14:51:01: Starting execution sequence in -cluster mode- for app name:child id:1
2015-01-05 14:51:01: App name:child id:1 online
2015-01-05 14:51:01: -reload- New worker listening
2015-01-05 14:51:01: -reload- Old worker disconnected
2015-01-05 14:51:01: Process with pid 2802 killed
2015-01-05 14:51:01: -reload- Creating a new process waiting for connections
2015-01-05 14:51:01: Starting execution sequence in -cluster mode- for app name:child id:2
2015-01-05 14:51:01: App name:child id:2 online
2015-01-05 14:51:01: -reload- New worker listening
2015-01-05 14:51:02: -reload- Old worker disconnected
2015-01-05 14:51:02: Process with pid 2810 killed
2015-01-05 14:51:02: -reload- Creating a new process waiting for connections
2015-01-05 14:51:02: Starting execution sequence in -cluster mode- for app name:child id:3
2015-01-05 14:51:02: App name:child id:3 online
2015-01-05 14:51:02: -reload- New worker listening
2015-01-05 14:51:02: -reload- Old worker disconnected
2015-01-05 14:51:02: Process with pid 2818 killed
2015-01-05 14:51:02: Unlocking 0
2015-01-05 14:51:02: Unlocking 1
2015-01-05 14:51:02: Unlocking 2
2015-01-05 14:51:02: Unlocking 3
    ✓ should RELOAD (1378ms)
Sending command {"_type":"trigger:pm2:action","method_name":"gracefulReload","parameters":{"name":"child"}}
2015-01-05 14:51:02: Locking 0
2015-01-05 14:51:02: Locking 1
2015-01-05 14:51:02: Locking 2
2015-01-05 14:51:02: Locking 3
2015-01-05 14:51:02: Starting execution sequence in -cluster mode- for app name:child id:0
2015-01-05 14:51:02: App name:child id:0 online
2015-01-05 14:51:02: -reload- New worker listening
2015-01-05 14:51:02: -reload- Old worker disconnected
2015-01-05 14:51:03: Process with pid 2825 killed
2015-01-05 14:51:03: Starting execution sequence in -cluster mode- for app name:child id:1
2015-01-05 14:51:03: App name:child id:1 online
2015-01-05 14:51:03: -reload- New worker listening
2015-01-05 14:51:03: -reload- Old worker disconnected
2015-01-05 14:51:03: Process with pid 2833 killed
2015-01-05 14:51:03: Starting execution sequence in -cluster mode- for app name:child id:2
2015-01-05 14:51:03: App name:child id:2 online
2015-01-05 14:51:03: -reload- New worker listening
2015-01-05 14:51:03: -reload- Old worker disconnected
2015-01-05 14:51:03: Process with pid 2841 killed
2015-01-05 14:51:03: Starting execution sequence in -cluster mode- for app name:child id:3
2015-01-05 14:51:03: App name:child id:3 online
2015-01-05 14:51:03: -reload- New worker listening
2015-01-05 14:51:03: -reload- Old worker disconnected
2015-01-05 14:51:03: Process with pid 2849 killed
2015-01-05 14:51:04: Unlocking 0
2015-01-05 14:51:04: Unlocking 1
2015-01-05 14:51:04: Unlocking 2
2015-01-05 14:51:04: Unlocking 3
    ✓ should gracefulRELOAD (1568ms)
Sending command {"_type":"trigger:pm2:action","method_name":"reset","parameters":{"name":"child"}}
2015-01-05 14:51:04: Locking 0
2015-01-05 14:51:04: Locking 1
2015-01-05 14:51:04: Locking 2
2015-01-05 14:51:04: Locking 3
2015-01-05 14:51:04: Unlocking 0
2015-01-05 14:51:04: Unlocking 1
2015-01-05 14:51:04: Unlocking 2
2015-01-05 14:51:04: Unlocking 3
    ✓ should RESET metadata (494ms)
[PM2] Deleting all process
2015-01-05 14:51:06: App name:child id:0 exited
2015-01-05 14:51:06: Process with pid 2869 killed
[PM2] deleteProcessId process id 0
2015-01-05 14:51:06: App name:child id:1 exited
2015-01-05 14:51:07: Process with pid 2877 killed
[PM2] deleteProcessId process id 1
2015-01-05 14:51:07: App name:child id:2 exited
2015-01-05 14:51:07: Process with pid 2885 killed
[PM2] deleteProcessId process id 2
2015-01-05 14:51:07: App name:child id:3 exited
2015-01-05 14:51:07: Process with pid 2893 killed
[PM2] deleteProcessId process id 3
2015-01-05 14:51:07: Starting execution sequence in -cluster mode- for app name:child id:4
2015-01-05 14:51:07: App name:child id:4 online
2015-01-05 14:51:07: Starting execution sequence in -cluster mode- for app name:child id:5
2015-01-05 14:51:07: App name:child id:5 online
2015-01-05 14:51:07: Starting execution sequence in -cluster mode- for app name:child id:6
2015-01-05 14:51:07: App name:child id:6 online
2015-01-05 14:51:07: Starting execution sequence in -cluster mode- for app name:child id:7
2015-01-05 14:51:08: App name:child id:7 online
[PM2] Process ./test/fixtures/child.js launched
    ✓ should delete all processes (3562ms)
2015-01-05 14:51:08: Locking 4
2015-01-05 14:51:08: Locking 5
2015-01-05 14:51:08: Locking 6
2015-01-05 14:51:08: Locking 7
2015-01-05 14:51:08: App name:child id:4 exited
2015-01-05 14:51:08: Process with pid 2930 killed
2015-01-05 14:51:08: Starting execution sequence in -cluster mode- for app name:child id:4
2015-01-05 14:51:08: App name:child id:4 online
[PM2] restartProcessId process id 4
2015-01-05 14:51:08: App name:child id:5 exited
2015-01-05 14:51:08: Process with pid 2933 killed
2015-01-05 14:51:08: Starting execution sequence in -cluster mode- for app name:child id:5
2015-01-05 14:51:08: App name:child id:5 online
[PM2] restartProcessId process id 5
2015-01-05 14:51:08: App name:child id:6 exited
2015-01-05 14:51:08: Process with pid 2940 killed
2015-01-05 14:51:08: Starting execution sequence in -cluster mode- for app name:child id:6
2015-01-05 14:51:08: App name:child id:6 online
[PM2] restartProcessId process id 6
2015-01-05 14:51:08: App name:child id:7 exited
2015-01-05 14:51:08: Process with pid 2947 killed
2015-01-05 14:51:08: Starting execution sequence in -cluster mode- for app name:child id:7
2015-01-05 14:51:09: App name:child id:7 online
[PM2] restartProcessId process id 7
Command restart finished
2015-01-05 14:51:09: Unlocking 4
2015-01-05 14:51:09: Unlocking 5
2015-01-05 14:51:09: Unlocking 6
2015-01-05 14:51:09: Unlocking 7
Processes child unlocked
    ✓ should test .remote (1110ms)
    ✓ should test .remote 
2015-01-05 14:51:09: Locking 4
2015-01-05 14:51:09: Locking 5
2015-01-05 14:51:09: Locking 6
2015-01-05 14:51:09: Locking 7
[PM2] Reloading process by name child
2015-01-05 14:51:09: -reload- Creating a new process waiting for connections
2015-01-05 14:51:09: Starting execution sequence in -cluster mode- for app name:child id:4
2015-01-05 14:51:09: App name:child id:4 online
2015-01-05 14:51:09: -reload- New worker listening
2015-01-05 14:51:09: -reload- Old worker disconnected
2015-01-05 14:51:09: Process with pid 2960 killed
[PM2] Process child succesfully reloaded
2015-01-05 14:51:09: -reload- Creating a new process waiting for connections
2015-01-05 14:51:09: Starting execution sequence in -cluster mode- for app name:child id:5
2015-01-05 14:51:09: App name:child id:5 online
2015-01-05 14:51:09: -reload- New worker listening
2015-01-05 14:51:09: -reload- Old worker disconnected
2015-01-05 14:51:09: Process with pid 2968 killed
[PM2] Process child succesfully reloaded
2015-01-05 14:51:10: -reload- Creating a new process waiting for connections
2015-01-05 14:51:10: Starting execution sequence in -cluster mode- for app name:child id:6
2015-01-05 14:51:10: App name:child id:6 online
2015-01-05 14:51:10: -reload- New worker listening
2015-01-05 14:51:10: -reload- Old worker disconnected
2015-01-05 14:51:10: Process with pid 2977 killed
[PM2] Process child succesfully reloaded
2015-01-05 14:51:10: -reload- Creating a new process waiting for connections
2015-01-05 14:51:10: Starting execution sequence in -cluster mode- for app name:child id:7
2015-01-05 14:51:10: App name:child id:7 online
2015-01-05 14:51:10: -reload- New worker listening
2015-01-05 14:51:10: -reload- Old worker disconnected
2015-01-05 14:51:10: Process with pid 2985 killed
[PM2] Process child succesfully reloaded
[PM2] All processes reloaded
Command reload finished
2015-01-05 14:51:10: Unlocking 4
2015-01-05 14:51:10: Unlocking 5
2015-01-05 14:51:10: Unlocking 6
2015-01-05 14:51:10: Unlocking 7
Processes child unlocked
    ✓ should test .remote #2 (1367ms)
2015-01-05 14:51:10: pm2 has been killed by signal


  10 passing (13s)

spec "Remote interactions test"
------------> ✔ Remote interactions test
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
mocha ./test/interface/bus.spec.mocha.js
child_process: customFds option is deprecated, use stdio instead.


  PM2 BUS / RPC
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Deleting all process
[PM2] [WARN] No process found
    Events
[PM2] Process /teste/pm2/test/fixtures/child.js launched
      ✓ should (process:event) when start process get online event and start event with right properties 
[PM2] Deleting all process
[PM2] deleteProcessId process id 0
[PM2] Process /teste/pm2/test/interface/fixtures/log:out.js launched
      ✓ should (log:out log:err) 
[PM2] Deleting all process
[PM2] deleteProcessId process id 1
[PM2] Process /teste/pm2/test/interface/fixtures/process:exception.js launched
      ✓ should (process:exception) (307ms)
[PM2] Deleting all process
[PM2] deleteProcessId process id 2
[PM2] Process /teste/pm2/test/interface/fixtures/human:event.js launched
      ✓ should (human:event) (309ms)
[PM2] Deleting all process
[PM2] deleteProcessId process id 3
[PM2] Process /teste/pm2/test/interface/fixtures/http:transaction.js launched
      ✓ should (transaction:http) (237ms)
[PM2] Deleting all process
[PM2] deleteProcessId process id 4
[PM2] Deleting all process
[PM2] [WARN] No process found
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped


  5 passing (2s)

spec "Protocol communication test"
------------> ✔ Protocol communication test
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
mocha ./test/interface/bus.fork.spec.mocha.js
child_process: customFds option is deprecated, use stdio instead.


  PM2 BUS / RPC
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Deleting all process
[PM2] [WARN] No process found
    Events
[PM2] Process /teste/pm2/test/fixtures/child.js launched
      ✓ should (process:event) when start process get online event and start event with right properties 
[PM2] Deleting all process
[PM2] deleteProcessId process id 0
[PM2] Process /teste/pm2/test/interface/fixtures/log:out.js launched
      ✓ should (log:out log:err) 
[PM2] Deleting all process
[PM2] deleteProcessId process id 1
[PM2] Process /teste/pm2/test/interface/fixtures/process:exception.js launched
      ✓ should (process:exception) (281ms)
[PM2] Deleting all process
[PM2] deleteProcessId process id 2
[PM2] Process /teste/pm2/test/interface/fixtures/human:event.js launched
      ✓ should (human:event) (277ms)
[PM2] Deleting all process
[PM2] deleteProcessId process id 3
[PM2] Process /teste/pm2/test/interface/fixtures/http:transaction.js launched
      ✓ should (transaction:http) (276ms)
[PM2] Deleting all process
[PM2] deleteProcessId process id 4
[PM2] Deleting all process
[PM2] [WARN] No process found
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped


  5 passing (2s)

spec "Protocol communication test"
------------> ✔ Protocol communication test
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

echo "########## PROGRAMMATIC TEST DONE #########"
########## PROGRAMMATIC TEST DONE #########

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

# Determine wget / curl
which wget > /dev/null
if [ $? -eq 0 ]
then
    http_get="wget"
else
    echo -e "\033[31mYou need wget to run this test \033[0m";
    exit 1;
fi

function fail {
  echo -e "######## \033[31m  ✘ $1\033[0m"
  exit 1
}

function success {
  echo -e "\033[32m------------> ✔ $1\033[0m"
}

function spec {
  RET=$?
  sleep 0.3
  [ $RET -eq 0 ] || fail "$1"
  success "$1"
}

function ispec {
  RET=$?
  sleep 0.3
  [ $RET -ne 0 ] || fail "$1"
  success "$1"
}

function should {
    sleep 0.5
    OUT=`$pm2 prettylist | grep -o "$2" | wc -l`
    [ $OUT -eq $3 ] || fail "$1"
    success "$1"
}

# Abort script at first error
set -e
# Display all commands executed
set -o verbose

echo "####################### DEBUG ############################"
####################### DEBUG ############################
echo "PM2 Command = " $pm2
PM2 Command =  /usr/local/bin/node /teste/pm2/bin/pm2
echo "Node version = " $nodeVersion
Node version =  v0.11.14
$node -e "var os = require('os'); console.log('arch : %s\nplatform : %s\nrelease : %s\ntype : %s\nmem : %d', os.arch(), os.platform(), os.release(), os.type(), os.totalmem())"
arch : x64
platform : linux
release : 3.10.0-123.9.3.el7.x86_64
type : Linux
mem : 7406440448
echo "###################### !DEBUG! ###########################"
###################### !DEBUG! ###########################

# if [ $TRAVIS ]
# then
#   export DEBUG="*"
# fi

bash ./test/bash/log-timestamp.sh

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

# Determine wget / curl
which wget > /dev/null
if [ $? -eq 0 ]
then
    http_get="wget"
else
    echo -e "\033[31mYou need wget to run this test \033[0m";
    exit 1;
fi

function fail {
  echo -e "######## \033[31m  ✘ $1\033[0m"
  exit 1
}

function success {
  echo -e "\033[32m------------> ✔ $1\033[0m"
}

function spec {
  RET=$?
  sleep 0.3
  [ $RET -eq 0 ] || fail "$1"
  success "$1"
}

function ispec {
  RET=$?
  sleep 0.3
  [ $RET -ne 0 ] || fail "$1"
  success "$1"
}

function should {
    sleep 0.5
    OUT=`$pm2 prettylist | grep -o "$2" | wc -l`
    [ $OUT -eq $3 ] || fail "$1"
    success "$1"
}

function head {
  echo -e "\x1B[1;35m$1\x1B[0m"
}
function rm_pm2log {
  if [ "$1" -ne 1 ]; then
    $pm2 kill
    rm -rf ~/.pm2/pm2.log
  fi
}
function grep_log {
  if [ -z $TRAVIS ]; then
    echo "not travis"
    eval "$pm2 $1"
    sleep 0.3
    OUT=`cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l`
  else
    echo "travis"
    eval "$pm2 $1 >| pm2.log"
    sleep 0.3
    OUT=`cat pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l`
  fi
}
function no_prefix {
  eval "grep_log \"$1\""
  echo "line count: $OUT"
  [ $OUT -eq 0 ] || fail "expect no timestamp prefix in pm2.log, but currently existing."
  success "have no timestamp prefix"
  rm_pm2log "$2"
}
function prefix {
  eval "grep_log \"$1\""
  echo "line count: $OUT"
  [ $OUT -ne 0 ] || fail "expect have timestamp prefix in pm2.log, but currently does not exist."
  success "have timestamp prefix"

  rm_pm2log "$2"
}

cd $file_path

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

sleep 0.5

if [ -z $TRAVIS ]
then
  echo "removing pm2.log"
  rm -rf ~/.pm2/pm2.log
fi
removing pm2.log

unset PM2_LOG_DATE_FORMAT
export PM2_LOG_DATE_FORMAT=""

head ">> LIST (NO PREFIX)"
>> LIST (NO PREFIX)
no_prefix "ls" 0
grep_log "ls"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 ls
[PM2] Spawning PM2 daemon
[PM2] Success
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 0
------------> ✔ have no timestamp prefix
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

head ">> START (NO PREFIX)"
>> START (NO PREFIX)
no_prefix "start echo.js" 1
grep_log "start echo.js"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 start echo.js
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process echo.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3276 │ online │         0 │ 0s     │ 12.777 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 0
------------> ✔ have no timestamp prefix

head ">> RESTART (NO PREFIX)"
>> RESTART (NO PREFIX)
no_prefix "restart echo" 1
grep_log "restart echo"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 restart echo
[PM2] restartProcessId process id 0
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3291 │ online │         1 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 0
------------> ✔ have no timestamp prefix

head ">> STOP (NO PREFIX)"
>> STOP (NO PREFIX)
no_prefix "stop echo" 0
grep_log "stop echo"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 stop echo
[PM2] Stopping echo
[PM2] stopProcessId process id 0
┌──────────┬────┬──────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ echo     │ 0  │ fork │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
└──────────┴────┴──────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 0
------------> ✔ have no timestamp prefix
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

head ">> START JSON (NO PREFIX)"
>> START JSON (NO PREFIX)
no_prefix "start echo-pm2.json" 1
grep_log "start echo-pm2.json"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 start echo-pm2.json
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3334 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 0
------------> ✔ have no timestamp prefix

head ">> RESTART JSON (NO PREFIX)"
>> RESTART JSON (NO PREFIX)
no_prefix "restart echo-pm2.json" 1
grep_log "restart echo-pm2.json"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 restart echo-pm2.json
[PM2] Process 0 restarted
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3348 │ online │         1 │ 0s     │ 12.773 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 0
------------> ✔ have no timestamp prefix

head ">> STOP-JSON (NO PREFIX)"
>> STOP-JSON (NO PREFIX)
no_prefix "stop echo-pm2.json" 0
grep_log "stop echo-pm2.json"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 stop echo-pm2.json
[PM2] Stopping echo-pm2.json
[PM2] Process 0 restarted
┌──────────┬────┬──────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ echo     │ 0  │ fork │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
└──────────┴────┴──────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 0
------------> ✔ have no timestamp prefix
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

export PM2_LOG_DATE_FORMAT="YYYY-MM-DD HH:mm Z"

head ">> LIST (PREFIX)"
>> LIST (PREFIX)
prefix "ls" 0
grep_log "ls"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 ls
[PM2] Spawning PM2 daemon
[PM2] Success
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 4
------------> ✔ have timestamp prefix
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

head ">> START (PREFIX)"
>> START (PREFIX)
prefix "start echo.js" 1
grep_log "start echo.js"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 start echo.js
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process echo.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3406 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 6
------------> ✔ have timestamp prefix

head ">> RESTART (PREFIX)"
>> RESTART (PREFIX)
prefix "restart echo" 1
grep_log "restart echo"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 restart echo
[PM2] restartProcessId process id 0
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3432 │ online │         1 │ 0s     │ 12.254 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 10
------------> ✔ have timestamp prefix

head ">> STOP (PREFIX)"
>> STOP (PREFIX)
prefix "stop echo" 0
grep_log "stop echo"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 stop echo
[PM2] Stopping echo
[PM2] stopProcessId process id 0
┌──────────┬────┬──────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ echo     │ 0  │ fork │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
└──────────┴────┴──────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 12
------------> ✔ have timestamp prefix
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

head ">> START JSON (PREFIX)"
>> START JSON (PREFIX)
prefix "start echo-pm2.json" 1
grep_log "start echo-pm2.json"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 start echo-pm2.json
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3474 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 6
------------> ✔ have timestamp prefix

head ">> RESTART JSON (PREFIX)"
>> RESTART JSON (PREFIX)
prefix "restart echo-pm2.json" 1
grep_log "restart echo-pm2.json"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 restart echo-pm2.json
[PM2] Process 0 restarted
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3489 │ online │         1 │ 0s     │ 12.777 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 10
------------> ✔ have timestamp prefix

head ">> STOP-JSON (PREFIX)"
>> STOP-JSON (PREFIX)
prefix "restart echo-pm2.json" 0
grep_log "restart echo-pm2.json"
not travis
/usr/local/bin/node /teste/pm2/bin/pm2 restart echo-pm2.json
[PM2] Process 0 restarted
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3501 │ online │         2 │ 0s     │ 12.773 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
cat ~/.pm2/pm2.log | grep -n "[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}" | wc -l
line count: 14
------------> ✔ have timestamp prefix
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

rm -rf pm2.log
unset PM2_LOG_DATE_FORMAT
touch ~/.pm2/pm2.log
spec "timetstamp prefix of pm2.log"
------------> ✔ timetstamp prefix of pm2.log
bash ./test/bash/cli.sh

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

# Determine wget / curl
which wget > /dev/null
if [ $? -eq 0 ]
then
    http_get="wget"
else
    echo -e "\033[31mYou need wget to run this test \033[0m";
    exit 1;
fi

function fail {
  echo -e "######## \033[31m  ✘ $1\033[0m"
  exit 1
}

function success {
  echo -e "\033[32m------------> ✔ $1\033[0m"
}

function spec {
  RET=$?
  sleep 0.3
  [ $RET -eq 0 ] || fail "$1"
  success "$1"
}

function ispec {
  RET=$?
  sleep 0.3
  [ $RET -ne 0 ] || fail "$1"
  success "$1"
}

function should {
    sleep 0.5
    OUT=`$pm2 prettylist | grep -o "$2" | wc -l`
    [ $OUT -eq $3 ] || fail "$1"
    success "$1"
}

echo -e "\033[1mRunning tests:\033[0m"
Running tests:

cd $file_path

#
# Different way to stop process
#
$pm2 start echo.js
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process echo.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3555 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
$pm2 start echo.js -f
[PM2] Process echo.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3555 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ echo     │ 1  │ fork │ 3563 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
$pm2 start echo.js -f
[PM2] Process echo.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3555 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ echo     │ 1  │ fork │ 3563 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ echo     │ 2  │ fork │ 3569 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

OUT=`$pm2 prettylist | grep -o "restart_time" | wc -l`
$pm2 prettylist | grep -o "restart_time" | wc -l
[ $OUT -eq 3 ] || fail "$1"
success "$1"
------------> ✔ 

$pm2 stop 12412
[PM2] Stopping 12412
[PM2] [ERROR] Process 12412 not found
$pm2 stop 0
[PM2] Stopping 0
[PM2] stopProcessId process id 0
┌──────────┬────┬──────┬──────┬─────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status  │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼─────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 0    │ stopped │         0 │ 0      │      0 B    │ disabled │
│ echo     │ 1  │ fork │ 3563 │ online  │         0 │ 1s     │ 12.773 MB   │ disabled │
│ echo     │ 2  │ fork │ 3569 │ online  │         0 │ 1s     │ 12.773 MB   │ disabled │
└──────────┴────┴──────┴──────┴─────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

OUT=`$pm2 prettylist | grep -o "stopped" | wc -l`
$pm2 prettylist | grep -o "stopped" | wc -l
[ $OUT -eq 1 ] || fail "$1"
success "$1"
------------> ✔ 

$pm2 stop asdsdaecho.js
[PM2] Stopping asdsdaecho.js
[PM2] [ERROR] Process asdsdaecho.js not found

$pm2 stop echo
[PM2] Stopping echo
[PM2] stopProcessId process id 0
[PM2] stopProcessId process id 1
[PM2] stopProcessId process id 2
┌──────────┬────┬──────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ echo     │ 0  │ fork │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ echo     │ 1  │ fork │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ echo     │ 2  │ fork │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
└──────────┴────┴──────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

$pm2 list
┌──────────┬────┬──────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ echo     │ 0  │ fork │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ echo     │ 1  │ fork │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ echo     │ 2  │ fork │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
└──────────┴────┴──────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
OUT=`$pm2 prettylist | grep -o "stopped" | wc -l`
$pm2 prettylist | grep -o "stopped" | wc -l
[ $OUT -eq 3 ] || fail "$1"
success "$1"
------------> ✔ 


#
# Describe process
#
$pm2 describe 0
Describing process with pid 0 - name echo
┌───────────────────┬──────────────────────────────────┐
│ status            │ stopped                          │
│ name              │ echo                             │
│ id                │ 0                                │
│ path              │ /teste/pm2/test/fixtures/echo.js │
│ args              │                                  │
│ exec cwd          │ /teste/pm2/test/fixtures         │
│ error log path    │ /root/.pm2/logs/echo-error-0.log │
│ out log path      │ /root/.pm2/logs/echo-out-0.log   │
│ pid path          │ /root/.pm2/pids/echo-0.pid       │
│ mode              │ fork_mode                        │
│ node v8 arguments │                                  │
│ watch & reload    │ ✘                                │
│ interpreter       │ node                             │
│ restarts          │ 0                                │
│ unstable restarts │ 0                                │
│ uptime            │ 0                                │
│ created at        │ 2015-01-05T16:51:34.754Z         │
└───────────────────┴──────────────────────────────────┘
spec "should describe stopped process"
------------> ✔ should describe stopped process

$pm2 restart 1
[PM2] restartProcessId process id 1
┌──────────┬────┬──────┬──────┬─────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status  │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼─────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 0    │ stopped │         0 │ 0      │      0 B    │ disabled │
│ echo     │ 1  │ fork │ 3639 │ online  │         0 │ 0s     │ 12.258 MB   │ disabled │
│ echo     │ 2  │ fork │ 0    │ stopped │         0 │ 0      │      0 B    │ disabled │
└──────────┴────┴──────┴──────┴─────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

$pm2 describe 1
Describing process with pid 1 - name echo
┌───────────────────┬──────────────────────────────────┐
│ status            │ online                           │
│ name              │ echo                             │
│ id                │ 1                                │
│ path              │ /teste/pm2/test/fixtures/echo.js │
│ args              │                                  │
│ exec cwd          │ /teste/pm2/test/fixtures         │
│ error log path    │ /root/.pm2/logs/echo-error-1.log │
│ out log path      │ /root/.pm2/logs/echo-out-1.log   │
│ pid path          │ /root/.pm2/pids/echo-1.pid       │
│ mode              │ fork_mode                        │
│ node v8 arguments │                                  │
│ watch & reload    │ ✘                                │
│ interpreter       │ node                             │
│ restarts          │ 0                                │
│ unstable restarts │ 0                                │
│ uptime            │ 0s                               │
│ created at        │ 2015-01-05T16:51:38.744Z         │
└───────────────────┴──────────────────────────────────┘
spec "should describe online process"
------------> ✔ should describe online process

$pm2 describe asdsa
asdsa doesn't exist
ispec "should exit with right exit code when no process found"
------------> ✔ should exit with right exit code when no process found

#
# Update pm2
#
$pm2 updatePM2
Be sure to have the latest version by doing `npm install pm2@latest -g` before doing this procedure.
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] deleteProcessId process id 1
[PM2] deleteProcessId process id 2
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
Process /teste/pm2/test/fixtures/echo.js launched
Process /teste/pm2/test/fixtures/echo.js launched
Process /teste/pm2/test/fixtures/echo.js launched
>>>>>>>>>> PM2 updated
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3670 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ echo     │ 1  │ fork │ 3673 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ echo     │ 2  │ fork │ 3678 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "should update pm2"
------------> ✔ should update pm2



#
# Verify PID
#
$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] deleteProcessId process id 1
[PM2] deleteProcessId process id 2
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

$pm2 start echo.js -p echo.pid
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process echo.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 3705 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

sleep 0.5
ls echo-0.pid
echo-0.pid
spec "should pid file exists"
------------> ✔ should pid file exists

$pm2 stop all
[PM2] Stopping all
[PM2] stopProcessId process id 0
┌──────────┬────┬──────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ echo     │ 0  │ fork │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
└──────────┴────┴──────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

sleep 1

ls echo-0.pid
ls: não é possível acessar echo-0.pid: Arquivo ou diretório não encontrado
ispec "should pid file be deleted once stopped"
------------> ✔ should pid file be deleted once stopped

$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

$pm2 start echo.js -p echo.pid -i 1
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process echo.js launched
┌──────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ cluster │ 3753 │ online │         0 │ 0s     │ 19.152 MB   │ disabled │
└──────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

sleep 1

ls echo-0.pid
echo-0.pid
spec "should pid file exists"
------------> ✔ should pid file exists

$pm2 stop all
[PM2] Stopping all
[PM2] stopProcessId process id 0
┌──────────┬────┬─────────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode    │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼─────────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ echo     │ 0  │ cluster │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
└──────────┴────┴─────────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

sleep 1

ls echo-0.pid
ls: não é possível acessar echo-0.pid: Arquivo ou diretório não encontrado
ispec "should pid file be deleted once stopped"
------------> ✔ should pid file be deleted once stopped

$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped






#
# Main tests
#
$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
spec "kill daemon"
------------> ✔ kill daemon

$pm2 start eyayimfake
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] [ERROR] script not found : /teste/pm2/test/fixtures/eyayimfake
Error: script not found : /teste/pm2/test/fixtures/eyayimfake
    at resolvePaths (/teste/pm2/lib/CLI.js:1539:11)
    at /teste/pm2/lib/CLI.js:127:28
    at /teste/pm2/node_modules/pm2-axon-rpc/lib/client.js:45:10
    at Parser.<anonymous> (/teste/pm2/node_modules/pm2-axon/lib/sockets/req.js:67:8)
    at Parser.emit (events.js:107:17)
    at Parser._write (/teste/pm2/node_modules/pm2-axon/node_modules/amp/lib/stream.js:91:16)
    at doWrite (_stream_writable.js:265:12)
    at writeOrBuffer (_stream_writable.js:252:5)
    at Parser.Writable.write (_stream_writable.js:197:11)
    at Socket.ondata (_stream_readable.js:539:20)
ispec "should fail if script doesnt exist"
------------> ✔ should fail if script doesnt exist

$pm2

  Usage: pm2 [cmd] app

  Commands:

    start [options] <file|json|stdin>                          start and daemonize an app
    deploy <file|environment>                                  deploy your json
    startOrRestart <json>                                      start or restart JSON file
    startOrReload <json>                                       start or gracefully reload JSON file
    startOrGracefulReload <json>                               start or gracefully reload JSON file
    stop [options] <id|name|all|json|stdin>                    stop a process (to start it again, do pm2 restart <app>)
    restart [options] <id|name|all|json|stdin>                 restart a process
    reload <name|all>                                          reload processes (note that its for app using HTTP/HTTPS)
    gracefulReload <name|all>                                  gracefully reload a process. Send a "shutdown" message to close all connections.
    delete <name|id|script|all|json|stdin>                     stop and delete a process from pm2 process list
    sendSignal <signal> <pm2_id|name>                          send a system signal to the target process
    ping                                                       ping pm2 daemon - if not up it will launch it
    updatePM2                                                  update in-memory PM2 with local PM2
    update                                                     (alias) update in-memory PM2 with local PM2
    interact [secret_key|command] [public_key] [machine_name]  agent actions for keymetrics.io - command can be stop|info|delete|restart
    web                                                        launch an health API on port 9615
    dump                                                       dump all processes for resurrecting them later
    save                                                       (alias) dump all processes for resurrecting them later
    resurrect                                                  resurrect previously dumped processes
    startup <platform>                                         auto resurrect process at startup. [platform] = ubuntu, centos, gentoo or systemd
    generate                                                   generate an ecosystem.json configuration file
    ecosystem                                                  generate an ecosystem.json configuration file
    reset <name|id|all>                                        reset counters for process
    describe <id>                                              describe all parameters of a process id
    desc <id>                                                  (alias) describe all parameters of a process id
    info <id>                                                  (alias) describe all parameters of a process id
    show <id>                                                  (alias) describe all parameters of a process id
    list                                                       list all processes
    ls                                                         (alias) list all processes
    l                                                          (alias) list all processes
    status                                                     (alias) list all processes
    jlist                                                      list all processes in JSON format
    prettylist                                                 print json in a prettified JSON
    monit                                                      launch termcaps monitoring
    m                                                          (alias) launch termcaps monitoring
    flush                                                      flush logs
    reloadLogs                                                 reload all logs
    logs [options] [id|name]                                   stream logs file. Default stream all logs
    ilogs                                                      advanced interface to display logs
    kill                                                       kill daemon
    pull <name> [commit_id]                                    updates repository for a given app
    forward <name>                                             updates repository to the next commit for a given app
    backward <name>                                            downgrades repository to the previous commit for a given app
    *                                                          undefined

  Options:

    -h, --help                           output usage information
    -V, --version                        output the version number
    -v --version                         get version
    -s --silent                          hide all messages
    -m --mini-list                       display a compacted list without formatting
    -f --force                           force actions
    -n --name <name>                     set a <name> for script
    -i --instances <number>              launch [number] instances (for networked app)(load balanced)
    -l --log [path]                      specify entire log file (error and out are both included)
    -o --output <path>                   specify out log file
    -e --error <path>                    specify error log file
    -p --pid <pid>                       specify pid file
    --max-memory-restart <memory>        specify max memory amount used to autorestart (in megaoctets)
    --env <environment_name>             specify environment to get specific env variables (for JSON declaration)
    -x --execute-command                 execute a program using fork system
    -u --user <username>                 define user when generating startup script
    -c --cron <cron_pattern>             restart a running process based on a cron pattern
    -w --write                           write configuration in local folder
    --interpreter <interpreter>          the interpreter pm2 should use for executing app (bash, python...)
    --log-date-format <momentjs format>  add custom prefix timestamp to logs
    --no-daemon                          run pm2 daemon in the foreground if it doesn't exist already
    --merge-logs                         merge logs from different instances but keep error and out separated
    --watch                              watch application folder for changes
    --ignore-watch <folders|files>       folder/files to be ignored watching, chould be a specific name or regex - e.g. --ignore-watch="test node_modules "some scripts""ispec "No argument"
------------> ✔ No argument

$pm2 list
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

$pm2 start cluster-pm2.json
[PM2] Process launched
┌────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name   │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust │ 0  │ cluster │ 3828 │ online │         0 │ 0s     │ 17.688 MB   │ disabled │
│ serv-clust │ 1  │ cluster │ 3835 │ online │         0 │ 0s     │ 15.836 MB   │ disabled │
│ serv-clust │ 2  │ cluster │ 3842 │ online │         0 │ 0s     │ 17.895 MB   │ disabled │
│ serv-clust │ 3  │ cluster │ 3845 │ online │         0 │ 0s     │ 17.836 MB   │ disabled │
└────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should start well formated json with name for file prefix"
------------> ✔ Should start well formated json with name for file prefix

$pm2 list
┌────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name   │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust │ 0  │ cluster │ 3828 │ online │         0 │ 1s     │ 17.688 MB   │ disabled │
│ serv-clust │ 1  │ cluster │ 3835 │ online │         0 │ 1s     │ 15.836 MB   │ disabled │
│ serv-clust │ 2  │ cluster │ 3842 │ online │         0 │ 1s     │ 17.895 MB   │ disabled │
│ serv-clust │ 3  │ cluster │ 3845 │ online │         0 │ 0s     │ 17.836 MB   │ disabled │
└────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should list processes succesfully"
------------> ✔ Should list processes succesfully


$pm2 start multi-echo.json
[PM2] Process launched
[PM2] Process launched
┌────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name   │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust │ 0  │ cluster │ 3828 │ online │         0 │ 1s     │ 17.688 MB   │ disabled │
│ serv-clust │ 1  │ cluster │ 3835 │ online │         0 │ 1s     │ 15.836 MB   │ disabled │
│ serv-clust │ 2  │ cluster │ 3842 │ online │         0 │ 1s     │ 17.895 MB   │ disabled │
│ serv-clust │ 3  │ cluster │ 3845 │ online │         0 │ 1s     │ 17.836 MB   │ disabled │
│ echo2      │ 4  │ fork    │ 3888 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
│ echo3      │ 5  │ fork    │ 3891 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should start multiple applications"
------------> ✔ Should start multiple applications

$pm2 generate echo
File /teste/pm2/test/fixtures/ecosystem.json5 generated
spec "Should generate echo sample json"
------------> ✔ Should generate echo sample json

$pm2 start echo-pm2.json -f
[PM2] Process launched
┌────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name   │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust │ 0  │ cluster │ 3828 │ online │         0 │ 3s     │ 17.688 MB   │ disabled │
│ serv-clust │ 1  │ cluster │ 3835 │ online │         0 │ 2s     │ 15.836 MB   │ disabled │
│ serv-clust │ 2  │ cluster │ 3842 │ online │         0 │ 2s     │ 17.895 MB   │ disabled │
│ serv-clust │ 3  │ cluster │ 3845 │ online │         0 │ 2s     │ 17.836 MB   │ disabled │
│ echo2      │ 4  │ fork    │ 3888 │ online │         0 │ 1s     │ 12.773 MB   │ disabled │
│ echo3      │ 5  │ fork    │ 3891 │ online │         0 │ 1s     │ 12.773 MB   │ disabled │
│ echo       │ 6  │ fork    │ 3911 │ online │         0 │ 0s     │ 12.262 MB   │ disabled │
└────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should start echo service"
------------> ✔ Should start echo service

$pm2 list
┌────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name   │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust │ 0  │ cluster │ 3828 │ online │         0 │ 3s     │ 17.688 MB   │ disabled │
│ serv-clust │ 1  │ cluster │ 3835 │ online │         0 │ 3s     │ 15.836 MB   │ disabled │
│ serv-clust │ 2  │ cluster │ 3842 │ online │         0 │ 3s     │ 17.895 MB   │ disabled │
│ serv-clust │ 3  │ cluster │ 3845 │ online │         0 │ 3s     │ 17.836 MB   │ disabled │
│ echo2      │ 4  │ fork    │ 3888 │ online │         0 │ 2s     │ 12.773 MB   │ disabled │
│ echo3      │ 5  │ fork    │ 3891 │ online │         0 │ 2s     │ 12.773 MB   │ disabled │
│ echo       │ 6  │ fork    │ 3911 │ online │         0 │ 0s     │ 12.777 MB   │ disabled │
└────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app


# $pm2 logs &
# spec "Should display logs"
# TMPPID=$!

# sleep 1

# kill $!
# spec "Should kill logs"

# $pm2 logs echo &
# spec "Should display logs"
# TMPPID=$!

# sleep 1

# kill $!
# spec "Should kill logs"


$pm2 web
Launching web interface on port 9615
[PM2] Process /teste/pm2/lib/HttpInterface.js launched
[PM2] Process launched
┌────────────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name           │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust         │ 0  │ cluster │ 3828 │ online │         0 │ 4s     │ 17.688 MB   │ disabled │
│ serv-clust         │ 1  │ cluster │ 3835 │ online │         0 │ 4s     │ 15.836 MB   │ disabled │
│ serv-clust         │ 2  │ cluster │ 3842 │ online │         0 │ 3s     │ 17.895 MB   │ disabled │
│ serv-clust         │ 3  │ cluster │ 3845 │ online │         0 │ 3s     │ 17.836 MB   │ disabled │
│ echo2              │ 4  │ fork    │ 3888 │ online │         0 │ 2s     │ 12.773 MB   │ disabled │
│ echo3              │ 5  │ fork    │ 3891 │ online │         0 │ 2s     │ 12.773 MB   │ disabled │
│ echo               │ 6  │ fork    │ 3911 │ online │         0 │ 1s     │ 12.777 MB   │ disabled │
│ pm2-http-interface │ 7  │ fork    │ 3924 │ online │         0 │ 0s     │ 16.855 MB   │ disabled │
└────────────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should start web interface"
------------> ✔ Should start web interface

sleep 0.3

JSON_FILE='/tmp/web-json'

$http_get -q http://localhost:9615/ -O $JSON_FILE
cat $JSON_FILE | grep "HttpInterface.js" > /dev/null
spec "Should get the right JSON with HttpInterface file launched"
------------> ✔ Should get the right JSON with HttpInterface file launched

$pm2 flush
[PM2] Flushing /root/.pm2/pm2.log
[PM2] Flushing
[PM2] /root/.pm2/logs/serv-clust-out-0.log
[PM2] /root/.pm2/logs/serv-clust-error-0.log
[PM2] Flushing
[PM2] /root/.pm2/logs/serv-clust-out-1.log
[PM2] /root/.pm2/logs/serv-clust-error-1.log
[PM2] Flushing
[PM2] /root/.pm2/logs/serv-clust-out-2.log
[PM2] /root/.pm2/logs/serv-clust-error-2.log
[PM2] Flushing
[PM2] /root/.pm2/logs/serv-clust-out-3.log
[PM2] /root/.pm2/logs/serv-clust-error-3.log
[PM2] Flushing
[PM2] /root/.pm2/logs/echo2-out-4.log
[PM2] /root/.pm2/logs/echo2-error-4.log
[PM2] Flushing
[PM2] /root/.pm2/logs/echo3-out-5.log
[PM2] /root/.pm2/logs/echo3-error-5.log
[PM2] Flushing
[PM2] /root/.pm2/logs/echo-out-6.log
[PM2] /root/.pm2/logs/echo-error-6.log
[PM2] Flushing
[PM2] /root/.pm2/logs/pm2-http-interface-out-7.log
[PM2] /root/.pm2/logs/pm2-http-interface-error-7.log
[PM2] Logs flushed
spec "Should clean logs"
------------> ✔ Should clean logs

# cat ~/.pm2/logs/echo-out.log | wc -l
# spec "File Log should be cleaned"

sleep 0.3
$http_get -q http://localhost:9615/ -O $JSON_FILE
cat $JSON_FILE | grep "restart_time\":0" > /dev/null
spec "Should get the right JSON with HttpInterface file launched"
------------> ✔ Should get the right JSON with HttpInterface file launched

#
# Restart only one process
#
$pm2 restart 1
[PM2] restartProcessId process id 1
┌────────────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name           │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust         │ 0  │ cluster │ 3828 │ online │         0 │ 6s     │ 17.688 MB   │ disabled │
│ serv-clust         │ 1  │ cluster │ 3958 │ online │         1 │ 0s     │ 17.914 MB   │ disabled │
│ serv-clust         │ 2  │ cluster │ 3842 │ online │         0 │ 6s     │ 17.895 MB   │ disabled │
│ serv-clust         │ 3  │ cluster │ 3845 │ online │         0 │ 6s     │ 17.836 MB   │ disabled │
│ echo2              │ 4  │ fork    │ 3888 │ online │         0 │ 5s     │ 12.793 MB   │ disabled │
│ echo3              │ 5  │ fork    │ 3891 │ online │         0 │ 5s     │ 12.781 MB   │ disabled │
│ echo               │ 6  │ fork    │ 3911 │ online │         0 │ 3s     │ 12.797 MB   │ disabled │
│ pm2-http-interface │ 7  │ fork    │ 3924 │ online │         0 │ 2s     │ 19.473 MB   │ disabled │
└────────────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should has restarted process' 'restart_time: 1' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should has restarted process

#
# Restart all processes
#
$pm2 restart all
[PM2] restartProcessId process id 0
[PM2] restartProcessId process id 1
[PM2] restartProcessId process id 2
[PM2] restartProcessId process id 3
[PM2] restartProcessId process id 4
[PM2] restartProcessId process id 5
[PM2] restartProcessId process id 6
[PM2] restartProcessId process id 7
┌────────────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name           │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust         │ 0  │ cluster │ 3988 │ online │         1 │ 1s     │ 17.820 MB   │ disabled │
│ serv-clust         │ 1  │ cluster │ 3996 │ online │         2 │ 0s     │ 15.918 MB   │ disabled │
│ serv-clust         │ 2  │ cluster │ 4004 │ online │         1 │ 0s     │ 17.828 MB   │ disabled │
│ serv-clust         │ 3  │ cluster │ 4012 │ online │         1 │ 0s     │ 18.227 MB   │ disabled │
│ echo2              │ 4  │ fork    │ 4020 │ online │         1 │ 0s     │ 12.773 MB   │ disabled │
│ echo3              │ 5  │ fork    │ 4024 │ online │         1 │ 0s     │ 12.773 MB   │ disabled │
│ echo               │ 6  │ fork    │ 4028 │ online │         1 │ 0s     │ 12.773 MB   │ disabled │
│ pm2-http-interface │ 7  │ fork    │ 4032 │ online │         1 │ 0s     │ 16.984 MB   │ disabled │
└────────────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should restart all processes"
------------> ✔ Should restart all processes

sleep 1
$http_get -q http://localhost:9615/ -O $JSON_FILE
OUT=`cat $JSON_FILE | grep -o "restart_time\":1" | wc -l`
cat $JSON_FILE | grep -o "restart_time\":1" | wc -l

[ $OUT -eq 7 ] || fail "Error while wgeting data via web interface"
success "Got data from interface"
------------> ✔ Got data from interface


$pm2 list
┌────────────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name           │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust         │ 0  │ cluster │ 3988 │ online │         1 │ 2s     │ 17.820 MB   │ disabled │
│ serv-clust         │ 1  │ cluster │ 3996 │ online │         2 │ 2s     │ 15.918 MB   │ disabled │
│ serv-clust         │ 2  │ cluster │ 4004 │ online │         1 │ 2s     │ 17.828 MB   │ disabled │
│ serv-clust         │ 3  │ cluster │ 4012 │ online │         1 │ 2s     │ 18.227 MB   │ disabled │
│ echo2              │ 4  │ fork    │ 4020 │ online │         1 │ 2s     │ 12.773 MB   │ disabled │
│ echo3              │ 5  │ fork    │ 4024 │ online │         1 │ 2s     │ 12.773 MB   │ disabled │
│ echo               │ 6  │ fork    │ 4028 │ online │         1 │ 1s     │ 12.773 MB   │ disabled │
│ pm2-http-interface │ 7  │ fork    │ 4032 │ online │         1 │ 1s     │ 19.168 MB   │ disabled │
└────────────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

$pm2 dump
[PM2] Dumping processes
spec "Should dump current processes"
------------> ✔ Should dump current processes

$pm2 save
[PM2] Dumping processes
spec "Should save (dump alias) current processes"
------------> ✔ Should save (dump alias) current processes


ls ~/.pm2/dump.pm2
/root/.pm2/dump.pm2
spec "Dump file should be present"
------------> ✔ Dump file should be present

$pm2 stop all
[PM2] Stopping all
[PM2] stopProcessId process id 0
[PM2] stopProcessId process id 1
[PM2] stopProcessId process id 2
[PM2] stopProcessId process id 3
[PM2] stopProcessId process id 4
[PM2] stopProcessId process id 5
[PM2] stopProcessId process id 6
[PM2] stopProcessId process id 7
┌────────────────────┬────┬─────────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name           │ id │ mode    │ PID │ status  │ restarted │ uptime │ memory │ watching │
├────────────────────┼────┼─────────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ serv-clust         │ 0  │ cluster │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
│ serv-clust         │ 1  │ cluster │ 0   │ stopped │         2 │ 0      │ 0 B    │ disabled │
│ serv-clust         │ 2  │ cluster │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
│ serv-clust         │ 3  │ cluster │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
│ echo2              │ 4  │ fork    │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
│ echo3              │ 5  │ fork    │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
│ echo               │ 6  │ fork    │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
│ pm2-http-interface │ 7  │ fork    │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
└────────────────────┴────┴─────────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should stop all processes"
------------> ✔ Should stop all processes

sleep 0.5
OUT=`$pm2 prettylist | grep -o "stopped" | wc -l`
$pm2 prettylist | grep -o "stopped" | wc -l
[ $OUT -eq 8 ] || fail "Process not stopped"
success "Process succesfully stopped"
------------> ✔ Process succesfully stopped


$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] deleteProcessId process id 1
[PM2] deleteProcessId process id 2
[PM2] deleteProcessId process id 3
[PM2] deleteProcessId process id 4
[PM2] deleteProcessId process id 5
[PM2] deleteProcessId process id 6
[PM2] deleteProcessId process id 7
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

#
# Issue #71
#

PROC_NAME='ECHONEST'
# Launch a script with name option
$pm2 start echo.js --name $PROC_NAME -f
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process echo.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ ECHONEST │ 0  │ fork │ 4125 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
OUT=`$pm2 prettylist | grep -o "ECHONEST" | wc -l`
$pm2 prettylist | grep -o "ECHONEST" | wc -l
[ $OUT -gt 0 ] || fail "Process not launched"
success "Processes sucessfully launched with a specific name"
------------> ✔ Processes sucessfully launched with a specific name

# Restart a process by name
$pm2 restart $PROC_NAME
[PM2] restartProcessId process id 0
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ ECHONEST │ 0  │ fork │ 4140 │ online │         1 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
OUT=`$pm2 prettylist | grep -o "restart_time: 1" | wc -l`
$pm2 prettylist | grep -o "restart_time: 1" | wc -l
[ $OUT -gt 0 ] || fail "Process name not restarted"
success "Processes sucessfully restarted with a specific name"
------------> ✔ Processes sucessfully restarted with a specific name





$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

$pm2 resurrect
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Resurrecting
Process /teste/pm2/test/fixtures/server.js launched
Process /teste/pm2/test/fixtures/server.js launched
Process /teste/pm2/test/fixtures/server.js launched
Process /teste/pm2/test/fixtures/server.js launched
Process /teste/pm2/test/fixtures/echo.js launched
Process /teste/pm2/test/fixtures/echo.js launched
Process /teste/pm2/test/fixtures/echo.js launched
Process /teste/pm2/lib/HttpInterface.js launched
┌────────────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name           │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├────────────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ serv-clust         │ 0  │ cluster │ 4171 │ online │         0 │ 0s     │ 17.910 MB   │ disabled │
│ serv-clust         │ 1  │ cluster │ 4178 │ online │         0 │ 0s     │ 16.145 MB   │ disabled │
│ serv-clust         │ 2  │ cluster │ 4185 │ online │         0 │ 0s     │ 18.051 MB   │ disabled │
│ serv-clust         │ 3  │ cluster │ 4192 │ online │         0 │ 0s     │ 16.023 MB   │ disabled │
│ echo2              │ 4  │ fork    │ 4199 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ echo3              │ 5  │ fork    │ 4206 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ echo               │ 6  │ fork    │ 4209 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ pm2-http-interface │ 7  │ fork    │ 4212 │ online │         0 │ 0s     │ 17.316 MB   │ disabled │
└────────────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should resurrect all apps"
------------> ✔ Should resurrect all apps

sleep 0.5
OUT=`$pm2 prettylist | grep -o "restart_time" | wc -l`
$pm2 prettylist | grep -o "restart_time" | wc -l
[ $OUT -eq 8 ] || fail "Not valid process number"
success "Processes valid"
------------> ✔ Processes valid



$pm2 delete all
[PM2] Deleting all process
[PM2] deleteProcessId process id 0
[PM2] deleteProcessId process id 1
[PM2] deleteProcessId process id 2
[PM2] deleteProcessId process id 3
[PM2] deleteProcessId process id 4
[PM2] deleteProcessId process id 5
[PM2] deleteProcessId process id 6
[PM2] deleteProcessId process id 7
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should delete all processes"
------------> ✔ Should delete all processes

sleep 0.5
OUT=`$pm2 prettylist | grep -o "restart_time" | wc -l`
$pm2 prettylist | grep -o "restart_time" | wc -l
[ $OUT -eq 0 ] || fail "Process not stopped"
success "Process succesfully stopped"
------------> ✔ Process succesfully stopped

#
# Cron
#
$pm2 start cron.js -c "* * * asdasd"
[PM2] cron restart at * * * asdasd
[PM2] [ERROR] Cron pattern is not valid, trace: Error: Unknown alias: asd
    at /teste/pm2/node_modules/cron/lib/cron.js:237:15
    at String.replace (native)
    at Object.CronTime._parse (/teste/pm2/node_modules/cron/lib/cron.js:230:28)
    at Object.CronTime (/teste/pm2/node_modules/cron/lib/cron.js:27:10)
    at Object.CronJob (/teste/pm2/node_modules/cron/lib/cron.js:314:19)
    at Object.Common.prepareAppConf (/teste/pm2/lib/Common.js:40:22)
    at resolvePaths (/teste/pm2/lib/CLI.js:1536:20)
    at /teste/pm2/lib/CLI.js:127:28
    at /teste/pm2/node_modules/pm2-axon-rpc/lib/client.js:45:10
    at Parser.<anonymous> (/teste/pm2/node_modules/pm2-axon/lib/sockets/req.js:67:8)
Error: Cron pattern is not valid, trace: Error: Unknown alias: asd
    at /teste/pm2/node_modules/cron/lib/cron.js:237:15
    at String.replace (native)
    at Object.CronTime._parse (/teste/pm2/node_modules/cron/lib/cron.js:230:28)
    at Object.CronTime (/teste/pm2/node_modules/cron/lib/cron.js:27:10)
    at Object.CronJob (/teste/pm2/node_modules/cron/lib/cron.js:314:19)
    at Object.Common.prepareAppConf (/teste/pm2/lib/Common.js:40:22)
    at resolvePaths (/teste/pm2/lib/CLI.js:1536:20)
    at /teste/pm2/lib/CLI.js:127:28
    at /teste/pm2/node_modules/pm2-axon-rpc/lib/client.js:45:10
    at Parser.<anonymous> (/teste/pm2/node_modules/pm2-axon/lib/sockets/req.js:67:8)
    at resolvePaths (/teste/pm2/lib/CLI.js:1539:11)
    at /teste/pm2/lib/CLI.js:127:28
    at /teste/pm2/node_modules/pm2-axon-rpc/lib/client.js:45:10
    at Parser.<anonymous> (/teste/pm2/node_modules/pm2-axon/lib/sockets/req.js:67:8)
    at Parser.emit (events.js:107:17)
    at Parser._write (/teste/pm2/node_modules/pm2-axon/node_modules/amp/lib/stream.js:91:16)
    at doWrite (_stream_writable.js:265:12)
    at writeOrBuffer (_stream_writable.js:252:5)
    at Parser.Writable.write (_stream_writable.js:197:11)
    at Socket.ondata (_stream_readable.js:539:20)
ispec "Cron should throw error when pattern invalid"
------------> ✔ Cron should throw error when pattern invalid

$pm2 start cron.js -c "* * * * * *"
[PM2] cron restart at * * * * * *
[PM2] Process cron.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ cron     │ 8  │ fork │ 4291 │ online │         0 │ 0s     │ 12.258 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Should cron restart echo.js"
------------> ✔ Should cron restart echo.js


$pm2 kill test
[PM2] 
Unknown command argument: test

  Usage: pm2 [cmd] app

  Commands:

    start [options] <file|json|stdin>                          start and daemonize an app
    deploy <file|environment>                                  deploy your json
    startOrRestart <json>                                      start or restart JSON file
    startOrReload <json>                                       start or gracefully reload JSON file
    startOrGracefulReload <json>                               start or gracefully reload JSON file
    stop [options] <id|name|all|json|stdin>                    stop a process (to start it again, do pm2 restart <app>)
    restart [options] <id|name|all|json|stdin>                 restart a process
    reload <name|all>                                          reload processes (note that its for app using HTTP/HTTPS)
    gracefulReload <name|all>                                  gracefully reload a process. Send a "shutdown" message to close all connections.
    delete <name|id|script|all|json|stdin>                     stop and delete a process from pm2 process list
    sendSignal <signal> <pm2_id|name>                          send a system signal to the target process
    ping                                                       ping pm2 daemon - if not up it will launch it
    updatePM2                                                  update in-memory PM2 with local PM2
    update                                                     (alias) update in-memory PM2 with local PM2
    interact [secret_key|command] [public_key] [machine_name]  agent actions for keymetrics.io - command can be stop|info|delete|restart
    web                                                        launch an health API on port 9615
    dump                                                       dump all processes for resurrecting them later
    save                                                       (alias) dump all processes for resurrecting them later
    resurrect                                                  resurrect previously dumped processes
    startup <platform>                                         auto resurrect process at startup. [platform] = ubuntu, centos, gentoo or systemd
    generate                                                   generate an ecosystem.json configuration file
    ecosystem                                                  generate an ecosystem.json configuration file
    reset <name|id|all>                                        reset counters for process
    describe <id>                                              describe all parameters of a process id
    desc <id>                                                  (alias) describe all parameters of a process id
    info <id>                                                  (alias) describe all parameters of a process id
    show <id>                                                  (alias) describe all parameters of a process id
    list                                                       list all processes
    ls                                                         (alias) list all processes
    l                                                          (alias) list all processes
    status                                                     (alias) list all processes
    jlist                                                      list all processes in JSON format
    prettylist                                                 print json in a prettified JSON
    monit                                                      launch termcaps monitoring
    m                                                          (alias) launch termcaps monitoring
    flush                                                      flush logs
    reloadLogs                                                 reload all logs
    logs [options] [id|name]                                   stream logs file. Default stream all logs
    ilogs                                                      advanced interface to display logs
    kill                                                       kill daemon
    pull <name> [commit_id]                                    updates repository for a given app
    forward <name>                                             updates repository to the next commit for a given app
    backward <name>                                            downgrades repository to the previous commit for a given app
    *                                                          undefined

  Options:

    -h, --help                           output usage information
    -V, --version                        output the version number
    -v --version                         get version
    -s --silent                          hide all messages
    -m --mini-list                       display a compacted list without formatting
    -f --force                           force actions
    -n --name <name>                     set a <name> for script
    -i --instances <number>              launch [number] instances (for networked app)(load balanced)
    -l --log [path]                      specify entire log file (error and out are both included)
    -o --output <path>                   specify out log file
    -e --error <path>                    specify error log file
    -p --pid <pid>                       specify pid file
    --max-memory-restart <memory>        specify max memory amount used to autorestart (in megaoctets)
    --env <environment_name>             specify environment to get specific env variables (for JSON declaration)
    -x --execute-command                 execute a program using fork system
    -u --user <username>                 define user when generating startup script
    -c --cron <cron_pattern>             restart a running process based on a cron pattern
    -w --write                           write configuration in local folder
    --interpreter <interpreter>          the interpreter pm2 should use for executing app (bash, python...)
    --log-date-format <momentjs format>  add custom prefix timestamp to logs
    --no-daemon                          run pm2 daemon in the foreground if it doesn't exist alreadyispec "Should not kill with extra args"
------------> ✔ Should not kill with extra args

$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 8
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
spec "Should kill daemon"
------------> ✔ Should kill daemon
spec "CLI basic test"
------------> ✔ CLI basic test
bash ./test/bash/json_file.sh

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

# Determine wget / curl
which wget > /dev/null
if [ $? -eq 0 ]
then
    http_get="wget"
else
    echo -e "\033[31mYou need wget to run this test \033[0m";
    exit 1;
fi

function fail {
  echo -e "######## \033[31m  ✘ $1\033[0m"
  exit 1
}

function success {
  echo -e "\033[32m------------> ✔ $1\033[0m"
}

function spec {
  RET=$?
  sleep 0.3
  [ $RET -eq 0 ] || fail "$1"
  success "$1"
}

function ispec {
  RET=$?
  sleep 0.3
  [ $RET -ne 0 ] || fail "$1"
  success "$1"
}

function should {
    sleep 0.5
    OUT=`$pm2 prettylist | grep -o "$2" | wc -l`
    [ $OUT -eq $3 ] || fail "$1"
    success "$1"
}
cd $file_path

echo -e "\033[1mRunning tests for json files :\033[0m"
Running tests for json files :

$pm2 start all.json
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process launched
[PM2] Process launched
[PM2] Process launched
┌──────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork    │ 4343 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ child    │ 1  │ cluster │ 4346 │ online │         0 │ 0s     │ 15.641 MB   │ disabled │
│ child    │ 2  │ cluster │ 4349 │ online │         0 │ 0s     │ 17.691 MB   │ disabled │
│ child    │ 3  │ cluster │ 4356 │ online │         0 │ 0s     │ 17.844 MB   │ disabled │
│ child    │ 4  │ cluster │ 4363 │ online │         0 │ 0s     │ 18.156 MB   │ disabled │
│ api-2    │ 5  │ fork    │ 4370 │ online │         0 │ 0s     │ 13.574 MB   │ disabled │
└──────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should start processes' 'online' 6
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should start processes

$pm2 stop all.json
[PM2] Stopping all.json
[PM2] Process 0 restarted
[PM2] Process 1 restarted
[PM2] Process 2 restarted
[PM2] Process 3 restarted
[PM2] Process 4 restarted
[PM2] Process 5 restarted
┌──────────┬────┬─────────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode    │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼─────────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ echo     │ 0  │ fork    │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ child    │ 1  │ cluster │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ child    │ 2  │ cluster │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ child    │ 3  │ cluster │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ child    │ 4  │ cluster │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
│ api-2    │ 5  │ fork    │ 0   │ stopped │         0 │ 0      │ 0 B    │ disabled │
└──────────┴────┴─────────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should stop processes' 'stopped' 6
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should stop processes

$pm2 delete all.json
[PM2] Deleting all.json process
[PM2] Process 0 restarted
[PM2] Process 1 restarted
[PM2] Process 2 restarted
[PM2] Process 3 restarted
[PM2] Process 4 restarted
[PM2] Process 5 restarted
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should start processes' 'online' 0
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should start processes

$pm2 start all.json
[PM2] Process launched
[PM2] Process launched
[PM2] Process launched
┌──────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 6  │ fork    │ 4452 │ online │         0 │ 0s     │ 12.773 MB   │ disabled │
│ child    │ 7  │ cluster │ 4455 │ online │         0 │ 0s     │ 15.836 MB   │ disabled │
│ child    │ 8  │ cluster │ 4458 │ online │         0 │ 0s     │ 17.664 MB   │ disabled │
│ child    │ 9  │ cluster │ 4461 │ online │         0 │ 0s     │ 15.621 MB   │ disabled │
│ child    │ 10 │ cluster │ 4472 │ online │         0 │ 0s     │ 17.645 MB   │ disabled │
│ api-2    │ 11 │ fork    │ 4479 │ online │         0 │ 0s     │ 13.574 MB   │ disabled │
└──────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should start processes' 'online' 6
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should start processes

$pm2 restart all.json
[PM2] Process 6 restarted
[PM2] Process 7 restarted
[PM2] Process 8 restarted
[PM2] Process 9 restarted
[PM2] Process 10 restarted
[PM2] Process 11 restarted
┌──────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 6  │ fork    │ 4508 │ online │         1 │ 1s     │ 12.773 MB   │ disabled │
│ child    │ 7  │ cluster │ 4513 │ online │         1 │ 0s     │ 15.898 MB   │ disabled │
│ child    │ 8  │ cluster │ 4521 │ online │         1 │ 0s     │ 16.027 MB   │ disabled │
│ child    │ 9  │ cluster │ 4529 │ online │         1 │ 0s     │ 17.902 MB   │ disabled │
│ child    │ 10 │ cluster │ 4537 │ online │         1 │ 0s     │ 15.871 MB   │ disabled │
│ api-2    │ 11 │ fork    │ 4545 │ online │         1 │ 0s     │ 13.574 MB   │ disabled │
└──────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should stop processes' 'online' 6
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should stop processes
should 'should all script been restarted one time' 'restart_time: 1' 6
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should all script been restarted one time

$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 6
[PM2] deleteProcessId process id 7
[PM2] deleteProcessId process id 8
[PM2] deleteProcessId process id 9
[PM2] deleteProcessId process id 10
[PM2] deleteProcessId process id 11
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

sleep 2

#
# CWD OPTION
#

#$pm2 kill

#$pm2 start change_cwd.json
#sleep 1
#should 'should start 2 processes' 'online' 2

#$pm2 delete all

#$pm2 start no_cwd_change.json
#sleep 1
#should 'should not start 2 processes because of paths' 'online' 0
spec "JSON file test"
------------> ✔ JSON file test
bash ./test/bash/watch.sh

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

# Determine wget / curl
which wget > /dev/null
if [ $? -eq 0 ]
then
    http_get="wget"
else
    echo -e "\033[31mYou need wget to run this test \033[0m";
    exit 1;
fi

function fail {
  echo -e "######## \033[31m  ✘ $1\033[0m"
  exit 1
}

function success {
  echo -e "\033[32m------------> ✔ $1\033[0m"
}

function spec {
  RET=$?
  sleep 0.3
  [ $RET -eq 0 ] || fail "$1"
  success "$1"
}

function ispec {
  RET=$?
  sleep 0.3
  [ $RET -ne 0 ] || fail "$1"
  success "$1"
}

function should {
    sleep 0.5
    OUT=`$pm2 prettylist | grep -o "$2" | wc -l`
    [ $OUT -eq $3 ] || fail "$1"
    success "$1"
}

cd $file_path

function waituntil {
  for (( i = 0; i <= $1; i++ )); do
      sleep 0.2
      echo -n "."
  done
  echo ""
}

echo -e "\033[1mRunning tests:\033[0m"
Running tests:

#####################
# Watch for changes #
#####################

>server-watch.js

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

cp server-watch.bak.js server-watch.js

$pm2 start server-watch.js --watch
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process server-watch.js launched
┌──────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0  │ fork │ 4646 │ online │         0 │ 0s     │ 13.566 MB   │  enabled │
└──────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'process should be watched' 'watch: true' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should be watched

echo "console.log('test');" >> server-watch.js

sleep 1

cat server-watch.js
var http = require('http');

http.createServer(function(req, res) {
  res.writeHead(200);
  res.end('hey');
}).listen(8000);
console.log('test');
$pm2 list
┌──────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0  │ fork │ 4660 │ online │         1 │ 1s     │ 13.824 MB   │  enabled │
└──────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'process should have been restarted' 'restart_time: 1' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should have been restarted
should 'process should be online' "status: 'online'" 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should be online

$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

sleep 1

rm server-watch.js

###############

# Script should fail but be started again on next change
# Sadly travis has an issue with that test, it's working and tested with node v0.11.10
# Feel free to uncomment and report to http://github.com/Unitech/pm2/issues

# cp server-watch.bak.js server-watch.js

# $pm2 start --watch server-watch.js

# echo "setTimeout(function() { process.exit(0) }, 1)" > server-watch.js

# for (( i = 0; i <= 30; i++ )); do
#     sleep 0.2
#     echo -n "."
# done

# $pm2 list
# should 'should have stopped unstable process' 'errored' 1

# cp server-watch.bak.js server-watch.js

# for (( i = 0; i <= 10; i++ )); do
#     sleep 0.2
#     echo -n "."
# done

# $pm2 list
# should 'should start the errored process again while putting file back' 'online' 1

# $pm2 kill
# rm server-watch.js

###############

cp server-watch.bak.js server-watch.js

$pm2 start --watch server-watch.js
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process server-watch.js launched
┌──────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0  │ fork │ 4722 │ online │         0 │ 0s     │ 13.566 MB   │  enabled │
└──────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

$pm2 restart 0
[PM2] restartProcessId process id 0
┌──────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0  │ fork │ 4731 │ online │         1 │ 0s     │ 13.570 MB   │  enabled │
└──────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'process should be watched' 'watch: true' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should be watched

$pm2 stop --watch 0
[PM2] Stopping 0
[PM2] stopProcessId process id 0
┌──────────────┬────┬──────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name     │ id │ mode │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────────┼────┼──────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ server-watch │ 0  │ fork │ 0   │ stopped │         1 │ 0      │ 0 B    │ disabled │
└──────────────┴────┴──────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'process should have stopped beeing watched' 'watch: false' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should have stopped beeing watched

echo "setInterval(function() { console.log('still ok'); }, 100);" > server-watch.js

should 'process should not have been restarted on file change' 'restart_time: 1' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should not have been restarted on file change

cp server-watch.bak.js server-watch.js

$pm2 restart 0
[PM2] restartProcessId process id 0
┌──────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0  │ fork │ 4784 │ online │         1 │ 0s     │ 13.566 MB   │ disabled │
└──────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'process should restart and not be watched' 'watch: false' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should restart and not be watched

#$pm2 restart --watch 0
#should 'process should be watched' 'watch: true' 1

$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

rm server-watch.js
#############
# JSON test #
#############
# we've already seen before that "watch: true" is really watching when changing a file

# $pm2 start --watch all.json

# should 'processes should be watched' 'watch: true' 8

# $pm2 stop --watch all

# should 'processes should have stop being watched' 'watch: false' 8

# $pm2 restart --watch all
# should 'processes should be watched' 'watch: true' 8

# $pm2 kill

##########
# delete #
##########

cp server-watch.bak.js server-watch.js

$pm2 start server-watch.js --watch
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process server-watch.js launched
┌──────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0  │ fork │ 4813 │ online │         0 │ 0s     │ 13.566 MB   │  enabled │
└──────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
$pm2 stop 0
[PM2] Stopping 0
[PM2] stopProcessId process id 0
┌──────────────┬────┬──────┬─────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name     │ id │ mode │ PID │ status  │ restarted │ uptime │ memory │ watching │
├──────────────┼────┼──────┼─────┼─────────┼───────────┼────────┼────────┼──────────┤
│ server-watch │ 0  │ fork │ 0   │ stopped │         0 │ 0      │ 0 B    │  enabled │
└──────────────┴────┴──────┴─────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
$pm2 delete 0
[PM2] Deleting 0 process
[PM2] deleteProcessId process id 0
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

echo "setTimeout(function() { console.log('watch me!') })" >> server-watch.js

waituntil 10
...........

should 'process should not have been restarted' 'watch: true' 0
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should not have been restarted

$pm2 delete all
[PM2] Deleting all process
[PM2] [WARN] No process found
rm server-watch.js

###########
# cluster #
###########

cp server-watch.bak.js server-watch.js

$pm2 start server-watch.js --watch -i 4
[PM2] Process server-watch.js launched
┌──────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 1  │ cluster │ 4875 │ online │         0 │ 0s     │ 17.906 MB   │  enabled │
│ server-watch │ 2  │ cluster │ 4878 │ online │         0 │ 0s     │ 17.961 MB   │  enabled │
│ server-watch │ 3  │ cluster │ 4885 │ online │         0 │ 0s     │ 19.902 MB   │  enabled │
│ server-watch │ 4  │ cluster │ 4892 │ online │         0 │ 0s     │ 17.840 MB   │  enabled │
└──────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'processes should be watched' 'watch: true' 4
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ processes should be watched

##############
# connection #
##############

wget -qO- http://localhost:8000 > /dev/null

spec "Got connection"
------------> ✔ Got connection

echo "console.log('test');" >> server-watch.js

sleep 2

should 'process should have been restarted' 'restart_time: 1' 4
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should have been restarted

$pm2 list
┌──────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 1  │ cluster │ 4926 │ online │         1 │ 2s     │ 16.043 MB   │  enabled │
│ server-watch │ 2  │ cluster │ 4934 │ online │         1 │ 2s     │ 17.895 MB   │  enabled │
│ server-watch │ 3  │ cluster │ 4942 │ online │         1 │ 2s     │ 18.039 MB   │  enabled │
│ server-watch │ 4  │ cluster │ 4950 │ online │         1 │ 2s     │ 18.102 MB   │  enabled │
└──────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

wget -qO- http://localhost:8000 > /dev/null
spec "Got connection"
------------> ✔ Got connection

#######################
# make sure isolation #
#######################

$pm2 start server-watch.js -i 4 --name "server-2" -f
[PM2] Process server-watch.js launched
┌──────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 1  │ cluster │ 4926 │ online │         1 │ 3s     │ 16.434 MB   │  enabled │
│ server-watch │ 2  │ cluster │ 4934 │ online │         1 │ 3s     │ 17.895 MB   │  enabled │
│ server-watch │ 3  │ cluster │ 4942 │ online │         1 │ 3s     │ 18.039 MB   │  enabled │
│ server-watch │ 4  │ cluster │ 4950 │ online │         1 │ 3s     │ 18.102 MB   │  enabled │
│ server-2     │ 5  │ cluster │ 4984 │ online │         0 │ 0s     │ 17.613 MB   │ disabled │
│ server-2     │ 6  │ cluster │ 4987 │ online │         0 │ 0s     │ 15.594 MB   │ disabled │
│ server-2     │ 7  │ cluster │ 4994 │ online │         0 │ 0s     │ 15.645 MB   │ disabled │
│ server-2     │ 8  │ cluster │ 5001 │ online │         0 │ 0s     │ 17.719 MB   │ disabled │
└──────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

$pm2 list
┌──────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 1  │ cluster │ 4926 │ online │         1 │ 4s     │ 16.434 MB   │  enabled │
│ server-watch │ 2  │ cluster │ 4934 │ online │         1 │ 4s     │ 17.895 MB   │  enabled │
│ server-watch │ 3  │ cluster │ 4942 │ online │         1 │ 4s     │ 18.039 MB   │  enabled │
│ server-watch │ 4  │ cluster │ 4950 │ online │         1 │ 3s     │ 18.102 MB   │  enabled │
│ server-2     │ 5  │ cluster │ 4984 │ online │         0 │ 0s     │ 17.613 MB   │ disabled │
│ server-2     │ 6  │ cluster │ 4987 │ online │         0 │ 0s     │ 15.594 MB   │ disabled │
│ server-2     │ 7  │ cluster │ 4994 │ online │         0 │ 0s     │ 15.645 MB   │ disabled │
│ server-2     │ 8  │ cluster │ 5001 │ online │         0 │ 0s     │ 17.719 MB   │ disabled │
└──────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

echo "console.log('test');" >> server-watch.js

sleep 2
should 'right processes should have been restarted' 'restart_time: 2' 4
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ right processes should have been restarted

$pm2 restart "server-2"
[PM2] restartProcessId process id 5
[PM2] restartProcessId process id 6
[PM2] restartProcessId process id 7
[PM2] restartProcessId process id 8
┌──────────────┬────┬─────────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name     │ id │ mode    │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────────┼────┼─────────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 1  │ cluster │ 5030 │ online │         2 │ 3s     │ 18.121 MB   │  enabled │
│ server-watch │ 2  │ cluster │ 5038 │ online │         2 │ 3s     │ 17.984 MB   │  enabled │
│ server-watch │ 3  │ cluster │ 5046 │ online │         2 │ 3s     │ 16.090 MB   │  enabled │
│ server-watch │ 4  │ cluster │ 5054 │ online │         2 │ 3s     │ 18.094 MB   │  enabled │
│ server-2     │ 5  │ cluster │ 5085 │ online │         1 │ 0s     │ 16.121 MB   │ disabled │
│ server-2     │ 6  │ cluster │ 5093 │ online │         1 │ 0s     │ 18.004 MB   │ disabled │
│ server-2     │ 7  │ cluster │ 5101 │ online │         1 │ 0s     │ 15.918 MB   │ disabled │
│ server-2     │ 8  │ cluster │ 5109 │ online │         1 │ 0s     │ 16.102 MB   │ disabled │
└──────────────┴────┴─────────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

should 'right processes should have been restarted' 'restart_time: 1' 4
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ right processes should have been restarted
rm server-watch.js
spec "Watch feature"
------------> ✔ Watch feature
bash ./test/bash/harmony.sh

$pm2 kill
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 1
[PM2] deleteProcessId process id 2
[PM2] deleteProcessId process id 3
[PM2] deleteProcessId process id 4
[PM2] deleteProcessId process id 5
[PM2] deleteProcessId process id 6
[PM2] deleteProcessId process id 7
[PM2] deleteProcessId process id 8
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

# Determine wget / curl
which wget > /dev/null
if [ $? -eq 0 ]
then
    http_get="wget"
else
    echo -e "\033[31mYou need wget to run this test \033[0m";
    exit 1;
fi

function fail {
  echo -e "######## \033[31m  ✘ $1\033[0m"
  exit 1
}

function success {
  echo -e "\033[32m------------> ✔ $1\033[0m"
}

function spec {
  RET=$?
  sleep 0.3
  [ $RET -eq 0 ] || fail "$1"
  success "$1"
}

function ispec {
  RET=$?
  sleep 0.3
  [ $RET -ne 0 ] || fail "$1"
  success "$1"
}

function should {
    sleep 0.5
    OUT=`$pm2 prettylist | grep -o "$2" | wc -l`
    [ $OUT -eq $3 ] || fail "$1"
    success "$1"
}

cd $file_path
$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

echo "################ HARMONY ES6"
################ HARMONY ES6

$pm2 start harmony.js
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process harmony.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │     memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼────────────┼──────────┤
│ harmony  │ 0  │ fork │ 5258 │ online │         2 │ 0s     │ 9.980 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
sleep 2
$pm2 list
┌──────────┬────┬──────┬──────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID  │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼──────┼─────────┼───────────┼────────┼────────┼──────────┤
│ harmony  │ 0  │ fork │ 5297 │ errored │        15 │ 0      │ 0 B    │ disabled │
└──────────┴────┴──────┴──────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should FAIL when not passing harmony option to V8' 'restart_time: 0' 0
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should FAIL when not passing harmony option to V8
$pm2 list
┌──────────┬────┬──────┬──────┬─────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID  │ status  │ restarted │ uptime │ memory │ watching │
├──────────┼────┼──────┼──────┼─────────┼───────────┼────────┼────────┼──────────┤
│ harmony  │ 0  │ fork │ 5297 │ errored │        15 │ 0      │ 0 B    │ disabled │
└──────────┴────┴──────┴──────┴─────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
$pm2 delete all
[PM2] Deleting all process
[PM2] deleteProcessId process id 0
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

$pm2 start harmony.js --node-args="--harmony"
[PM2] Process harmony.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ harmony  │ 1  │ fork │ 5344 │ online │         0 │ 0s     │ 13.227 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
sleep 2
$pm2 list
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ harmony  │ 1  │ fork │ 5344 │ online │         0 │ 2s     │ 13.484 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should not fail when passing node-args=harmony opts in CLUSTERMODE' 'restart_time: 0' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should not fail when passing node-args=harmony opts in CLUSTERMODE
$pm2 delete all
[PM2] Deleting all process
[PM2] deleteProcessId process id 1
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

echo "################ HARMONY / NODEARGS ES6 FORK MODE"
################ HARMONY / NODEARGS ES6 FORK MODE

$pm2 start harmony.js --node-args="--harmony" -x
[PM2] Process harmony.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ harmony  │ 2  │ fork │ 5377 │ online │         0 │ 0s     │ 13.230 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
sleep 2
$pm2 list
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ harmony  │ 2  │ fork │ 5377 │ online │         0 │ 2s     │ 13.488 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should not fail when passing node-args=harmony opts in FORKMODE' 'restart_time: 0' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should not fail when passing node-args=harmony opts in FORKMODE
$pm2 delete all
[PM2] Deleting all process
[PM2] deleteProcessId process id 2
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

echo "################## NODE ARGS VIA JSON"
################## NODE ARGS VIA JSON

$pm2 start harmony.json
[PM2] Process launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ ES6      │ 3  │ fork │ 5422 │ online │         0 │ 0s     │ 13.230 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
sleep 2
$pm2 list
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ ES6      │ 3  │ fork │ 5422 │ online │         0 │ 2s     │ 13.488 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
should 'should not fail when passing harmony option to V8 via node_args in JSON files' 'restart_time: 0' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ should not fail when passing harmony option to V8 via node_args in JSON files

$pm2 delete all
[PM2] Deleting all process
[PM2] deleteProcessId process id 3
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app
spec "Harmony test"
------------> ✔ Harmony test
bash ./test/bash/log-custom.sh

$pm2 kill
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped

# Determine wget / curl
which wget > /dev/null
if [ $? -eq 0 ]
then
    http_get="wget"
else
    echo -e "\033[31mYou need wget to run this test \033[0m";
    exit 1;
fi

function fail {
  echo -e "######## \033[31m  ✘ $1\033[0m"
  exit 1
}

function success {
  echo -e "\033[32m------------> ✔ $1\033[0m"
}

function spec {
  RET=$?
  sleep 0.3
  [ $RET -eq 0 ] || fail "$1"
  success "$1"
}

function ispec {
  RET=$?
  sleep 0.3
  [ $RET -ne 0 ] || fail "$1"
  success "$1"
}

function should {
    sleep 0.5
    OUT=`$pm2 prettylist | grep -o "$2" | wc -l`
    [ $OUT -eq $3 ] || fail "$1"
    success "$1"
}

cd $file_path

$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped


# CLUSTERMODE YYYY
$pm2 start echo.js --log-date-format "YYYY" -o out-rel.log --merge-logs
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process echo.js launched
┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │ watching │
├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ echo     │ 0  │ fork │ 5494 │ online │         0 │ 0s     │ 12.262 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
 Use `pm2 info <id|name>` to get more details about an app

>out-rel.log

sleep 2

grep "2014" out-rel.log
spec "Should have written year in log file according to format YYYY"
########   ✘ Should have written year in log file according to format YYYY
npm ERR! Test failed.  See above for more details.

@soyuka
Copy link
Collaborator

soyuka commented Jan 5, 2015

#913

@soyuka soyuka reopened this Jan 5, 2015
@Tjatse Tjatse closed this as completed Jan 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants