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

basic NodeJS support #3277

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
cc60e5e
Update hst-install-debian.sh
darkworks Feb 18, 2023
8ff9801
Update hst-install-ubuntu.sh
darkworks Feb 18, 2023
fd219a7
Add files via upload
darkworks Feb 18, 2023
8dad8c7
Add files via upload
darkworks Feb 18, 2023
ed8c6ee
Update NodeJS.sh
darkworks Feb 18, 2023
0c1ce66
Update NodeJS.sh
darkworks Feb 18, 2023
a08ac05
Update hst-install-debian.sh
darkworks Feb 18, 2023
0f2e22e
Update hst-install-ubuntu.sh
darkworks Feb 18, 2023
219b684
Update hst-install-debian.sh
darkworks Feb 18, 2023
41223ed
Create NodeJS.stpl
darkworks Feb 20, 2023
f4326f7
Create NodeJS.tpl
darkworks Feb 20, 2023
f08457a
Create NodeJS.tpl
darkworks Feb 20, 2023
2d916b2
Create NodeJS.stpl
darkworks Feb 20, 2023
58c9349
Update NodeJS.stpl
darkworks Feb 22, 2023
fe96304
Update NodeJS.stpl
darkworks Feb 22, 2023
b4836f4
Update NodeJS.stpl
darkworks Feb 22, 2023
909193f
Update NodeJS.tpl
darkworks Feb 22, 2023
15c674b
Update NodeJS.tpl
darkworks Feb 22, 2023
a1754d6
Update NodeJS.stpl
darkworks Feb 22, 2023
c09a766
Update NodeJS.stpl
darkworks Feb 22, 2023
924527f
Update NodeJS.stpl
darkworks Feb 22, 2023
bb0e00a
Update NodeJS.stpl
darkworks Feb 22, 2023
2a0fb7a
Update NodeJS.tpl
darkworks Feb 22, 2023
be2f1d7
Update NodeJS.stpl
darkworks Feb 22, 2023
e487235
Update NodeJS.stpl
darkworks Feb 22, 2023
5050678
Update NodeJS.tpl
darkworks Feb 22, 2023
dfbff5c
beautified
darkworks Mar 10, 2023
e197d08
beautified
darkworks Mar 10, 2023
f148673
beautified
darkworks Mar 10, 2023
da3c7aa
beautified
darkworks Mar 10, 2023
1157025
Update hst-install-debian.sh
darkworks Apr 2, 2023
68c8df1
Update hst-install-debian.sh
darkworks Apr 2, 2023
3267f59
Update hst-install-ubuntu.sh
darkworks Apr 2, 2023
555aa46
Update NodeJS.stpl
darkworks Apr 2, 2023
4c8ccbd
Update NodeJS.tpl
darkworks Apr 2, 2023
6739c61
Merge branch 'main' into darkworks-nodejs
jaapmarcus May 21, 2023
2d19797
Fix templates
jaapmarcus May 21, 2023
1c28b9a
Rename to lower case
jaapmarcus May 21, 2023
e4b1510
Rename templates to lowercase
jaapmarcus May 21, 2023
9fa2c41
Update / Rename RPM templates
jaapmarcus May 21, 2023
0137065
Update permissions
jaapmarcus May 21, 2023
51291ed
Update hst-install-debian.sh
darkworks May 22, 2023
668ab02
Update hst-install-ubuntu.sh
darkworks May 22, 2023
f355d22
Merge remote-tracking branch 'darkworks/darkworks-nodejs' into darkwo…
jaapmarcus May 22, 2023
fc43639
Don't install nodejs
jaapmarcus May 22, 2023
57795e6
Merge branch 'main' into darkworks-nodejs
jaapmarcus May 22, 2023
795ea00
Merge remote-tracking branch 'darkworks/darkworks-nodejs' into darkwo…
jaapmarcus May 22, 2023
a1cdd8c
Install NPM from NodeJS repo
jaapmarcus May 22, 2023
291c22c
Fix Shellcheck error
jaapmarcus May 22, 2023
43e1495
Update docs
jaapmarcus May 22, 2023
12a20c5
Start on a new line
jaapmarcus May 22, 2023
42f842b
Add N as valid option
jaapmarcus May 22, 2023
e5e9eae
Fix bug in config test function
jaapmarcus May 22, 2023
813bb0f
Keep config test working
jaapmarcus May 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/v-add-web-php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fi
# Check if php version is supported
if [[ ! "$multiphp_v" =~ $version ]]; then
echo "ERROR: Specified PHP version is not supported or does not exist."
exit "$E_INVALID";
exit "$E_INVALID"
fi

# Perform verification if read-only mode is enabled
Expand Down
8 changes: 4 additions & 4 deletions bin/v-change-sys-ip-nat
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ if [ -n "$old" ] && [ -n "$FTP_SYSTEM" ]; then
fi
fi
if [ "$FTP_SYSTEM" = 'proftpd' ]; then
conf="/etc/$FTP_SYSTEM/conf.d/external_ip.conf"
content="MasqueradeAddress ${nat_ip}"
echo "$content" > $conf
fi
conf="/etc/$FTP_SYSTEM/conf.d/external_ip.conf"
content="MasqueradeAddress ${nat_ip}"
echo "$content" > $conf
fi
$BIN/v-restart-ftp "$restart"
fi

Expand Down
11 changes: 5 additions & 6 deletions bin/v-import-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,11 @@ echo "Converting addons domains, subdomains and some other fun"
cp sds hst_sds
cp sds2 hst_sds2
sed -i 's/_/./g' hst_sds
cat addons | while read ddon_domain addon_sub
do
echo "Converting default subdomain: $addon_sub in domain: $addon_domain"
sed -i -e "s/$addon_sub/$addon_domain/g" hst_sds
sed -i -e "s/$addon_sub/$addon_domain/g" hst_sds2
mv userdata/$addon_sub userdata/${addon_domain}
cat addons | while read ddon_domain addon_sub; do
echo "Converting default subdomain: $addon_sub in domain: $addon_domain"
sed -i -e "s/$addon_sub/$addon_domain/g" hst_sds
sed -i -e "s/$addon_sub/$addon_domain/g" hst_sds2
mv userdata/$addon_sub userdata/${addon_domain}
done
sed -i 's/public_html/public@html/g; s/_/./g; s/public@html/public_html/g; s/=/ /g' hst_sds2

Expand Down
7 changes: 7 additions & 0 deletions docs/_data/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,12 @@ export const options: OptionsListItem[] = [
desc: "Interactive install.",
selected: true,
},
{
name: " --nodejs",
id: "nodejs",
param: "--nodejs",
desc: "Install NodeJS.",
selected: true,
},
{ name: " --force", id: "force", param: "--force", desc: "Force installation.", selected: false },
];
101 changes: 101 additions & 0 deletions install/deb/templates/web/nginx/nodejs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

user=$1
domain=$2
ip=$3
home=$4
docroot=$5

#default script name
mainScript="src/index.js"
nodeDir="$home/$user/web/$domain/nodeapp"

mkdir $nodeDir
chown -R $user:$user $nodeDir

nodeVersion=""
nvmDir="/opt/nvm"
nodeInterpreter=""
envFile=""

#if are installed .nvm on the system
if [ -d "$nvmDir" ]; then

#check files .naverc .node-version .nvm
if [ -f "$nodeDir/.nvm" ]; then
nodeVersion=$(cat $nodeDir/.nvm)
elif [ -f "$nodeDir/.node-version" ]; then
nodeVersion=$(cat $nodeDir/.node-version)
fi

echo "Needs Node version: $nodeVersion"

export NVM_DIR=$nvmDir
. "$NVM_DIR/nvm.sh"

if [ ! -d "/opt/nvm/versions/node/$nodeVersion" ]; then
echo "Install this version"
nvm install $nodeVersion
chmod -R 755 /opt/nvm
else
echo "Error on install Node version on NVM"
fi

nodeInterpreter="--interpreter /opt/nvm/versions/node/$nodeVersion/bin/node"
fi

#auto install dependences
if [ ! -d "$nodeDir/node_modules" ]; then
echo "No modules found."
cd $nodeDir && npm i
fi

#get init script form package.json
package="$nodeDir/package.json"

if [ -e $package ]; then
mainScript=$(cat $package \
| grep main \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| sed 's/ *$//g')

scriptName=$(cat $package \
| grep name \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| sed 's/ *$//g')
fi

rm "$nodeDir/app.sock"
runuser -l $user -c "pm2 del $scriptName"

#apply enviroment variables from .env file
if [ -f "$nodeDir/.env" ]; then
echo ".env file in folder, applying."
envFile=$(grep -v '^#' $nodeDir/.env | xargs | sed "s/(PORT=(.*) )//g" | sed "s/ = /=/g")
echo $envFile
fi

#remove blank spaces
pmPath=$(echo "$nodeDir/$mainScript" | tr -d ' ')
runuser -l $user -c "$envFile PORT=$nodeDir/app.sock HOST=127.0.0.1 PWD=$nodeDir NODE_ENV=production pm2 start $pmPath --name $scriptName $nodeInterpreter"

echo "Waiting for init PM2"
sleep 5

if [ ! -f "$nodeDir/app.sock" ]; then
echo "Allow nginx access to the socket $nodeDir/app.sock"
chmod 755 "$nodeDir/app.sock"
else
echo "Sock file not present disable Node app"
runuser -l $user -c "pm2 del $scriptName"
rm $nodeDir/app.sock
fi

#copy pm2 logs to app folder
echo "Copy logs to nodeapp folder"
cp -r $home/$user/.pm2/logs/$domain-error.log $nodeDir
cp -r $home/$user/.pm2/logs/$domain-out.log $nodeDir
66 changes: 66 additions & 0 deletions install/deb/templates/web/nginx/nodejs.stpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#=========================================================================#
# Default Web Domain Template #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
# https://hestiacp.com/docs/server-administration/web-templates.html #
#=========================================================================#

server {
listen %ip%:%proxy_ssl_port%;
server_name %domain_idn% %alias_idn%;
root %docroot%;
index index.php index.html index.htm;

access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;

ssl_certificate %ssl_pem%;
ssl_certificate_key %ssl_key%;
ssl_stapling on;
ssl_stapling_verify on;

include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;

location / {
#single node
#proxy_pass http://127.0.0.1:3000;

#unix socket mode
proxy_pass http://unix:%home%/%user%/web/%domain%/nodeapp/app.sock:$request_uri;

proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_cache_bypass $http_upgrade;

location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
root %docroot%;
access_log /var/log/%web_system%/domains/%domain%.log combined;
access_log /var/log/%web_system%/domains/%domain%.bytes bytes;
expires max;
try_files $uri @fallback;
}
}

location /error/ {
alias %home%/%user%/web/%domain%/document_errors/;
}

location @fallback {
#single node
#proxy_pass http://127.0.0.1:3000;

#unix socket mode
proxy_pass http://unix:%home%/%user%/web/%domain%/nodeapp/app.sock:/$1;
}

location ~ /\.(?!well-known\/) {
deny all;
return 404;
}

include %home%/%user%/conf/web/%domain%/nginx.conf_*;

}
61 changes: 61 additions & 0 deletions install/deb/templates/web/nginx/nodejs.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#=========================================================================#
# Default Web Domain Template #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
# https://hestiacp.com/docs/server-administration/web-templates.html #
#=========================================================================#

server {
listen %ip%:%proxy_port%;
server_name %domain_idn% %alias_idn%;
root %docroot%;
index index.php index.html index.htm;

access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;

include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;

location / {
#single node
#proxy_pass http://127.0.0.1:3000;

#unix socket mode
proxy_pass http://unix:%home%/%user%/web/%domain%/nodeapp/app.sock:$request_uri;

proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_cache_bypass $http_upgrade;

location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
root %docroot%;
access_log /var/log/%web_system%/domains/%domain%.log combined;
access_log /var/log/%web_system%/domains/%domain%.bytes bytes;
expires max;
try_files $uri @fallback;
}
}

location /error/ {
alias %home%/%user%/web/%domain%/document_errors/;
}

location @fallback {
#single node
#proxy_pass http://127.0.0.1:3000;

#unix socket mode
proxy_pass http://unix:%home%/%user%/web/%domain%/nodeapp/app.sock:/$1;
}

location ~ /\.(?!well-known\/) {
deny all;
return 404;
}

include %home%/%user%/conf/web/%domain%/nginx.conf_*;

}
101 changes: 101 additions & 0 deletions install/deb/templates/web/nginx/php-fpm/nodejs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

user=$1
domain=$2
ip=$3
home=$4
docroot=$5

#default script name
mainScript="src/index.js"
nodeDir="$home/$user/web/$domain/nodeapp"

mkdir $nodeDir
chown -R $user:$user $nodeDir

nodeVersion=""
nvmDir="/opt/nvm"
nodeInterpreter=""
envFile=""

#if are installed .nvm on the system
if [ -d "$nvmDir" ]; then

#check files .naverc .node-version .nvm
if [ -f "$nodeDir/.nvm" ]; then
nodeVersion=$(cat $nodeDir/.nvm)
elif [ -f "$nodeDir/.node-version" ]; then
nodeVersion=$(cat $nodeDir/.node-version)
fi

echo "Needs Node version: $nodeVersion"

export NVM_DIR=$nvmDir
. "$NVM_DIR/nvm.sh"

if [ ! -d "/opt/nvm/versions/node/$nodeVersion" ]; then
echo "Install this version"
nvm install $nodeVersion
chmod -R 755 /opt/nvm
else
echo "Error on install Node version on NVM"
fi

nodeInterpreter="--interpreter /opt/nvm/versions/node/$nodeVersion/bin/node"
fi

#auto install dependences
if [ ! -d "$nodeDir/node_modules" ]; then
echo "No modules found."
cd $nodeDir && npm i
fi

#get init script form package.json
package="$nodeDir/package.json"

if [ -e $package ]; then
mainScript=$(cat $package \
| grep main \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| sed 's/ *$//g')

scriptName=$(cat $package \
| grep name \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| sed 's/ *$//g')
fi

rm "$nodeDir/app.sock"
runuser -l $user -c "pm2 del $scriptName"

#apply enviroment variables from .env file
if [ -f "$nodeDir/.env" ]; then
echo ".env file in folder, applying."
envFile=$(grep -v '^#' $nodeDir/.env | xargs | sed "s/(PORT=(.*) )//g" | sed "s/ = /=/g")
echo $envFile
fi

#remove blank spaces
pmPath=$(echo "$nodeDir/$mainScript" | tr -d ' ')
runuser -l $user -c "$envFile PORT=$nodeDir/app.sock HOST=127.0.0.1 PWD=$nodeDir NODE_ENV=production pm2 start $pmPath --name $scriptName $nodeInterpreter"

echo "Waiting for init PM2"
sleep 5

if [ ! -f "$nodeDir/app.sock" ]; then
echo "Allow nginx access to the socket $nodeDir/app.sock"
chmod 755 "$nodeDir/app.sock"
else
echo "Sock file not present disable Node app"
runuser -l $user -c "pm2 del $scriptName"
rm $nodeDir/app.sock
fi

#copy pm2 logs to app folder
echo "Copy logs to nodeapp folder"
cp -r $home/$user/.pm2/logs/$domain-error.log $nodeDir
cp -r $home/$user/.pm2/logs/$domain-out.log $nodeDir