refactor: change my-servers and unraid-api base paths

This commit is contained in:
Alexis Tyler
2021-05-13 13:08:43 +09:30
parent f821c0e258
commit 69432bd3d9
5 changed files with 19 additions and 11 deletions

View File

@@ -3,6 +3,6 @@ PATHS_STATES=$(pwd)/../core/test/fixtures/states
PATHS_PLUGINS=$(pwd)/../core/test/fixtures/plugins
PATHS_UNRAID_VERSION=$(pwd)/../core/test/fixtures/etc/unraid-version
PATHS_DYNAMIX_CONFIG=$(pwd)/../core/test/fixtures/boot/config/plugins/dynamix/dynamix.cfg
PATHS_MY_SERVERS_CONFIG=$(pwd)/../core/test/fixtures/boot/config/plugins/Unraid.net/myservers.cfg
PATHS_MY_SERVERS_CONFIG=$(pwd)/../core/test/fixtures/boot/config/plugins/dynamix.my.servers/myservers.cfg
NCHAN=false
PORT=5000

View File

@@ -62,7 +62,7 @@ This will enable debug logs and the playground.
## Playground
The playground can be access via `http://tower.local/graphql` while in debug mode.
To get your API key open a terminal on your server and run `cat /boot/config/plugins/Unraid.net/myservers.cfg | grep apikey= | cut -d '"' -f2`. Add that API key in the "HTTP headers" panel of the playground.
To get your API key open a terminal on your server and run `cat /boot/config/plugins/dynamix.my.servers/myservers.cfg | grep apikey= | cut -d '"' -f2`. Add that API key in the "HTTP headers" panel of the playground.
```json
{

View File

@@ -7,6 +7,7 @@ import pidusage from 'pidusage';
import prettyMs from 'pretty-ms';
import dedent from 'dedent';
import { version } from '../package.json';
import { paths } from './core';
const setEnv = (envName: string, value: any) => {
if (!value || String(value).trim().length === 0) {
@@ -79,7 +80,7 @@ const commands = {
process.title = 'unraid-api';
// Set cwd
process.chdir('/usr/local/bin/node/unraid-api/');
process.chdir(paths.get('unraid-api-base')!);
// Set envs
setEnv('DEBUG', mainOptions.debug);
@@ -107,7 +108,7 @@ const commands = {
env: Object.assign(process.env, { _DAEMONIZE_PROCESS: '1' }),
// The process MUST have it's cwd set to the
// path where it resides within the Nexe VFS
cwd: '/usr/local/bin/node/unraid-api/',
cwd: '/usr/local/bin/unraid-api/',
stdio: 'ignore',
detached: true
});
@@ -176,7 +177,8 @@ const commands = {
`);
},
async 'switch-env'() {
const envFile = await fs.promises.readFile('/boot/config/plugins/Unraid.net/env', 'utf-8').catch(() => '');
const envFilePath = paths.get('myservers-env')!;
const envFile = await fs.promises.readFile(envFilePath, 'utf-8').catch(() => '');
// Match the env file env="production" which would be [0] = env="production", [1] = env and [2] = production
const matchArray = /([a-zA-Z]+)=["]*([a-zA-Z]+)["]*/.exec(envFile);
// Get item from index 2 of the regex match or return undefined
@@ -187,18 +189,18 @@ const commands = {
console.info('Switching env to "production"...');
// Default back to production
await fs.promises.writeFile('/boot/config/plugins/Unraid.net/env', 'env=production');
await fs.promises.writeFile(envFilePath, 'env=production');
return;
}
// Switch from staging to production
if (currentEnv === 'staging') {
await fs.promises.writeFile('/boot/config/plugins/Unraid.net/env', 'env=production');
await fs.promises.writeFile(envFilePath, 'env=production');
}
// Switch from production to staging
if (currentEnv === 'staging') {
await fs.promises.writeFile('/boot/config/plugins/Unraid.net/env', 'env=staging');
await fs.promises.writeFile(envFilePath, 'env=staging');
}
// Restart the process

View File

@@ -8,6 +8,7 @@ export interface Paths {
plugins: string;
htpasswd: string;
states: string;
'unraid-api-base': string;
'unraid-version': string;
'unraid-data': string;
'docker-autostart': string;
@@ -16,7 +17,9 @@ export interface Paths {
'emhttpd-socket': string;
'dynamix-base': string;
'dynamix-config': string;
'myservers-base': string;
'myservers-config': string;
'myservers-env': string;
'nginx-origin': string;
'machine-id': string;
}
@@ -37,8 +40,9 @@ const addEnvPaths = ([key, value]: [keyof Paths, string]): [keyof Paths, string]
*/
export const defaultPaths = new Map<keyof Paths, string>([
['core', thisDir],
['unraid-api-base', '/usr/local/bin/unraid-api/'],
['unraid-version', '/etc/unraid-version'],
['unraid-data', '/boot/config/plugins/Unraid.net/data'],
['unraid-data', '/boot/config/plugins/dynamix.my.servers/data/'],
['docker-autostart', '/var/lib/docker/unraid-autostart'],
['docker-socket', '/var/run/docker.sock'],
['parity-checks', '/boot/config/parity-checks.log'],
@@ -47,7 +51,9 @@ export const defaultPaths = new Map<keyof Paths, string>([
['states', '/usr/local/emhttp/state/'],
['dynamix-base', '/boot/config/plugins/dynamix/'],
['dynamix-config', '/boot/config/plugins/dynamix/dynamix.cfg'],
['myservers-config', '/boot/config/plugins/Unraid.net/myservers.cfg'],
['myservers-base', '/boot/config/plugins/dynamix.my.servers/'],
['myservers-config', '/boot/config/plugins/dynamix.my.servers/myservers.cfg'],
['myservers-env', '/boot/config/plugins/dynamix.my.servers/env'],
['nginx-origin', '/var/run/nginx.origin'],
['machine-id', '/etc/machine-id']
]);

View File

@@ -16,7 +16,7 @@ npm i -g nexe del-cli move-file-cli
# Setup our directory
mkdir /sandbox && cd /sandbox
# Copy our source package
cp /boot/config/plugins/Unraid.net/unraid-api.tgz .
cp /boot/config/plugins/dynamix.my.servers/unraid-api.tgz .
# Decompress the source
tar xvzf ./unraid-api.tgz
# Rename the directory and enter it