Skip to content

Commit

Permalink
lxc: fix auto repair in systemd script
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Dec 28, 2024
1 parent 48c5e1a commit 586f78e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion install/proxmox/docker-compose.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cd /root/.scrypted
# always immediately upgrade everything in case there's a broken update.
# this will also be preferable for troubleshooting via lxc reboot.
export DEBIAN_FRONTEND=noninteractive
((yes | dpkg --configure -a) && apt -y --fix-broken install && apt -y update && apt -y dist-upgrade) &
((yes | dpkg --configure -a) ; apt -y --fix-broken install && apt -y update && apt -y dist-upgrade) &
# foreground pull if requested.
if [ -e "volume/.pull" ]
Expand Down
1 change: 1 addition & 0 deletions plugins/core/fs/lxc/docker-compose.sh
22 changes: 0 additions & 22 deletions plugins/core/fs/lxc/scrypted.service

This file was deleted.

4 changes: 2 additions & 2 deletions plugins/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/core",
"version": "0.3.100",
"version": "0.3.101",
"description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.",
"author": "Scrypted",
"license": "Apache-2.0",
Expand Down
3 changes: 2 additions & 1 deletion plugins/core/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AggregateCore, AggregateCoreNativeId } from './aggregate-core';
import { AutomationCore, AutomationCoreNativeId } from './automations-core';
import { LauncherMixin } from './launcher-mixin';
import { MediaCore } from './media-core';
import { checkLegacyLxc } from './platform/lxc';
import { checkLegacyLxc, checkLxc } from './platform/lxc';
import { ConsoleServiceNativeId, PluginSocketService, ReplServiceNativeId } from './plugin-socket-service';
import { ScriptCore, ScriptCoreNativeId, newScript } from './script-core';
import { TerminalService, TerminalServiceNativeId } from './terminal-service';
Expand Down Expand Up @@ -99,6 +99,7 @@ class ScryptedCore extends ScryptedDeviceBase implements HttpRequestHandler, Dev
}

checkLegacyLxc();
checkLxc();

this.storageSettings.settings.releaseChannel.hide = process.env.SCRYPTED_INSTALL_ENVIRONMENT !== 'lxc-docker';

Expand Down
25 changes: 25 additions & 0 deletions plugins/core/src/platform/lxc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import fs from 'fs';
import sdk from '@scrypted/sdk';

export const SCRYPTED_INSTALL_ENVIRONMENT_LXC = 'lxc';
export const SCRYPTED_INSTALL_ENVIRONMENT_LXC_DOCKER = 'lxc-docker';

export async function checkLegacyLxc() {
if (process.env.SCRYPTED_INSTALL_ENVIRONMENT !== SCRYPTED_INSTALL_ENVIRONMENT_LXC)
return;

sdk.log.a('This system is currently running the legacy LXC installation method and must be migrated to the new LXC manually: https://docs.scrypted.app/installation.html#proxmox-ve-container-reset');
}

const DOCKER_COMPOSE_SH_PATH = '/root/.scrypted/docker-compose.sh';
const LXC_DOCKER_COMPOSE_SH_PATH = 'lxc/docker-compose.sh';

export async function checkLxc() {
if (process.env.SCRYPTED_INSTALL_ENVIRONMENT !== SCRYPTED_INSTALL_ENVIRONMENT_LXC_DOCKER)
return;

const foundDockerComposeSh = await fs.promises.readFile(DOCKER_COMPOSE_SH_PATH, 'utf8');
const dockerComposeSh = await fs.promises.readFile(LXC_DOCKER_COMPOSE_SH_PATH, 'utf8');

if (foundDockerComposeSh === dockerComposeSh) {
// check if the file is executable
const stats = await fs.promises.stat(DOCKER_COMPOSE_SH_PATH);
if (stats.mode & 0o111)
return;
await fs.promises.chmod(DOCKER_COMPOSE_SH_PATH, 0o755);
return;
}

await fs.promises.copyFile(LXC_DOCKER_COMPOSE_SH_PATH, DOCKER_COMPOSE_SH_PATH);
await fs.promises.chmod(DOCKER_COMPOSE_SH_PATH, 0o755);
}

0 comments on commit 586f78e

Please sign in to comment.