server/core: support built in server updates

This commit is contained in:
Koushik Dutta
2023-05-23 12:04:02 -07:00
parent 9334d1c2a4
commit af02753cef
9 changed files with 51 additions and 24 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/core",
"version": "0.1.128",
"version": "0.1.129",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/core",
"version": "0.1.128",
"version": "0.1.129",
"license": "Apache-2.0",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/core",
"version": "0.1.128",
"version": "0.1.129",
"description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.",
"author": "Scrypted",
"license": "Apache-2.0",

View File

@@ -149,20 +149,31 @@ export default {
getComponentViewPath,
async checkUpdateAvailable() {
await this.$connectingScrypted;
const info = await this.$scrypted.systemManager.getComponent("info");
const version = await info.getVersion();
this.currentVersion = version;
const { updateAvailable } = await checkUpdate(
"@scrypted/server",
version
const serviceControl = await this.$scrypted.systemManager.getComponent(
"service-control"
);
this.updateAvailable = updateAvailable;
if (updateAvailable) {
try {
this.updateAvailable = await serviceControl.getUpdateAvailable();
}
catch (e) {
// old scrypted servers dont support this call, or it may be unimplemented
// in which case fall back and determine what the install type is.
const info = await this.$scrypted.systemManager.getComponent("info");
const version = await info.getVersion();
this.currentVersion = version;
const { updateAvailable } = await checkUpdate(
"@scrypted/server",
version
);
this.updateAvailable = updateAvailable;
}
if (this.updateAvailable) {
const logger = this.$scrypted.deviceManager.getDeviceLogger();
const u = new URL(window.location)
u.hash = "#/component/settings";
logger.clearAlerts();
logger.a(`Scrypted Server update available: ${updateAvailable}. ${u}`);
logger.a(`Scrypted Server update available: ${this.updateAvailable}. ${u}`);
}
},
filterComponents: function (category) {

View File

@@ -130,17 +130,28 @@ export default {
const info = await this.$scrypted.systemManager.getComponent("info");
const version = await info.getVersion();
this.currentVersion = version;
const { updateAvailable } = await checkUpdate(
"@scrypted/server",
version
const serviceControl = await this.$scrypted.systemManager.getComponent(
"service-control"
);
this.updateAvailable = updateAvailable;
try {
this.updateAvailable = await serviceControl.getUpdateAvailable();
}
catch (e) {
// old scrypted servers dont support this call, or it may be unimplemented
// in which case fall back and determine what the install type is.
const { updateAvailable } = await checkUpdate(
"@scrypted/server",
version
);
this.updateAvailable = updateAvailable;
}
},
async loadEnv() {
const info = await this.$scrypted.systemManager.getComponent("info");
const env = await info.getScryptedEnv();
this.showRestart = !!env.SCRYPTED_CAN_RESTART;
this.canUpdate = !!env.SCRYPTED_NPM_SERVE || !!env.SCRYPTED_WEBHOOK_UPDATE;
this.canUpdate = !!env.SCRYPTED_NPM_SERVE || !!env.SCRYPTED_WEBHOOK_UPDATE || !!env.SCRYPTED_CAN_UPDATE;
},
async doRestart() {
this.restartStatus = "Restarting...";

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/server",
"version": "0.24.0",
"version": "0.29.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@scrypted/server",
"version": "0.24.0",
"version": "0.29.0",
"license": "ISC",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.10",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/server",
"version": "0.24.0",
"version": "0.29.0",
"description": "",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.10",

View File

@@ -83,11 +83,12 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
},
});
pluginComponent = new PluginComponent(this);
servieControl = new ServiceControl(this);
serviceControl = new ServiceControl(this);
alerts = new Alerts(this);
corsControl = new CORSControl(this);
addressSettings = new AddressSettings(this);
usersService = new UsersService(this);
info = new Info();
pluginHosts = new Map<string, RuntimeHost>();
constructor(public mainFilename: string, datastore: Level, insecure: http.Server, secure: https.Server, app: express.Application) {
@@ -332,11 +333,11 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
case 'SCRYPTED_SECURE_PORT':
return SCRYPTED_SECURE_PORT;
case 'info':
return new Info();
return this.info;
case 'plugins':
return this.pluginComponent;
case 'service-control':
return this.servieControl;
return this.serviceControl;
case 'logger':
return this.logger;
case 'alerts':

View File

@@ -325,7 +325,7 @@ async function start(mainFilename: string, options?: {
for (const address of getHostAddresses(true, true)) {
console.log(`Scrypted Server (Remote) : https://${address}:${SCRYPTED_SECURE_PORT}/`);
}
console.log(`Version: : ${await new Info().getVersion()}`);
console.log(`Version: : ${await scrypted.info.getVersion()}`);
console.log('#######################################################');
console.log('Scrypted insecure http service port:', SCRYPTED_INSECURE_PORT);
console.log('Ports can be changed with environment variables.')

View File

@@ -15,6 +15,10 @@ export class ServiceControl {
process.exit();
}
async getUpdateAvailable(): Promise<string> {
throw new Error('getUpdateAvailable is not implemented. Updates will come out of band through Docker or npm.');
}
async update() {
const webhookUpdate = process.env.SCRYPTED_WEBHOOK_UPDATE;
if (webhookUpdate) {