2016-07-29 16:59:58 +00:00
/ *
Node - OpenDroneMap Node . js App and REST API to access OpenDroneMap .
Copyright ( C ) 2016 Node - OpenDroneMap Contributors
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2016-07-28 01:51:52 +00:00
'use strict' ;
2016-08-02 16:07:54 +00:00
let fs = require ( 'fs' ) ;
2016-07-29 16:59:58 +00:00
let argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
2016-08-02 16:07:54 +00:00
let utils = require ( './libs/utils' ) ;
2016-07-29 16:59:58 +00:00
if ( argv . help ) {
console . log ( `
Usage : node index . js [ options ]
Options :
2018-06-25 15:42:44 +00:00
-- config < path > Path to the configuration file ( default : config - default . json )
2016-07-29 16:59:58 +00:00
- p , -- port < number > Port to bind the server to ( default : 3000 )
-- odm _path < path > Path to OpenDroneMap ' s code ( default : / c o d e )
2016-07-29 22:16:22 +00:00
-- log _level < logLevel > Set log level verbosity ( default : info )
2016-07-29 16:59:58 +00:00
- d , -- deamonize Set process to run as a deamon
2019-05-13 14:42:53 +00:00
- q , -- parallel _queue _processing < number > Number of simultaneous processing tasks ( default : 2 )
2018-11-23 19:48:22 +00:00
-- cleanup _tasks _after < number > Number of minutes that elapse before deleting finished and canceled tasks ( default : 2880 )
2019-01-31 18:33:50 +00:00
-- cleanup _uploads _after < number > Number of minutes that elapse before deleting unfinished uploads . Set this value to the maximum time you expect a dataset to be uploaded . ( default : 2880 )
2016-09-25 00:07:02 +00:00
-- test Enable test mode . In test mode , no commands are sent to OpenDroneMap . This can be useful during development or testing ( default : false )
2017-03-14 15:52:50 +00:00
-- test _skip _orthophotos If test mode is enabled , skip orthophoto results when generating assets . ( default : false )
2017-06-30 19:17:44 +00:00
-- test _skip _dems If test mode is enabled , skip dems results when generating assets . ( default : false )
2019-01-31 22:16:37 +00:00
-- test _drop _uploads If test mode is enabled , drop / task / new / u p l o a d r e q u e s t s w i t h 5 0 % p r o b a b i l i t y . ( d e f a u l t : f a l s e )
2019-02-13 19:03:28 +00:00
-- test _fail _tasks If test mode is enabled , mark tasks as failed . ( default : false )
2019-05-28 13:26:17 +00:00
-- test _seconds If test mode is enabled , sleep these many seconds before finishing processing a test task . ( default : 0 )
2018-06-25 15:42:44 +00:00
-- powercycle When set , the application exits immediately after powering up . Useful for testing launch and compilation issues .
2018-11-09 17:44:18 +00:00
-- token < token > Sets a token that needs to be passed for every request . This can be used to limit access to the node only to token holders . ( default : none )
-- max _images < number > Specify the maximum number of images that this processing node supports . ( default : unlimited )
2018-11-23 19:48:22 +00:00
-- webhook < url > Specify a POST URL endpoint to be invoked when a task completes processing ( default : none )
2018-11-22 03:22:37 +00:00
-- s3 _endpoint < url > Specify a S3 endpoint ( for example , nyc3 . digitaloceanspaces . com ) to upload completed task results to . ( default : do not upload to S3 )
2018-11-23 18:19:52 +00:00
-- s3 _bucket < bucket > Specify a S3 bucket name where to upload completed task results to . ( default : none )
2018-11-22 03:22:37 +00:00
-- s3 _access _key < key > S3 access key , required if -- s3 _endpoint is set . ( default : none )
-- s3 _secret _key < secret > S3 secret key , required if -- s3 _endpoint is set . ( default : none )
2018-11-23 18:19:52 +00:00
-- s3 _signature _version < version > S3 signature version . ( default : 4 )
2018-12-04 02:46:49 +00:00
-- s3 _upload _everything Upload all task results to S3 . ( default : upload only . zip archive and orthophoto )
2018-11-28 21:27:03 +00:00
-- max _concurrency < number > Place a cap on the max - concurrency option to use for each task . ( default : no limit )
2019-10-02 02:59:00 +00:00
-- max _runtime < number > Number of minutes ( approximate ) that a task is allowed to run before being forcibly canceled ( timeout ) . ( default : no limit )
2016-07-29 16:59:58 +00:00
Log Levels :
error | debug | info | verbose | debug | silly
` );
process . exit ( 0 ) ;
}
2016-07-28 01:51:52 +00:00
2016-07-28 22:59:08 +00:00
let config = { } ;
2016-07-28 01:51:52 +00:00
2016-08-02 16:07:54 +00:00
// Read configuration from file
let configFilePath = argv . config || "config-default.json" ;
let configFile = { } ;
if ( /\.json$/i . test ( configFilePath ) ) {
try {
let data = fs . readFileSync ( configFilePath ) ;
configFile = JSON . parse ( data . toString ( ) ) ;
} catch ( e ) {
console . log ( ` Invalid configuration file ${ configFilePath } ` ) ;
process . exit ( 1 ) ;
}
}
// Gets a property that might not exist from configuration file
// example: fromConfigFile("logger.maxFileSize", 1000);
function fromConfigFile ( prop , defaultValue ) {
return utils . get ( configFile , prop , defaultValue ) ;
}
2016-07-29 16:59:58 +00:00
// Instance name - default name for this configuration
2016-08-02 16:07:54 +00:00
config . instance = fromConfigFile ( "instance" , 'node-OpenDroneMap' ) ;
config . odm _path = argv . odm _path || fromConfigFile ( "odm_path" , '/code' ) ;
2016-07-28 01:51:52 +00:00
// Logging configuration
config . logger = { } ;
2016-08-02 16:07:54 +00:00
config . logger . level = argv . log _level || fromConfigFile ( "logger.level" , 'info' ) ; // What level to log at; info, verbose or debug are most useful. Levels are (npm defaults): silly, debug, verbose, info, warn, error.
config . logger . maxFileSize = fromConfigFile ( "logger.maxFileSize" , 1024 * 1024 * 100 ) ; // Max file size in bytes of each log file; default 100MB
config . logger . maxFiles = fromConfigFile ( "logger.maxFiles" , 10 ) ; // Max number of log files kept
config . logger . logDirectory = fromConfigFile ( "logger.logDirectory" , '' ) ; // Set this to a full path to a directory - if not set logs will be written to the application directory.
config . port = parseInt ( argv . port || argv . p || fromConfigFile ( "port" , process . env . PORT || 3000 ) ) ;
config . deamon = argv . deamonize || argv . d || fromConfigFile ( "daemon" , false ) ;
2019-05-13 14:42:53 +00:00
config . parallelQueueProcessing = parseInt ( argv . parallel _queue _processing || argv . q || fromConfigFile ( "parallelQueueProcessing" , 2 ) ) ;
2018-12-06 01:40:08 +00:00
config . cleanupTasksAfter = parseInt ( argv . cleanup _tasks _after || fromConfigFile ( "cleanupTasksAfter" , 2880 ) ) ;
2019-01-31 18:33:50 +00:00
config . cleanupUploadsAfter = parseInt ( argv . cleanup _uploads _after || fromConfigFile ( "cleanupUploadsAfter" , 2880 ) ) ;
2016-09-25 00:07:02 +00:00
config . test = argv . test || fromConfigFile ( "test" , false ) ;
2017-03-14 15:52:50 +00:00
config . testSkipOrthophotos = argv . test _skip _orthophotos || fromConfigFile ( "testSkipOrthophotos" , false ) ;
2017-06-30 19:17:44 +00:00
config . testSkipDems = argv . test _skip _dems || fromConfigFile ( "testSkipDems" , false ) ;
2019-01-31 22:16:37 +00:00
config . testDropUploads = argv . test _drop _uploads || fromConfigFile ( "testDropUploads" , false ) ;
2019-02-13 19:03:28 +00:00
config . testFailTasks = argv . test _fail _tasks || fromConfigFile ( "testFailTasks" , false ) ;
2019-05-28 13:26:17 +00:00
config . testSeconds = parseInt ( argv . test _seconds || fromConfigFile ( "testSeconds" , 0 ) ) ;
2017-03-30 16:23:00 +00:00
config . powercycle = argv . powercycle || fromConfigFile ( "powercycle" , false ) ;
2018-06-25 15:40:57 +00:00
config . token = argv . token || fromConfigFile ( "token" , "" ) ;
2018-11-23 14:04:47 +00:00
config . maxImages = parseInt ( argv . max _images || fromConfigFile ( "maxImages" , "" ) ) || null ;
2018-11-23 19:48:22 +00:00
config . webhook = argv . webhook || fromConfigFile ( "webhook" , "" ) ;
2018-11-23 18:19:52 +00:00
config . s3Endpoint = argv . s3 _endpoint || fromConfigFile ( "s3Endpoint" , "" ) ;
config . s3Bucket = argv . s3 _bucket || fromConfigFile ( "s3Bucket" , "" ) ;
2018-11-22 03:22:37 +00:00
config . s3AccessKey = argv . s3 _access _key || fromConfigFile ( "s3AccessKey" , process . env . AWS _ACCESS _KEY _ID || "" )
config . s3SecretKey = argv . s3 _secret _key || fromConfigFile ( "s3SecretKey" , process . env . AWS _SECRET _ACCESS _KEY || "" )
2018-11-23 18:19:52 +00:00
config . s3SignatureVersion = argv . s3 _signature _version || fromConfigFile ( "s3SignatureVersion" , "4" )
2018-12-04 02:46:49 +00:00
config . s3UploadEverything = argv . s3 _upload _everything || fromConfigFile ( "s3UploadEverything" , false ) ;
2018-11-28 21:27:03 +00:00
config . maxConcurrency = parseInt ( argv . max _concurrency || fromConfigFile ( "maxConcurrency" , 0 ) ) ;
2019-10-02 02:52:48 +00:00
config . maxRuntime = parseInt ( argv . max _runtime || fromConfigFile ( "maxRuntime" , - 1 ) ) ;
2018-11-28 21:27:03 +00:00
2016-07-28 01:51:52 +00:00
module . exports = config ;