@@ -30,7 +30,10 @@ public function allocate_ports( $nodeapp_folder ) {
30
30
}
31
31
32
32
// Allocate a port for each .config.js file found
33
- if ( ! is_dir ( $ nodeapp_folder ) ) return ;
33
+ if ( ! is_dir ( $ nodeapp_folder ) ) {
34
+ $ hcpp ->log ( "allocate_ports: $ nodeapp_folder is not a directory " );
35
+ return ;
36
+ }
34
37
$ files = $ this ->get_config_files ( $ nodeapp_folder );
35
38
foreach ($ files as $ file ) {
36
39
@@ -82,10 +85,11 @@ public function __construct() {
82
85
* using the specified major version of NodeJS and invoke the given callback.
83
86
* Lastly, after the callback has returned, the apps will be restarted.
84
87
*
85
- * @param array $majors The list of major versions to perform maintenance on; leave empty to shutdown all running apps.
86
88
* @param callable $cb_maintenance The callback to invoke after all apps have been shutdown, a [user=>apps] array will be passed of stopped apps.
89
+ * @param array $majors The list of major nodejs versions to perform maintenance on; leave empty to shutdown apps from all versions.
90
+ * @param array $apps The list of apps to perform maintenance on; leave empty to shutdown all apps.
87
91
*/
88
- public function do_maintenance ( $ majors = [], $ cb_maintenance = null ) {
92
+ public function do_maintenance ( $ cb_maintenance = null , $ majors = [], $ apps = [] ) {
89
93
90
94
// Check if majors array is empty and get all majors as default
91
95
global $ hcpp ;
@@ -100,7 +104,6 @@ public function do_maintenance( $majors = [], $cb_maintenance = null ) {
100
104
}
101
105
102
106
// Get user list of PM2 (bash) capable users
103
- global $ hcpp ;
104
107
$ all = $ hcpp ->run ( 'v-list-users json ' );
105
108
$ users = [];
106
109
foreach ( $ all as $ user => $ details ) {
@@ -121,12 +124,20 @@ public function do_maintenance( $majors = [], $cb_maintenance = null ) {
121
124
$ version = $ hcpp ->getLeftMost ( $ version , '/ ' );
122
125
$ major = $ hcpp ->getLeftMost ( $ version , '. ' );
123
126
if ( in_array ( $ major , $ majors ) ) {
124
- $ pm2_list [$ user ][] = $ p ['pm_id ' ];
127
+ if ( count ( $ apps ) == 0 ) {
128
+ $ pm2_list [$ user ][] = $ p ['pm_id ' ];
129
+ }else {
130
+
131
+ // Filter by app name i.e. 'ghost' in 'ghost | test1.dev.pw'
132
+ $ name = $ hcpp ->getLeftMost ( $ p ['name ' ], ' | ' );
133
+ if ( in_array ( $ name , $ apps ) ) {
134
+ $ pm2_list [$ user ][] = $ p ['pm_id ' ];
135
+ }
136
+ }
125
137
}
126
138
}
127
139
}
128
140
}
129
- $ pm2_list = $ hcpp ->do_action ( 'nodeapp_maintenance_start ' , $ pm2_list );
130
141
131
142
// Shutdown all apps by id for each user
132
143
foreach ( $ pm2_list as $ user => $ app_ids ) {
@@ -146,7 +157,6 @@ public function do_maintenance( $majors = [], $cb_maintenance = null ) {
146
157
$ this ->restart_pm2_ids ( $ app_ids , $ user );
147
158
}
148
159
}
149
- $ pm2_list = $ hcpp ->do_action ( 'nodeapp_maintenance_end ' , $ pm2_list );
150
160
}
151
161
152
162
/**
@@ -796,7 +806,7 @@ public function update_all() {
796
806
}
797
807
798
808
// Perform the maintenance tasks
799
- $ this ->do_maintenance ( $ majors , function ( $ stopped ) use ( $ hcpp , $ updates ) {
809
+ $ this ->do_maintenance ( function ( $ stopped ) use ( $ hcpp , $ updates ) {
800
810
// Update NodeJS, npm, and re-install global packages
801
811
foreach ( $ updates as $ v ) {
802
812
$ cmd = 'nvm install ' . $ v ['latest ' ] . ' && nvm use ' . $ v ['latest ' ] . ' && npm install -g npm ' ;
@@ -805,7 +815,7 @@ public function update_all() {
805
815
$ cmd = $ hcpp ->do_action ( 'nodeapp_update_nodejs ' , $ cmd );
806
816
$ hcpp ->runuser ( '' , $ cmd );
807
817
}
808
- });
818
+ }, $ majors );
809
819
}
810
820
811
821
/**
@@ -913,7 +923,7 @@ public function v_unsuspend_domain( $args ) {
913
923
*/
914
924
public function v_update_sys_queue ( $ args ) {
915
925
global $ hcpp ;
916
- if ( ! (isset ( $ args [0 ] ) && $ args [0 ] == 'daily ' ) ) return $ args ;
926
+ if ( ! (isset ( $ args [0 ] ) && trim ( $ args [0 ] ) == 'daily ' ) ) return $ args ;
917
927
if ( strpos ( $ hcpp ->run ('v-list-sys-hestia-autoupdate ' ), 'Enabled ' ) == false ) return $ args ;
918
928
$ this ->update_all ();
919
929
return $ args ;
0 commit comments