Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
- Various fixes to config file handling that only manifested when ins…
Browse files Browse the repository at this point in the history
…talling via nom globally, and using the bin links (like unity-cache-server)
  • Loading branch information
stephen-palmer committed Feb 22, 2018
1 parent eacc867 commit 866a4a1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ unity-cache-server [arguments]
-m, --monitor-parent-process <n> Monitor a parent process and exit if it dies
--dump-config Write the active configuration to the console
--save-config [path] Write the active configuration to the specified file and exit. Defaults to ./default.yml
--NODE_CONFIG_DIR=[path] Specify the directory to search for config files. This is equivalent to setting the NODE_CONFIG_DIR environment variable. Without this option, the built-in configuration is used. With this option the default is to look in the current directory for config files.
--NODE_CONFIG_DIR=<path> Specify the directory to search for config files. This is equivalent to setting the NODE_CONFIG_DIR environment variable. Without this option, the built-in configuration is used.
-h, --help output usage information
```
## Configuration files
Expand Down
9 changes: 6 additions & 3 deletions cleanup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env node
const helpers = require('./lib/helpers');
helpers.initConfigDir(__dirname);
const config = require('config');

const consts = require('./lib/constants');
const program = require('commander');
const moment = require('moment');
const filesize =require('filesize');
const ora = require('ora');

const config = require('config');
const VERSION = require('./package.json').version;

function myParseInt(val, def) {
Expand All @@ -28,13 +29,15 @@ const defaultCacheModule = config.get("Cache.defaultModule");

program.description("Unity Cache Server - Cache Cleanup\n\n Removes old files from supported cache modules.")
.version(VERSION)
.allowUnknownOption(true)
.option('-c --cache-module [path]', 'Use cache module at specified path', defaultCacheModule)
.option('-P, --cache-path [path]', 'Specify the path of the cache directory')
.option('-l, --log-level <n>', 'Specify the level of log verbosity. Valid values are 0 (silent) through 5 (debug)', myParseInt, consts.DEFAULT_LOG_LEVEL)
.option('-e, --expire-time-span <timeSpan>', 'Override the configured file expiration timespan. Both ASP.NET style time spans (days.minutes:hours:seconds, e.g. \'15.23:59:59\') and ISO 8601 time spans (e.g. \'P15DT23H59M59S\') are supported.', parseTimeSpan)
.option('-s, --max-cache-size <bytes>', 'Override the configured maximum cache size. Files will be removed from the cache until the max cache size is satisfied, using a Least Recently Used search. A value of 0 disables this check.', myParseInt)
.option('-d, --delete', 'Delete cached files that match the configured criteria. Without this, the default behavior is to dry-run which will print diagnostic information only.')
.option('-D, --daemon <interval>', 'Daemon mode: execute the cleanup script at the given interval in seconds as a foreground process.', myParseInt);
.option('-D, --daemon <interval>', 'Daemon mode: execute the cleanup script at the given interval in seconds as a foreground process.', myParseInt)
.option('--NODE_CONFIG_DIR=<path>', 'Specify the directory to search for config files. This is equivalent to setting the NODE_CONFIG_DIR environment variable. Without this option, the built-in configuration is used.');

if (!process.argv.slice(2).length) {
return program.outputHelp();
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ exports.setLogLevel = function(lvl) {
exports.getLogLevel = () => logLevel;

exports.initConfigDir = (rootDir) => {
if(!process.env.hasOwnProperty('NODE_CONFIG_DIR')) {
const configDir = process.env['NODE_CONFIG_DIR'];
if(!configDir) {
process.env['NODE_CONFIG_DIR'] = path.resolve(rootDir, "config/");
}
};
Expand Down
13 changes: 8 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env node
const cluster = require('cluster');
const helpers = require('./lib/helpers');
helpers.initConfigDir(__dirname);
const config = require('config');

const { Server } = require('./lib');
const cluster = require('cluster');
const consts = require('./lib/constants');
const program = require('commander');
const CacheServer = require('./lib').Server;
const prompt = require('prompt');
const ip = require('ip');
const VERSION = require('./package.json').version;
const config = require('config');
const fs = require('fs-extra');
const path = require('path');

Expand All @@ -29,6 +31,7 @@ const defaultCacheModule = config.get("Cache.defaultModule");

program.description("Unity Cache Server")
.version(VERSION)
.allowUnknownOption(true)
.option('-p, --port <n>', 'Specify the server port, only apply to new cache server', myParseInt, consts.DEFAULT_PORT)
.option('-c --cache-module [path]', 'Use cache module at specified path', defaultCacheModule)
.option('-P, --cache-path [path]', 'Specify the path of the cache directory')
Expand All @@ -38,7 +41,7 @@ program.description("Unity Cache Server")
.option('-m, --monitor-parent-process <n>', 'Monitor a parent process and exit if it dies', myParseInt, 0)
.option('--dump-config', 'Write the active configuration to the console')
.option('--save-config [path]', 'Write the active configuration to the specified file and exit. Defaults to ./default.yml')
.option('--NODE_CONFIG_DIR [path]', 'Specify the directory to search for config files. This is equivalent to setting the NODE_CONFIG_DIR environment variable. Without this option, the built-in configuration is used. With this option the default is to look in the current directory for config files.');
.option('--NODE_CONFIG_DIR=<path>', 'Specify the directory to search for config files. This is equivalent to setting the NODE_CONFIG_DIR environment variable. Without this option, the built-in configuration is used.');

program.parse(process.argv);

Expand Down Expand Up @@ -137,7 +140,7 @@ Cache.init(cacheOpts)
mirror: mirrors
};

server = new CacheServer(Cache, opts);
server = new Server(Cache, opts);

if(cluster.isMaster) {
helpers.log(consts.LOG_INFO, `Cache Server version ${VERSION}; Cache module is ${program.cacheModule}`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-cache-server",
"version": "6.0.0-beta.5",
"version": "6.0.0-beta.7",
"description": "Unity Cache Server",
"main": "lib/index.js",
"engines": {
Expand Down

0 comments on commit 866a4a1

Please sign in to comment.