Verified Commit 623110fc authored by Aral Balkan's avatar Aral Balkan
Browse files

PM2-related functionality works (tested with Linux binary)

parent 75a2c451
node_modules
dist
node_modules.zip
dist-iws
web-server.zip
......@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [7.2.0] - TBR
## TODO
- Automate: `zip web-server.zip * -x \*.git\* \*dist-iws\* -r` to create the source code zip to bundle in the binary.
## Added
- Native binary releases.
......@@ -18,6 +22,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix auto-restart after automatically obtaining privileged port binding privileges via setcap during first run on Linux.
## Changed
- Renamed `dist` folder to `dist-iws` so we can exclude it from the source code zip (used for the binaries) without also exclusing some of the node modules that have dist directories that are required for proper functioning.
## [7.1.0] - 2019-04-01
## Added
......
......@@ -17,8 +17,8 @@ const childProcess = require('child_process')
console.log(`\n ⚙ Indie Web Server: building native binaries for version ${version}`)
const linuxVersionPath = `dist/linux/${version}`
const macOSVersionPath = `dist/macos/${version}`
const linuxVersionPath = `dist-iws/linux/${version}`
const macOSVersionPath = `dist-iws/macos/${version}`
fs.mkdirSync(linuxVersionPath, {recursive: true})
fs.mkdirSync(macOSVersionPath, {recursive: true})
......@@ -32,7 +32,7 @@ async function build () {
input: 'bin/web-server.js',
output: `${linuxVersionPath}/web-server`,
target: 'linux-x64-10.15.3',
resources: ['package.json', 'bin/daemon.js', 'node_modules.zip']
resources: ['package.json', 'bin/daemon.js', 'web-server.zip']
})
console.log(' • Building macOS version…')
......
......@@ -10,19 +10,19 @@ const childProcess = require('child_process')
const arguments = require('minimist')(process.argv.slice(2), {boolean: true})
const externalDirectory = path.join(os.homedir(), '.indie-web-server')
if (!fs.existsSync(externalDirectory)) {
try {
fs.mkdirSync(externalDirectory, {recursive: true})
} catch (error) {
console.log(' 💥 Failed to create external directory.', error)
process.exit(1)
}
}
// if (!fs.existsSync(externalDirectory)) {
// try {
// fs.mkdirSync(externalDirectory, {recursive: true})
// } catch (error) {
// console.log(' 💥 Failed to create external directory.', error)
// process.exit(1)
// }
// }
const pm2Path = path.join(externalDirectory, 'node_modules/pm2/bin/pm2')
const nodeModulesZipFilePath = path.join(externalDirectory, 'node_modules.zip')
if (!fs.existsSync(nodeModulesZipFilePath)) {
const zipFilePath = path.join(os.homedir(), 'web-server.zip')
if (!fs.existsSync(externalDirectory)) {
try {
//
// Note: we are copying the node_modules.zip file using fs.readFileSync()
......@@ -33,10 +33,10 @@ if (!fs.existsSync(nodeModulesZipFilePath)) {
// 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)
const nodeModulesZip = fs.readFileSync(internalnodeModulesZipFilePath, 'binary')
fs.writeFileSync(nodeModulesZipFilePath, nodeModulesZip, 'binary')
const internalZipFilePath = path.join(__dirname, '../web-server.zip')
// fs.copyFileSync(internalZipFilePath, zipFilePath)
const webServerZip = fs.readFileSync(internalZipFilePath, 'binary')
fs.writeFileSync(zipFilePath, webServerZip, 'binary')
// Unzip the node_modules
const options = {
......@@ -45,10 +45,10 @@ if (!fs.existsSync(nodeModulesZipFilePath)) {
}
// Unzip the node_modules directory to the external directory.
childProcess.execSync(`unzip ${nodeModulesZipFilePath} -d ${externalDirectory}`)
childProcess.execSync(`unzip ${zipFilePath} -d ${externalDirectory}`)
} catch (error) {
console.log(' 💥 Failed to copy node_modules zip file to external directory.', error)
console.log(' 💥 Failed to copy Indie Web Server source to external directory.', error)
process.exit(1)
}
}
......@@ -243,7 +243,7 @@ if (arguments.live !== undefined) {
}
pm2.start({
script: path.join(__dirname, 'daemon.js'),
script: path.join(externalDirectory, 'bin/daemon.js'),
args: pathToServe,
name: 'web-server',
autorestart: true
......@@ -258,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 ${pm2Path} 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 ${pm2Path} 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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment