Commit f93ce14d authored by Aral Balkan's avatar Aral Balkan

Add --offline command for live servers; simplify help; update docs

parent 1cd0d359
......@@ -14,18 +14,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [7.0.1] - 2019-04-01
## Added
- `--offline` command to take a running live server offline (remove it from startup items and delete it from the process manager if necessary).
## Changed
- No longer using a custom directory for pm2 files.
- Simplified the `--help` display.
## [7.0.0] - 2019-03-31
## Added
- `--live` flag to run as daemon and handle crashes/restarts via integrated pm2 process manager.
- `--monitor` flag to monitor an already-running live server daemon process.
- `--logs` flag to display and tail the web server logs for an already-running live server daemon process.
- `--info` flag to display detailed information for an already-running live server daemon process.
- `--monitor` command to monitor an already-running live server daemon process.
- `--logs` command to display and tail the web server logs for an already-running live server daemon process.
- `--info` command to display detailed information for an already-running live server daemon process.
## Changed
......
......@@ -8,10 +8,12 @@ Indie Web Server is a secure and seamless [Small Tech](https://ar.al/2019/03/04/
- Develop and test with automatically-provisioned locally-trusted TLS thanks to [mkcert](https://github.com/FiloSottile/mkcert) via [Nodecert](https://source.ind.ie/hypha/tools/nodecert).
- Stage and deploy with automatically-provisioned globally-trusted TLS thanks to [Let’s Encrypt](https://letsencrypt.org/) via [ACME TLS](https://source.ind.ie/hypha/tools/acme-tls) (with an A score on [SSL Labs SSL Server Test](https://www.ssllabs.com/ssltest)).
- Stage and deploy with automatically-provisioned globally-trusted TLS thanks to [Let’s Encrypt](https://letsencrypt.org/) via [ACME TLS](https://source.ind.ie/hypha/tools/acme-tls) (with an A score on [SSL Labs SSL Server Test](https://www.ssllabs.com/ssltest)) and the seamlessly integrated [pm2](https://pm2.io/runtime/) process manager.
[Watch a short 4-minute video](https://ar.al/2019/03/14/introducing-indie-web-server-video/) demonstrating how easy Indie Web Server is to install and use.
(Note: the video is about two weeks old and so it does not demonstrate the new `--live` feature for deployments. I will record a new one as soon as I find some time.)
## Install
```sh
......@@ -52,11 +54,12 @@ The `--live` option sets up your server to (re)start automatically when you serv
For example, if you run the command on a connected server that has the ar.al domain pointing to it and `ar.al` set in _/etc/hostname_ (on Unix/Linux/macOS), you will be able to access the site at https://ar.al. The first time you hit it, it will take a little longer to load as your Let’s Encrypt certificates are being automatically provisioned by ACME TLS.
Once you have a live web server daemon running, you can use the following commands to get insight into it:
With a running live server, you can also use the following commands:
- `--monitor`: monitor the running live server daemon process.
- `--logs`: display and tail the web server logs for the running live server daemon process.
- `--info`: display detailed information on the running live server daemon process.
- `--monitor`: Monitor the server.
- `--logs`: Display and tail the server logs.
- `--info`: Display detailed information about the server.
- `--offline`: Take the server offline and remove it from startup items.
The live server uses the [pm2](https://pm2.io/runtime/) process manager internally. Beyond the commands listed above that Indie Web Server proxies to pm2, you can make use of all pm2 functionality via the pm2 command directly should you need to.
......
......@@ -20,22 +20,31 @@ if (arguments._.length > 2 || arguments.help === true) {
const usageMonitorOption = `${clr('--monitor', 'yellow')}`
const usageLogsOption = `${clr('--logs', 'yellow')}`
const usageInfoOption = `${clr('--info', 'yellow')}`
const usageOfflineOption = `${clr('--offline', 'yellow')}`
const usageVersionOption = `${clr('--version', 'yellow')}`
const usage = `
${webServer.version()}
${clr('Usage:', 'underline')}
${clr('web-server', 'bold')} [${usageFolderToServe}] [${usagePortOption}] [${usageStagingOption}] [${usageLiveOption}] [${usageMonitorOption}] [${usageLogsOption}] [${usageVersionOption}]
${clr('web-server', 'bold')} [${usageFolderToServe}] [${clr('options', 'yellow')}]
${usageFolderToServe}\tPath to the folder to serve (defaults to current folder).
${usagePortOption}\t\tThe port to start the server on (defaults to 443).
${usageStagingOption}\t\tRun as regular process with globally-trusted certificates.
${usageLiveOption}\t\tRun as launch-time daemon with globally-trusted certificates.
${usageMonitorOption}\t\tMonitor the running live server.
${usageLogsOption}\t\tDisplay and tail the server logs for the running live server.
${usageInfoOption}\t\tDisplay detailed information about the running live server.
${usageVersionOption}\t\tDisplay the version.
${usageFolderToServe}\tPath to the folder to serve (defaults to current folder).
${clr('Options:', 'underline')}
${usagePortOption}\t\tThe port to start the server on (defaults to 443).
${usageVersionOption}\t\tDisplay the version and exit.
${usageStagingOption}\t\tLaunch server as regular process with globally-trusted certificates.
${usageLiveOption}\t\tLaunch server as startup daemon with globally-trusted certificates.
${clr('With a running live server, you can also:', 'underline')}
${usageMonitorOption}\t\tMonitor the server.
${usageLogsOption}\t\tDisplay and tail the server logs.
${usageInfoOption}\t\tDisplay detailed information about the server.
${usageOfflineOption}\t\tTake the server offline and remove it from startup items.
`.replace(/\n$/, '').replace(/^\n/, '')
console.log(usage)
......@@ -53,13 +62,13 @@ if (arguments.monitor !== undefined) {
// Launch pm2 monit.
const options = {
env: process.env,
stdio: 'inherit'
stdio: 'inherit' // Display output.
}
try {
childProcess.execSync(`sudo ${pm2Path} monit`, options)
} catch (error) {
console.log(` 👿 Failed to launch the process monitor.\n`)
console.log(`\n 👿 Failed to launch the process monitor.\n`)
process.exit(1)
}
process.exit(0)
......@@ -70,13 +79,13 @@ if (arguments.logs !== undefined) {
// Launch pm2 logs.
const options = {
env: process.env,
stdio: 'inherit'
stdio: 'inherit' // Display output.
}
try {
childProcess.execSync(`sudo ${pm2Path} logs web-server`, options)
} catch (error) {
console.log(` 👿 Failed to get the logs.\n`)
console.log(`\n 👿 Failed to get the logs.\n`)
process.exit(1)
}
process.exit(0)
......@@ -87,18 +96,76 @@ if (arguments.info !== undefined) {
// Launch pm2 logs.
const options = {
env: process.env,
stdio: 'inherit'
stdio: 'inherit' // Display output.
}
try {
childProcess.execSync(`sudo ${pm2Path} show web-server`, options)
} catch (error) {
console.log(` 👿 Failed to show detailed information on the web server.\n`)
console.log(`\n 👿 Failed to show detailed information on the web server.\n`)
process.exit(1)
}
process.exit(0)
}
// Offline (pm2 proxy for unstartup + delete)
if (arguments.offline !== undefined) {
const options = {
env: process.env,
stdio: 'pipe' // Suppress output.
}
// Do some cleanup, display a success message and exit.
function success () {
// Try to reset permissions on pm2 so that future uses of pm2 proxies via web-server
// in this session will not require sudo.
try {
childProcess.execSync('sudo chown $(whoami):$(whoami) /home/$(whoami)/.pm2/rpc.sock /home/$(whoami)/.pm2/pub.sock', options)
} catch (error) {
console.log(`\n 👿 Warning: could not reset permissions on pm2.`)
}
// All’s good.
console.log(`\n 😈 Server is offline and removed from startup items.\n`)
process.exit(0)
}
// Is the server running?
try {
childProcess.execSync(`sudo ${pm2Path} 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)
}
// Try to remove from startup items.
try {
childProcess.execSync(`sudo ${pm2Path} unstartup`, options)
} catch (error) {
console.log(`\n 👿 Could not remove the server from startup items.\n`)
process.exit(1)
}
// 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 ${pm2Path} show web-server`, options)
} catch (error) {
success()
}
// The server is still on (it was not started as a startup item). Use
// pm2 delete to remove it.
try {
childProcess.execSync(`sudo ${pm2Path} delete web-server`, options)
} catch (error) {
console.log(`\n 👿 Could not delete the server daemon.\n`)
process.exit(1)
}
success()
}
// If no path is passed, serve the current folder.
// If there is a path, serve that.
let pathToServe = '.'
......@@ -151,7 +218,7 @@ if (arguments.live !== undefined) {
//
const options = {
env: process.env,
stdio: 'pipe'
stdio: 'pipe' // Suppress output.
}
try {
......
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