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

Add an option to not run hotel on startup #357

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ By default, `hotel` uses the following configuration values:
"tld": 'localhost',

// If you're behind a corporate proxy, replace this with your network proxy IP (example: "1.2.3.4:5000")
"proxy": false
"proxy": false,

// Change to false to prevent hotel from starting itself up automatically on login
"autostart": true
}
```

Expand Down
33 changes: 27 additions & 6 deletions src/cli/daemon.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const cp = require('child_process')
const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp')
const startup = require('user-startup')
const common = require('../common')
const conf = require('../conf')
const pidFile = require('../pid-file')
const uninstall = require('../scripts/uninstall')

module.exports = {
Expand All @@ -15,14 +17,33 @@ module.exports = {
function start() {
const node = process.execPath
const daemonFile = path.join(__dirname, '../daemon')
const startupFile = startup.getFile('hotel')

startup.create('hotel', node, [daemonFile], common.logFile)
const pid = pidFile.read()
if (pid) {
console.log(`Already running (process ${pid})`)
return
}

// Save startup file path in ~/.hotel
// Will be used later by uninstall script
mkdirp.sync(common.hotelDir)
fs.writeFileSync(common.startupFile, startupFile)
if (conf.autostart) {
const startupFile = startup.getFile('hotel')
startup.create('hotel', node, [daemonFile], common.logFile)

// Save startup file path in ~/.hotel
// Will be used later by uninstall script
mkdirp.sync(common.hotelDir)
fs.writeFileSync(common.startupFile, startupFile)
} else {
const fd = fs.openSync(common.logFile, 'w')
const opts = {
detached: true, // needed to unref() below
stdio: ['ignore', fd, fd]
}

cp
.spawn(node, [daemonFile], opts)
.on('error', console.log)
.unref()
}

console.log(`Started http://localhost:${conf.port}`)
}
Expand Down
4 changes: 3 additions & 1 deletion src/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const defaults = {
tld: 'localhost',
// Replace with your network proxy IP (1.2.3.4:5000) if any
// For example, if you're behind a corporate proxy
proxy: false
proxy: false,
// Set to false to disable automatic running on startup.
autostart: true
}

// Create empty conf it it doesn't exist
Expand Down