@@ -30,7 +30,10 @@ public function allocate_ports( $nodeapp_folder ) {
3030 }
3131
3232 // 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+ }
3437 $ files = $ this ->get_config_files ( $ nodeapp_folder );
3538 foreach ($ files as $ file ) {
3639
@@ -82,10 +85,11 @@ public function __construct() {
8285 * using the specified major version of NodeJS and invoke the given callback.
8386 * Lastly, after the callback has returned, the apps will be restarted.
8487 *
85- * @param array $majors The list of major versions to perform maintenance on; leave empty to shutdown all running apps.
8688 * @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.
8791 */
88- public function do_maintenance ( $ majors = [], $ cb_maintenance = null ) {
92+ public function do_maintenance ( $ cb_maintenance = null , $ majors = [], $ apps = [] ) {
8993
9094 // Check if majors array is empty and get all majors as default
9195 global $ hcpp ;
@@ -100,7 +104,6 @@ public function do_maintenance( $majors = [], $cb_maintenance = null ) {
100104 }
101105
102106 // Get user list of PM2 (bash) capable users
103- global $ hcpp ;
104107 $ all = $ hcpp ->run ( 'v-list-users json ' );
105108 $ users = [];
106109 foreach ( $ all as $ user => $ details ) {
@@ -121,12 +124,20 @@ public function do_maintenance( $majors = [], $cb_maintenance = null ) {
121124 $ version = $ hcpp ->getLeftMost ( $ version , '/ ' );
122125 $ major = $ hcpp ->getLeftMost ( $ version , '. ' );
123126 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+ }
125137 }
126138 }
127139 }
128140 }
129- $ pm2_list = $ hcpp ->do_action ( 'nodeapp_maintenance_start ' , $ pm2_list );
130141
131142 // Shutdown all apps by id for each user
132143 foreach ( $ pm2_list as $ user => $ app_ids ) {
@@ -146,7 +157,6 @@ public function do_maintenance( $majors = [], $cb_maintenance = null ) {
146157 $ this ->restart_pm2_ids ( $ app_ids , $ user );
147158 }
148159 }
149- $ pm2_list = $ hcpp ->do_action ( 'nodeapp_maintenance_end ' , $ pm2_list );
150160 }
151161
152162 /**
@@ -796,7 +806,7 @@ public function update_all() {
796806 }
797807
798808 // Perform the maintenance tasks
799- $ this ->do_maintenance ( $ majors , function ( $ stopped ) use ( $ hcpp , $ updates ) {
809+ $ this ->do_maintenance ( function ( $ stopped ) use ( $ hcpp , $ updates ) {
800810 // Update NodeJS, npm, and re-install global packages
801811 foreach ( $ updates as $ v ) {
802812 $ cmd = 'nvm install ' . $ v ['latest ' ] . ' && nvm use ' . $ v ['latest ' ] . ' && npm install -g npm ' ;
@@ -805,7 +815,7 @@ public function update_all() {
805815 $ cmd = $ hcpp ->do_action ( 'nodeapp_update_nodejs ' , $ cmd );
806816 $ hcpp ->runuser ( '' , $ cmd );
807817 }
808- });
818+ }, $ majors );
809819 }
810820
811821 /**
@@ -913,7 +923,7 @@ public function v_unsuspend_domain( $args ) {
913923 */
914924 public function v_update_sys_queue ( $ args ) {
915925 global $ hcpp ;
916- if ( ! (isset ( $ args [0 ] ) && $ args [0 ] == 'daily ' ) ) return $ args ;
926+ if ( ! (isset ( $ args [0 ] ) && trim ( $ args [0 ] ) == 'daily ' ) ) return $ args ;
917927 if ( strpos ( $ hcpp ->run ('v-list-sys-hestia-autoupdate ' ), 'Enabled ' ) == false ) return $ args ;
918928 $ this ->update_all ();
919929 return $ args ;
0 commit comments