Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hypha
Tools
Indie Web Server
Commits
75a2c451
Verified
Commit
75a2c451
authored
Apr 09, 2019
by
Aral Balkan
Browse files
Getting closer to having working binaries
parent
977341c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
75a2c451
node_modules
dist
node_modules.zip
bin/web-server.js
View file @
75a2c451
...
...
@@ -19,11 +19,34 @@ if (!fs.existsSync(externalDirectory)) {
}
}
const
pm2Path
=
path
.
join
(
externalDirectory
,
'
node_modules/pm2/bin/pm2
'
)
const
nodeModulesZipFilePath
=
path
.
join
(
externalDirectory
,
'
node_modules.zip
'
)
if
(
!
fs
.
existsSync
(
nodeModulesZipFilePath
))
{
try
{
//
// Note: we are copying the node_modules.zip file using fs.readFileSync()
// ===== and fs.writeFileSync() instead of fs.copyFileSync() as the latter
// does not work currently in binaries that are compiled with
// Nexe (tested with version 3.1.0). See these issues for more details:
//
// https://github.com/nexe/nexe/issues/605 (red herring)
// https://github.com/nexe/nexe/issues/607 (actual issue)
//
const
internalnodeModulesZipFilePath
=
path
.
join
(
__dirname
,
'
../node_modules.zip
'
)
fs
.
copyFileSync
(
internalnodeModulesZipFilePath
,
nodeModulesZipFilePath
)
// fs.copyFileSync(internalnodeModulesZipFilePath, nodeModulesZipFilePath)
const
nodeModulesZip
=
fs
.
readFileSync
(
internalnodeModulesZipFilePath
,
'
binary
'
)
fs
.
writeFileSync
(
nodeModulesZipFilePath
,
nodeModulesZip
,
'
binary
'
)
// Unzip the node_modules
const
options
=
{
env
:
process
.
env
,
stdio
:
'
inherit
'
// Display output.
}
// Unzip the node_modules directory to the external directory.
childProcess
.
execSync
(
`unzip
${
nodeModulesZipFilePath
}
-d
${
externalDirectory
}
`
)
}
catch
(
error
)
{
console
.
log
(
'
💥 Failed to copy node_modules zip file to external directory.
'
,
error
)
process
.
exit
(
1
)
...
...
@@ -85,7 +108,7 @@ if (arguments.monitor !== undefined) {
}
try
{
childProcess
.
execSync
(
`sudo
${
nodeModulesZipFile
Path
}
monit`
,
options
)
childProcess
.
execSync
(
`sudo
${
pm2
Path
}
monit`
,
options
)
}
catch
(
error
)
{
console
.
log
(
`\n 👿 Failed to launch the process monitor.\n`
)
process
.
exit
(
1
)
...
...
@@ -102,7 +125,7 @@ if (arguments.logs !== undefined) {
}
try
{
childProcess
.
execSync
(
`sudo
${
nodeModulesZipFile
Path
}
logs web-server`
,
options
)
childProcess
.
execSync
(
`sudo
${
pm2
Path
}
logs web-server`
,
options
)
}
catch
(
error
)
{
console
.
log
(
`\n 👿 Failed to get the logs.\n`
)
process
.
exit
(
1
)
...
...
@@ -119,7 +142,7 @@ if (arguments.info !== undefined) {
}
try
{
childProcess
.
execSync
(
`sudo
${
nodeModulesZipFile
Path
}
show web-server`
,
options
)
childProcess
.
execSync
(
`sudo
${
pm2
Path
}
show web-server`
,
options
)
}
catch
(
error
)
{
console
.
log
(
`\n 👿 Failed to show detailed information on the web server.\n`
)
process
.
exit
(
1
)
...
...
@@ -151,7 +174,7 @@ if (arguments.offline !== undefined) {
// Is the server running?
try
{
childProcess
.
execSync
(
`sudo
${
nodeModulesZipFile
Path
}
show web-server`
,
options
)
childProcess
.
execSync
(
`sudo
${
pm2
Path
}
show web-server`
,
options
)
}
catch
(
error
)
{
console
.
log
(
`\n 👿 Server is not running as a live daemon; nothing to take offline.\n`
)
process
.
exit
(
1
)
...
...
@@ -159,7 +182,7 @@ if (arguments.offline !== undefined) {
// Try to remove from startup items.
try
{
childProcess
.
execSync
(
`sudo
${
nodeModulesZipFile
Path
}
unstartup`
,
options
)
childProcess
.
execSync
(
`sudo
${
pm2
Path
}
unstartup`
,
options
)
}
catch
(
error
)
{
console
.
log
(
`\n 👿 Could not remove the server from startup items.\n`
)
process
.
exit
(
1
)
...
...
@@ -168,7 +191,7 @@ if (arguments.offline !== undefined) {
// If the server was started as a startup item, unstartup will also
// kill the process. Check again to see if the server is running.
try
{
childProcess
.
execSync
(
`sudo
${
nodeModulesZipFile
Path
}
show web-server`
,
options
)
childProcess
.
execSync
(
`sudo
${
pm2
Path
}
show web-server`
,
options
)
}
catch
(
error
)
{
success
()
}
...
...
@@ -176,7 +199,7 @@ if (arguments.offline !== undefined) {
// The server is still on (it was not started as a startup item). Use
// pm2 delete to remove it.
try
{
childProcess
.
execSync
(
`sudo
${
nodeModulesZipFile
Path
}
delete web-server`
,
options
)
childProcess
.
execSync
(
`sudo
${
pm2
Path
}
delete web-server`
,
options
)
}
catch
(
error
)
{
console
.
log
(
`\n 👿 Could not delete the server daemon.\n`
)
process
.
exit
(
1
)
...
...
@@ -235,20 +258,20 @@ if (arguments.live !== undefined) {
// Run the script that tells the process manager to add the server to launch at startup
// as a separate process with sudo privileges.
//
const
options
=
{
env
:
process
.
env
,
stdio
:
'
pipe
'
// Suppress output.
}
try
{
const
output
=
childProcess
.
execSync
(
`sudo
${
nodeModulesZipFile
Path
}
startup`
,
options
)
}
catch
(
error
)
{
console
.
log
(
` 👿 Failed to add server for auto-launch at startup.\n`
)
pm2
.
disconnect
()
process
.
exit
(
1
)
}
console
.
log
(
` 😈 Installed for auto-launch at startup.\n`
)
//
const options = {
//
env: process.env,
//
stdio: 'pipe' // Suppress output.
//
}
//
try {
//
const output = childProcess.execSync(`sudo ${
pm2
Path} startup`, options)
//
} catch (error) {
//
console.log(` 👿 Failed to add server for auto-launch at startup.\n`)
//
pm2.disconnect()
//
process.exit(1)
//
}
//
console.log(` 😈 Installed for auto-launch at startup.\n`)
// Disconnect from the pm2 daemon. This will also exit the script.
pm2
.
disconnect
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment