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 13 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
102 changes: 102 additions & 0 deletions install/deb/templates/web/nginx/NodeJS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/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
76 changes: 76 additions & 0 deletions install/deb/templates/web/nginx/NodeJS.stpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
server {
jaapmarcus marked this conversation as resolved.
Show resolved Hide resolved
listen %ip%:%proxy_port%;
server_name %domain_idn% %alias_idn%;
return 301 https://%domain_idn%$request_uri;
}

server {
listen %ip%:%proxy_ssl_port%;

server_name %domain_idn%;

ssl on;
ssl_certificate %ssl_pem%;
ssl_certificate_key %ssl_key%;

error_log /var/log/%web_system%/domains/%domain%.error.log error;

gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types image/svg+xml svg svgz text/plain application/x-javascript text/xml text/css;
gzip_vary on;

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

location / {

#single
#proxy_pass http://127.0.0.1:3000;

#unix socket
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 ~* ^.+\.(%proxy_extensions%)$ {
root %sdocroot%;
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;
add_header Pragma public;
add_header Cache-Control "public";
}
}

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

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

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

location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
location ~ /\.(?!well-known\/|file) {
deny all;
return 404;
}

include %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
}
50 changes: 50 additions & 0 deletions install/deb/templates/web/nginx/NodeJS.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
server {
listen %ip%:%proxy_port%;
server_name %domain_idn% %alias_idn%;

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

error_log /var/log/%web_system%/domains/%domain%.error.log error;

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;


location ~* ^.+\.(%proxy_extensions%)$ {
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 ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
location ~ /\.(?!well-known\/|file) {
deny all;
return 404;
}

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

}
76 changes: 76 additions & 0 deletions install/deb/templates/web/nginx/php-fpm/NodeJS.stpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
server {
darkworks marked this conversation as resolved.
Show resolved Hide resolved
listen %ip%:%proxy_port%;
server_name %domain_idn% %alias_idn%;
return 301 https://%domain_idn%$request_uri;
}

server {
listen %ip%:%proxy_ssl_port%;

server_name %domain_idn%;

ssl on;
ssl_certificate %ssl_pem%;
ssl_certificate_key %ssl_key%;

error_log /var/log/%web_system%/domains/%domain%.error.log error;

gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types image/svg+xml svg svgz text/plain application/x-javascript text/xml text/css;
gzip_vary on;

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

location / {

#single
#proxy_pass http://127.0.0.1:3000;

#unix socket
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 ~* ^.+\.(%proxy_extensions%)$ {
root %sdocroot%;
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;
add_header Pragma public;
add_header Cache-Control "public";
}
}

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

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

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

location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
location ~ /\.(?!well-known\/|file) {
deny all;
return 404;
}

include %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
}
50 changes: 50 additions & 0 deletions install/deb/templates/web/nginx/php-fpm/NodeJS.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
server {
listen %ip%:%proxy_port%;
darkworks marked this conversation as resolved.
Show resolved Hide resolved
server_name %domain_idn% %alias_idn%;

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

error_log /var/log/%web_system%/domains/%domain%.error.log error;

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;


location ~* ^.+\.(%proxy_extensions%)$ {
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 ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
location ~ /\.(?!well-known\/|file) {
deny all;
return 404;
}

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

}