Skip to content

Commit cdb492e

Browse files
committed
wip
1 parent a60b9ab commit cdb492e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

nodeapp.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public function __construct() {
2626
$hcpp->add_action( 'priv_suspend_web_domain', [ $this, 'priv_suspend_web_domain' ] );
2727
$hcpp->add_action( 'priv_unsuspend_domain', [ $this, 'priv_unsuspend_domain' ] );
2828
$hcpp->add_action( 'priv_update_sys_queue', [ $this, 'priv_update_sys_queue' ] );
29+
$hcpp->add_action( 'hcpp_runuser', [ $this, 'hcpp_runuser' ] );
30+
}
31+
32+
/**
33+
* Modify runuser to incorporate NVM
34+
*/
35+
public function hcpp_runuser( $cmd ) {
36+
$cmd = 'export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh && ' . $cmd;
37+
return $cmd;
2938
}
3039

3140
/**
@@ -55,7 +64,7 @@ public function priv_update_sys_queue( $args ) {
5564

5665
// Restart any pm2 processes
5766
$cmd .= 'runuser -s /bin/bash -l ' . $user . ' -c "cd /home/' . $user . ' && ';
58-
$cmd .= 'source /opt/nvm/nvm.sh && pm2 resurrect"' . "\n";
67+
$cmd .= 'export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh && pm2 resurrect"' . "\n";
5968
}
6069
}
6170
shell_exec( $hcpp->do_action( 'nodeapp_resurrect_apps', $cmd ) );
@@ -95,7 +104,7 @@ public function priv_change_web_domain_proxy_tpl( $args ) {
95104
$nodeapp_folder = $args['nodeapp_folder'];
96105

97106
// Install dependencies
98-
$cmd = 'runuser -s /bin/bash -l ' . $user . ' -c "cd \"' . $nodeapp_folder . '\" && source /opt/nvm/nvm.sh && npm install"';
107+
$cmd = 'runuser -s /bin/bash -l ' . $user . ' -c "cd \"' . $nodeapp_folder . '\" && export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh && npm install"';
99108
$args['cmd'] = $cmd;
100109
$args = $hcpp->do_action( 'nodeapp_install_dependencies', $args );
101110
shell_exec( $args['cmd'] );
@@ -300,7 +309,7 @@ public function startup_apps( $nodeapp_folder, $inc_root = true ) {
300309
$user = $parse[2];
301310
$domain = $parse[4];
302311
$files = $this->get_config_files( $nodeapp_folder );
303-
$cmd = 'runuser -s /bin/bash -l ' . $user . ' -c "cd \"' . $nodeapp_folder . '\" && source /opt/nvm/nvm.sh ';
312+
$cmd = 'runuser -s /bin/bash -l ' . $user . ' -c "cd \"' . $nodeapp_folder . '\" && export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh ';
304313
foreach($files as $file) {
305314

306315
// Skip the root app if inc_root is false
@@ -340,10 +349,10 @@ public function shutdown_apps( $nodeapp_folder ) {
340349
$domain = $parse[4];
341350

342351
// Get list of apps to delete
343-
$cmd = 'runuser -s /bin/bash -l ' . $user . ' -c "source /opt/nvm/nvm.sh ; pm2 ls | grep ' . $domain . '"';
352+
$cmd = 'runuser -s /bin/bash -l ' . $user . ' -c "export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh ; pm2 ls | grep ' . $domain . '"';
344353
$lines = shell_exec( $cmd );
345354
$lines = explode( "\n", $lines );
346-
$cmd = 'runuser -s /bin/bash -l ' . $user . ' -c "cd \"' . $nodeapp_folder . '\" && source /opt/nvm/nvm.sh ';
355+
$cmd = 'runuser -s /bin/bash -l ' . $user . ' -c "cd \"' . $nodeapp_folder . '\" && export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh ';
347356
foreach( $lines as $l ) {
348357
if ( strpos( $l, '-' . $domain ) === false ) continue;
349358
$app = $hcpp->getRightMost( $hcpp->getLeftMost( $l, '-' ), ' ' );

0 commit comments

Comments
 (0)