Skip to content

Commit

Permalink
set service mode as default, remove standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Feb 23, 2025
1 parent e4946cd commit 2d7cc25
Show file tree
Hide file tree
Showing 62 changed files with 67 additions and 635 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All notable changes to `homebridge-config-ui-x` will be documented in this file.
- make terminal enabled by default on new macOS hb-service installs
- update `fastify` and `nestjs` dependencies
- remove `log.tail` and `log.systemd` ui settings
- set service mode as default, remove standalone

### Homebridge Dependencies

Expand Down
114 changes: 0 additions & 114 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@
}
]
},
"restart": {
"title": "Custom Restart Command",
"type": "string",
"description": "If no restart command is set the process will terminate with a non-zero exit code.",
"placeholder": "eg. sudo systemctl restart homebridge"
},
"temp": {
"title": "OS Temp File Path",
"type": "string",
Expand Down Expand Up @@ -398,39 +392,19 @@
"type": "string",
"placeholder": "eg. /home/pi/mywallpaper.jpg"
},
"sudo": {
"title": "Use Sudo",
"type": "boolean",
"description": "If you are running Homebridge as root, you may need to enable this option."
},
"homebridgePackagePath": {
"title": "Path To Homebridge Module",
"type": "string",
"description": "If you have multiple versions of Homebridge installed, you can specify the path to the version you want to use here.",
"placeholder": "eg. /usr/local/lib/node_modules/homebridge"
},
"noFork": {
"title": "Do not run the UI server in a separate process/thread",
"type": "boolean",
"description": "If you are running Homebridge in a container, you may need to enable this option."
},
"host": {
"title": "Host IP Address",
"type": "string",
"pattern": "^[^{}/ :\\\\]+(?::\\d+)?$",
"description": "The host IP address to listen on. In most cases this will be '::' or '0.0.0.0'.",
"placeholder": "eg. 0.0.0.0"
},
"debug": {
"title": "Enable Debug Logging",
"type": "boolean",
"description": "If enabled, the Homebridge UI will log debug level messages to the console."
},
"standalone": {
"title": "Tell Homebridge the plugin is operating in standalone mode",
"type": "boolean",
"description": "If you are running Homebridge in a container, you may need to enable this option."
},
"sessionTimeout": {
"title": "Session Timeout (Seconds)",
"type": "integer",
Expand All @@ -447,69 +421,6 @@
"title": "Log Settings",
"description": "The log settings for the Homebridge UI.",
"properties": {
"method": {
"title": "Log Method",
"type": "string",
"default": "",
"description": "The method used to read the Homebridge log file.",
"required": true,
"oneOf": [
{
"title": "Default",
"enum": [
""
]
},
{
"title": "From File",
"enum": [
"file"
]
},
{
"title": "Systemd",
"enum": [
"systemd"
]
},
{
"title": "Custom Command",
"enum": [
"custom"
]
}
]
},
"path": {
"title": "Log File Path",
"type": "string",
"description": "Enter the full file path to your log file.",
"placeholder": "/var/log/homebridge.log",
"required": true,
"condition": {
"functionBody": "return (model.log && model.log.method==='file')"
}
},
"service": {
"title": "Systemd Service",
"type": "string",
"description": "Enter the systemd service name. Defaults to 'homebridge'.",
"placeholder": "homebridge",
"required": true,
"condition": {
"functionBody": "return (model.log && model.log.method==='systemd')"
}
},
"command": {
"title": "Custom Command",
"description": "This command should stream the logs to stdout.",
"type": "string",
"placeholder": "journalctl -f -n 100 -u homebridge",
"required": true,
"condition": {
"functionBody": "return (model.log && model.log.method==='custom')"
}
},
"maxSize": {
"type": "integer",
"description": "The max log size (bytes). Set to -1 to disable log truncation.",
Expand Down Expand Up @@ -640,19 +551,6 @@
}
]
},
{
"ref": "log",
"type": "fieldset",
"expandable": true,
"title": "Log Settings",
"items": [
"debug",
"log.method",
"log.path",
"log.service",
"log.command"
]
},
{
"ref": "logRetention",
"type": "fieldset",
Expand Down Expand Up @@ -710,8 +608,6 @@
"expandable": true,
"title": "Homebridge Settings",
"items": [
"sudo",
"restart",
"homebridgePackagePath"
]
},
Expand All @@ -732,16 +628,6 @@
"linux.restart",
"temp"
]
},
{
"ref": "container",
"type": "fieldset",
"expandable": true,
"title": "Container Settings",
"items": [
"standalone",
"noFork"
]
}
]
},
Expand Down
12 changes: 3 additions & 9 deletions src/core/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class ConfigService {

// Server env
public minimumNodeVersion = '20.18.0'
public serviceMode = (process.env.UIX_SERVICE_MODE === '1')
public runningInDocker = Boolean(process.env.HOMEBRIDGE_CONFIG_UI === '1')
public runningInSynologyPackage = Boolean(process.env.HOMEBRIDGE_SYNOLOGY_PACKAGE === '1')
public runningInPackageMode = Boolean(process.env.HOMEBRIDGE_APT_PACKAGE === '1')
Expand Down Expand Up @@ -105,12 +104,10 @@ export class ConfigService {
temp?: string
tempUnits?: string
loginWallpaper?: string
noFork?: boolean
linux?: {
shutdown?: string
restart?: string
}
standalone?: boolean
debug?: boolean
proxyHost?: string
sessionTimeout?: number
Expand Down Expand Up @@ -159,9 +156,7 @@ export class ConfigService {
this.setConfigForDocker()
}

if (this.serviceMode) {
this.setConfigForServiceMode()
}
this.setConfig()

if (!this.ui.port) {
this.ui.port = 8080
Expand Down Expand Up @@ -202,7 +197,6 @@ export class ConfigService {
packageVersion: this.package.version,
platform: platform(),
port: this.ui.port,
serviceMode: this.serviceMode,
setupWizardComplete: this.setupWizardComplete,
},
formAuth: Boolean(this.ui.auth !== 'none'),
Expand Down Expand Up @@ -295,9 +289,9 @@ export class ConfigService {
}

/**
* Populate the required config when running in "Service Mode"
* Populate the required config
*/
private setConfigForServiceMode() {
private setConfig() {
this.homebridgeInsecureMode = Boolean(process.env.UIX_INSECURE_MODE === '1')
this.ui.restart = undefined
this.ui.sudo = (platform() === 'linux' && !this.runningInDocker && !this.runningInSynologyPackage && !this.runningInPackageMode) || platform() === 'freebsd'
Expand Down
58 changes: 1 addition & 57 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Homebridge Entry Point
*/

import { fork } from 'node:child_process'
import { resolve } from 'node:path'
import process from 'node:process'

import { Command } from 'commander'
Expand Down Expand Up @@ -35,57 +33,6 @@ class HomebridgeUi {
log.error(msg)
log.warn(msg)
}

if (process.env.UIX_SERVICE_MODE === '1' && process.connected) {
this.log('Running in service mode.')
} else if (config.standalone || process.env.UIX_SERVICE_MODE === '1'
|| (process.env.HOMEBRIDGE_CONFIG_UI === '1' && satisfies(process.env.CONFIG_UI_VERSION, '>=3.5.5', { includePrerelease: true }))) {
this.log.warn('*********** Homebridge Standalone Mode Is Deprecated **********')
this.log.warn('* Please swap to service mode using the hb-service command. *')
this.log.warn('* See https://homebridge.io/w/JUvQr for instructions on how to migrate. *')
this.log('Running in standalone mode.')
} else if (config.noFork) {
this.noFork()
} else {
this.fork()
}
}

/**
* Run plugin as a separate node.js process
*/
fork() {
const ui = fork(resolve(__dirname, 'bin/fork'), null, {
env: process.env,
})

this.log('Spawning Homebridge UI with PID', ui.pid)

ui.on('close', () => {
process.kill(process.pid, 'SIGTERM')
})

ui.on('error', () => {
// Do nothing
})
}

/**
* Run plugin in the main homebridge process
*/
async noFork() {
await import('./main')
}

/**
* Set up the service mode process helper
* This ensures the Homebridge process is killed when hb-service
* is killed with SIGTERM to prevent stale processes.
*/
static serviceMode() {
process.on('disconnect', () => {
process.exit()
})
}

accessories(callback) {
Expand All @@ -98,8 +45,5 @@ class HomebridgeUi {
export = (api) => {
homebridge = api
homebridge.registerPlatform('homebridge-config-ui-x', 'config', HomebridgeUi)

if (process.env.UIX_SERVICE_MODE === '1' && process.connected) {
HomebridgeUi.serviceMode()
}
process.on('disconnect', () => process.exit())
}
Loading

0 comments on commit 2d7cc25

Please sign in to comment.