├── .gitignore ├── README.md ├── package.json └── app.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | *.log 4 | *.pid 5 | test/child 6 | *.iml 7 | .idea/** 8 | package-lock.json 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Deprecated with PM2 <= 3.2** 2 | 3 | # pm2-auto-pull 4 | 5 | Synchronize all applications managed by PM2 + GIT automatically. 6 | 7 | ``` 8 | # Install 9 | 10 | $ pm2 install pm2-auto-pull 11 | 12 | ## Uninstall 13 | 14 | $ pm2 uninstall pm2-auto-pull 15 | 16 | ## Configure auto pull interval 17 | 18 | $ pm2 set pm2-auto-pull:interval 60000 19 | ``` 20 | 21 | # License 22 | 23 | MIT 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pm2-auto-pull", 3 | "version": "2.0.1", 4 | "description": "PM2 module to auto pull applications when there is an update", 5 | "main": "app", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "dependencies": { 10 | "pmx": "latest", 11 | "pm2": "2.x", 12 | "async": "*", 13 | "debug": "*" 14 | }, 15 | "apps": [ 16 | { 17 | "script": "app.js", 18 | "log_date_format": "YYYY-MM-DD HH:mm:ss Z", 19 | "merge_logs": true 20 | } 21 | ], 22 | "author": "Keymetrics", 23 | "license": "ISC" 24 | } 25 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('pmx'); 3 | var pm2 = require('pm2'); 4 | var async = require('async'); 5 | var pkg = require('./package.json'); 6 | 7 | var Probe = pmx.probe(); 8 | 9 | var app_updated = Probe.counter({ 10 | name : 'Updates' 11 | }); 12 | 13 | function autoPull(cb) { 14 | pm2.list(function(err, procs) { 15 | if (err) return console.error(err); 16 | 17 | async.forEachLimit(procs, 1, function(proc, next) { 18 | if (proc.pm2_env && proc.pm2_env.versioning) { 19 | pm2.pullAndReload(proc.name, function(err, meta) { 20 | if (meta) { 21 | app_updated.inc(); 22 | 23 | console.log('>>>>>>>>>>>>> Successfully pulled Application! [App name: %s]', proc.name) 24 | } 25 | if (err) 26 | console.log('App %s already at latest version', proc.name); 27 | return next(); 28 | }); 29 | } 30 | else next(); 31 | }, cb); 32 | 33 | }); 34 | } 35 | 36 | pmx.initModule({ 37 | widget : { 38 | type : 'generic', 39 | theme : ['#111111', '#1B2228', '#807C7C', '#807C7C'], 40 | 41 | el : { 42 | probes : true, 43 | actions : true 44 | }, 45 | 46 | block : { 47 | actions : true, 48 | issues : true, 49 | meta : true, 50 | cpu: true, 51 | mem: true 52 | } 53 | 54 | // Status 55 | // Green / Yellow / Red 56 | } 57 | }, function(err, conf) { 58 | pm2.connect(function() { 59 | console.log('pm2-auto-pull module connected to pm2'); 60 | 61 | var running = false; 62 | 63 | setInterval(function() { 64 | if (running == true) return false; 65 | 66 | running = true; 67 | autoPull(function() { 68 | running = false; 69 | }); 70 | }, conf.interval || 30000); 71 | 72 | }); 73 | }); 74 | --------------------------------------------------------------------------------