From d259b87e4ee564696d795c5dc9aaedd796abce42 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Mon, 11 Jul 2022 17:14:17 +0900 Subject: [PATCH] Refactored, added features and updated code --- .gitignore | 28 + Dockerfile | 52 ++ ansible/init.sh | 9 + devcluster/README.md | 8 +- devcluster/api/local-json.js | 34 +- devcluster/api/local_api.json | 29 +- devcluster/api/r3apijson.js | 783 +++++++++--------- devcluster/api/r3clusterini.js | 204 +++-- devcluster/api/setup_api.sh | 331 ++++---- devcluster/api/setup_api_centos.ini | 11 +- devcluster/api/setup_api_debian.ini | 9 +- devcluster/api/setup_api_default.ini | 15 +- devcluster/api/setup_api_fedora.ini | 9 +- devcluster/api/setup_api_functions | 119 +-- devcluster/api/setup_api_node_module.sh | 275 +++--- devcluster/app/local-json.js | 35 +- devcluster/app/local_app.json | 28 + devcluster/app/r3appjson.js | 509 ++++++------ devcluster/app/r3clusterini.js | 210 ++--- devcluster/app/setup_app.sh | 158 ++-- devcluster/app/setup_app_centos.ini | 9 +- devcluster/app/setup_app_debian.ini | 9 +- devcluster/app/setup_app_default.ini | 9 +- devcluster/app/setup_app_fedora.ini | 9 +- devcluster/app/setup_app_functions | 119 +-- devcluster/app/setup_app_node_module.sh | 239 ++---- devcluster/chmpx/{slave.ini => chmpx.ini} | 25 +- devcluster/chmpx/{server.ini => k2hdkc.ini} | 33 +- devcluster/chmpx/override.conf | 6 +- devcluster/chmpx/setup_chmpx_functions | 397 ++++----- devcluster/cluster.sh | 183 ++-- devcluster/cluster_functions | 7 + devcluster/dkc/setup_dkc.sh | 185 +++-- devcluster/dkc/setup_dkc_centos.ini | 9 +- devcluster/dkc/setup_dkc_debian.ini | 9 +- devcluster/dkc/setup_dkc_default.ini | 10 +- devcluster/dkc/setup_dkc_fedora.ini | 9 +- devcluster/osnl/k2hr3-osnl.conf | 9 +- devcluster/osnl/setup_osnl.sh | 109 +-- devcluster/osnl/setup_osnl_centos6.ini | 9 +- devcluster/osnl/setup_osnl_centos7.ini | 9 +- devcluster/osnl/setup_osnl_debian.ini | 9 +- devcluster/osnl/setup_osnl_default.ini | 9 +- devcluster/osnl/setup_osnl_fedora.ini | 9 +- devcluster/osnl/setup_osnl_functions | 135 +-- .../service_manager/chmpx-slave.service | 15 - devcluster/service_manager/k2hr3-api.service | 32 +- devcluster/service_manager/k2hr3-app.service | 28 + devcluster/service_manager/k2hr3-osnl.service | 28 + devcluster/service_manager/plugin/default.sh | 96 ++- devcluster/test/cluster_test.sh | 11 +- 51 files changed, 2494 insertions(+), 2137 deletions(-) create mode 100644 Dockerfile rename devcluster/chmpx/{slave.ini => chmpx.ini} (85%) rename devcluster/chmpx/{server.ini => k2hdkc.ini} (82%) delete mode 100644 devcluster/service_manager/chmpx-slave.service diff --git a/.gitignore b/.gitignore index ad46b30..cc455f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,22 @@ +# +# K2HR3 K2HR3 Utilities +# +# Copyright 2020 Yahoo! Japan Corporation. +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# +# For the full copyright and license information, please view +# the licenses file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Thu, 14 Nov 2019 +# REVISION: +# + # Logs logs *.log @@ -59,3 +78,12 @@ typings/ # next.js build output .next + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3acf046 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +# syntax=docker/dockerfile:1 +# +# K2HR3 K2HR3 Utilities +# +# Copyright 2020 Yahoo! Japan Corporation. +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# +# For the full copyright and license information, please view +# the licenses file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Thu, 14 Nov 2019 +# REVISION: +# + +# [See] +# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ +# https://docs.docker.com/develop/develop-images/multistage-build/ + +FROM python:3.6-alpine as build + +RUN apk --update --no-cache add build-base libffi-dev openssl-dev +RUN pip3 install --upgrade pip +RUN pip3 install --prefix=/install ansible + +FROM python:3.6-alpine + +LABEL maintainer="antpickax@mail.yahoo.co.jp" + +RUN mkdir /lib64 \ + && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 \ + && apk --update --no-cache add git curl openssh-client rsync bash + +COPY --from=build /install /usr/local + +WORKDIR /ansible + +CMD [ "ansible-playbook", "--version" ] + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/ansible/init.sh b/ansible/init.sh index ee7d214..8ba0c52 100644 --- a/ansible/init.sh +++ b/ansible/init.sh @@ -78,3 +78,12 @@ EOF fi exit 0 + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/devcluster/README.md b/devcluster/README.md index 1f95e75..5bb8337 100644 --- a/devcluster/README.md +++ b/devcluster/README.md @@ -148,9 +148,9 @@ Here are summary of installation procedures: 5. Installs binary packages k2hr3_dkc needs the k2htpdtor, libfullock, k2hash, chmpx and k2hdkc. 6. Configures the chmpx default configuratoin - The default server.ini contains dummy server name. You need to change it. + The default k2hdkc.ini contains dummy server name. You need to change it. 7. Installs the configured chmpx config file - k2hr3_dkc uses a configuration file(for instance /etc/k2hdkc/server.ini) for [chmpx](https://github.com/yahoojapan/chmpx). + k2hr3_dkc uses a configuration file(for instance /etc/antpickax/k2hdkc.ini) for [chmpx](https://github.com/yahoojapan/chmpx). 8. Configures the chmpx's service manager default configuration We recommend [chmpx](https://github.com/yahoojapan/chmpx) processes work as a service by [systemd](https://freedesktop.org/wiki/Software/systemd/). 9. Installs the chmpx service manager configuration and enables it @@ -194,9 +194,9 @@ Here are summary of installation procedures: 5. Installs binary packages k2hr3_api needs the nodejs, k2htpdtor, libfullock, k2hash, chmpx and k2hdkc. 6. Configures the chmpx slave default configuration - The default slave.ini contains dummy server name. You need to change it. + The default chmpx.ini contains dummy server name. You need to change it. 7. Installs the configured chmpx slave config file - k2hr3_api uses a configuration file(for instance /etc/k2hdkc/slave.ini) for [chmpx](https://github.com/yahoojapan/chmpx). + k2hr3_api uses a configuration file(for instance /etc/k2hdkc/chmpx.ini) for [chmpx](https://github.com/yahoojapan/chmpx). 8. Configures the chmpx slave's service manager default configuration We recommend [chmpx](https://github.com/yahoojapan/chmpx) process works as a service by [systemd](https://freedesktop.org/wiki/Software/systemd/). 9. Configures the chmpx slave's service manager default configuration diff --git a/devcluster/api/local-json.js b/devcluster/api/local-json.js index f9e0997..14941ea 100644 --- a/devcluster/api/local-json.js +++ b/devcluster/api/local-json.js @@ -17,6 +17,7 @@ * CREATE: Tue Nov 12 2019 * REVISION: */ + // // This program generates a local.json of k2hr3-api from a k2hr3-utils setup.ini // @@ -27,21 +28,30 @@ const srcdir = path.resolve(__dirname); const process = require('process'); if ( process.argv.length != 4) { - let err = "Usage: node " + process.argv[1] + " "; - console.error(err); - throw new Error(err); + let err = "Usage: node " + process.argv[1] + " "; + console.error(err); + throw new Error(err); } const input = process.argv[2]; const output = process.argv[3]; try { - let rci = require(path.join(srcdir, 'r3clusterini.js')); - let raj = require(path.join(srcdir, 'r3apijson.js')); - let cluster = new rci.R3clusterIni(input, 'k2hr3_api'); - let r3api= new raj.R3apiJson(); - for (const val of cluster) { - r3api.configure(val[0], val[1]); // key, value - } - r3api.dumpTo(output); + let rci = require(path.join(srcdir, 'r3clusterini.js')); + let raj = require(path.join(srcdir, 'r3apijson.js')); + let cluster = new rci.R3clusterIni(input, 'k2hr3_api'); + let r3api= new raj.R3apiJson(); + for (const val of cluster) { + r3api.configure(val[0], val[1]); // key, value + } + r3api.dumpTo(output); } catch (err) { - console.error(err.name + ' ' + err.message); + console.error(err.name + ' ' + err.message); } + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/devcluster/api/local_api.json b/devcluster/api/local_api.json index 4801753..3166a97 100644 --- a/devcluster/api/local_api.json +++ b/devcluster/api/local_api.json @@ -1,3 +1,22 @@ +/* + * K2HR3 Utils + * + * Copyright 2019 Yahoo! Japan Corporation. + * + * K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers + * common management information for the cloud. + * K2HR3 can dynamically manage information as "who", "what", "operate". + * These are stored as roles, resources, policies in K2hdkc, and the + * client system can dynamically read and modify these information. + * + * For the full copyright and license information, please view + * the license file that was distributed with this source code. + * + * AUTHOR: Hirotaka Wakabayashi + * CREATE: Tue Nov 12 2019 + * REVISION: + */ + { "keystone": { "type": "openstackapiv3", @@ -51,8 +70,16 @@ "allowcredauth": true, "k2hdkc": { - "config": "/etc/antpickax/slave.ini", + "config": "/etc/antpickax/chmpx.ini", "port": 8031 } } +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/devcluster/api/r3apijson.js b/devcluster/api/r3apijson.js index a04f08c..a05ea81 100644 --- a/devcluster/api/r3apijson.js +++ b/devcluster/api/r3apijson.js @@ -17,6 +17,7 @@ * CREATE: Tue Nov 12 2019 * REVISION: */ + // // This program generates a local.json of k2hr3-api from a k2hr3-utils setup.ini // @@ -24,7 +25,7 @@ const fs = require('fs'); const ACCESSLOGNAME = 'accesslogname'; -const ALLOWCREDAUTH = 'allowcredauth'; +const ALLOWCREDAUTH = 'allowcredauth'; const CA = 'ca'; const CERT = 'cert'; const CHKIPCONFIG_TYPE = 'chkipconfig_type'; @@ -56,11 +57,11 @@ const USERDATA_SCRIPT_TEMPL = 'userdata_script_templ'; const WATCHERLOGNAME = 'watcherlogname'; const WCONSOLELOGNAME = 'watcherlogname'; const CHKIPCONFIGTYPE = { - CHECKER_TYPE_LISTENER:'Listener', - CHECKER_TYPE_FUNCTION:'Function', - CHECKER_TYPE_BASIC_OR:'BasicOr', - CHECKER_TYPE_BASIC_AND:'BasicAnd', - CHECKER_TYPE_NOCHECK:'NoCheck' + CHECKER_TYPE_LISTENER:'Listener', + CHECKER_TYPE_FUNCTION:'Function', + CHECKER_TYPE_BASIC_OR:'BasicOr', + CHECKER_TYPE_BASIC_AND:'BasicAnd', + CHECKER_TYPE_NOCHECK:'NoCheck' }; // @@ -68,417 +69,437 @@ const CHKIPCONFIGTYPE = { // a class to represent k2hr3-api parameters // class R3apiJson { - constructor() { - // properties of this object - this.debug = false; - this.configured = false; - - // k2hr3-api parameters - this.data = { - keystone: { // User authentication type - type: 'openstackapiv3', // module name in lib for openstack keystone access - eptype: 'list', // type of openstack keystone endpoint - epfile: null, - eplist: { - myregion: 'https://dummy.keystone.openstack/' - } - }, - - k2hdkc: { // Slave configuration to K2HDKC cluster - config: '/etc/antpickax/slave.ini', // Configuration file path for k2hdkc(chmpx) slave - port: '8031' // Control port number for k2hdkc(chmpx) slave - }, - - corsips: [ // CORS IP Addresses - '::ffff:127.0.0.1', - '127.0.0.1' - ], - - scheme: 'http', // Scheme - port: 80, // Port - multiproc: true, // Multi processing - runuser: '', // Username for process owner - privatekey: '', // Privatekey file path - cert: '', // Certification file path - ca: '', // CA - - logdir: null, // Path for logging directory - fixedlogdir: null, // Fixed log directory - accesslogname: 'access.log', // Access log name - accesslogform: 'combined', // Access log format by morgan - consolelogname: null, // Console(Error)/Debug log name - watcherlogname: 'watcher.log', // Watcher log name - watchertimeform: 'yyyy/mm/dd HH:MM:ss', // Watcher log time format by dateformat - wconsolelogname: null, // Console(Error)/Debug log name by watcher - logrotateopt: { // rotating-file-stream option object - compress: 'gzip', // gzip : compression method of rotated files. - interval: '6h', // 6 hour : the time interval to rotate the file. - initialRotation: true, // true : initial rotation based on not-rotated file timestamp. - path: null // null : the base path for files.(* this value is replace by 'logdir') - /* - * [NOTE] following option is not specified now. - * - rotationTime: true, // true : makes rotated file name with time of rotation. - highWaterMark: null, // null : proxy to new stream. - history: null, // null : the history filename. - immutable: null, // null : never mutates file names. - maxFiles: null, // null : the maximum number of rotated files to keep. - maxSize: null, // null : the maximum size of rotated files to keep. - mode: null, // null : proxy to fs.createWriteStream - rotate: null, // null : enables the classical UNIX logrotate behaviour. - size: null // null : the file size to rotate the file. - */ - }, - - userdata: { // Userdata for Openstack - baseuri: 'https://localhost', // URI - cc_templ: 'config/k2hr3-cloud-config.txt.templ', // Template for Cloud Config part - script_templ: 'config/k2hr3-init.sh.templ', // Template for Shell part - errscript_templ: 'config/k2hr3-init-error.sh.templ', // Template for common shell if error - algorithm: 'aes-256-cbc', // Encrypt type - passphrase: 'k2hr3_regpass' // Default passphrase - }, - - k2hr3admin: { // K2HR3 Admin information for example is removing IPn Addresses - tenant: 'admintenant', // Admin tenant name - delhostrole: 'delhostrole' // Admin Role name - }, - - confirmtenant: false, // Whichever confirm tenant when adding service member - - chkipconfig: { // IP Addresses checker(watcher) type - type: CHKIPCONFIGTYPE.CHECKER_TYPE_LISTENER, // Listener / Function / Basic{Or|And} / NoCheck - funcmod: null, // Module name(path) for Function type - pendingsec: 864000, // Limit for removing IP which is not alive : 10 * 24 * 60 * 60 = 10 days - intervalms: 4320000, // Interval ms for checking IP address : 12 * 60 * 60 * 1000 = 12 hour - parallelcnt: 32, // Parallel processing count - command4: 'ping', // Basic IP address check use this command for IPv4 : ping command - command6: 'ping6', // Basic IP address check use this command for IPv6 - params: '-c 1', // Common ping command parameters - timeoutparam: '-W', // Timeout parameter name for ping command - timeoutms: 5000 // Timeout millisecond for each checking : 5000ms - }, - allowcredauth: true, // allow CORS access for authorization by credential - - expiration: { // Expiration for Tokens - roletoken: 86400, // Expire time(sec) for RoleToken : 24 * 60 * 60 = 1 day - regroletoken: 315360000 // Expire time(sec) for register host : 10 * 356 * 24 * 60 * 60 = 10 years(no expire) - } - }; - } - - // - // methods - // - - configureAccessLogName(r3apikey, val) { - if (r3apikey.localeCompare(ACCESSLOGNAME) == 0) { - this.data.accesslogname = val; - } - } - - configureAllowCredAuth(r3apikey, val) { - if (r3apikey.localeCompare(ALLOWCREDAUTH) == 0) { - if( val.localeCompare("true") ) { - this.data.allowcredauth = true; - } else { - this.data.allowcredauth = false; - } - } - } - - configureCA(r3apikey, val) { - if (r3apikey.localeCompare(CA) == 0) { - this.data.ca = val; - } - } - - configureCERT(r3apikey, val) { - if (r3apikey.localeCompare(CERT) == 0) { - this.data.cert = val; - } - } - - configureChkConfigType(r3apikey, val) { - if (r3apikey.localeCompare(CHKIPCONFIG_TYPE) == 0) { - this.data.chkipconfig_type = val; - } - } - - configureConfirmTenant(r3apikey, val) { - if (r3apikey.localeCompare(CONFIRMTENANT) == 0) { - if( val.localeCompare("true") ) { - this.data.confirmtenant = true; - } else { - this.data.confirmtenant = false; - } - } - } - - configureConsoleLogName(r3apikey, val) { - if (r3apikey.localeCompare(CONSOLELOGNAME) == 0) { - this.data.consolelogname = val; - } - } - - configureCorsIps(r3apikey, val) { - if (r3apikey.localeCompare(CORSIPS) == 0) { - // NOTE: CORSIPS data is in a csv data like "a=b,c=d" - let iparray = []; - let spos = 0; // startPos - let pos = 0; - do { - pos = val.indexOf(',', spos); - if (this.debug) { - console.log('pos=' + pos); + constructor() { + // properties of this object + this.debug = false; + this.configured = false; + + // k2hr3-api parameters + this.data = { + keystone: { // User authentication type + type: 'openstackapiv3', // module name in lib for openstack keystone access + eptype: 'list', // type of openstack keystone endpoint + epfile: null, + eplist: { + myregion: 'https://dummy.keystone.openstack/' + } + }, + + k2hdkc: { // Slave configuration to K2HDKC cluster + config: '/etc/antpickax/chmpx.ini', // Configuration file path for k2hdkc(chmpx) slave + port: '8031' // Control port number for k2hdkc(chmpx) slave + }, + + corsips: [ // CORS IP Addresses + '::ffff:127.0.0.1', + '127.0.0.1' + ], + + scheme: 'http', // Scheme + port: 80, // Port + multiproc: true, // Multi processing + runuser: '', // Username for process owner + privatekey: '', // Privatekey file path + cert: '', // Certification file path + ca: '', // CA + + logdir: null, // Path for logging directory + fixedlogdir: null, // Fixed log directory + accesslogname: 'access.log', // Access log name + accesslogform: 'combined', // Access log format by morgan + consolelogname: null, // Console(Error)/Debug log name + watcherlogname: 'watcher.log', // Watcher log name + watchertimeform: 'yyyy/mm/dd HH:MM:ss', // Watcher log time format by dateformat + wconsolelogname: null, // Console(Error)/Debug log name by watcher + logrotateopt: { // rotating-file-stream option object + compress: 'gzip', // gzip : compression method of rotated files. + interval: '6h', // 6 hour : the time interval to rotate the file. + initialRotation: true, // true : initial rotation based on not-rotated file timestamp. + path: null // null : the base path for files.(* this value is replace by 'logdir') + + /* + * [NOTE] following option is not specified now. + * + rotationTime: true, // true : makes rotated file name with time of rotation. + highWaterMark: null, // null : proxy to new stream. + history: null, // null : the history filename. + immutable: null, // null : never mutates file names. + maxFiles: null, // null : the maximum number of rotated files to keep. + maxSize: null, // null : the maximum size of rotated files to keep. + mode: null, // null : proxy to fs.createWriteStream + rotate: null, // null : enables the classical UNIX logrotate behaviour. + size: null // null : the file size to rotate the file. + */ + }, + + userdata: { // Userdata for Openstack + baseuri: 'https://localhost', // URI + cc_templ: 'config/k2hr3-cloud-config.txt.templ', // Template for Cloud Config part + script_templ: 'config/k2hr3-init.sh.templ', // Template for Shell part + errscript_templ: 'config/k2hr3-init-error.sh.templ', // Template for common shell if error + algorithm: 'aes-256-cbc', // Encrypt type + passphrase: 'k2hr3_regpass' // Default passphrase + }, + + k2hr3admin: { // K2HR3 Admin information for example is removing IPn Addresses + tenant: 'admintenant', // Admin tenant name + delhostrole: 'delhostrole' // Admin Role name + }, + + confirmtenant: false, // Whichever confirm tenant when adding service member + + chkipconfig: { // IP Addresses checker(watcher) type + type: CHKIPCONFIGTYPE.CHECKER_TYPE_LISTENER, // Listener / Function / Basic{Or|And} / NoCheck + funcmod: null, // Module name(path) for Function type + pendingsec: 864000, // Limit for removing IP which is not alive : 10 * 24 * 60 * 60 = 10 days + intervalms: 4320000, // Interval ms for checking IP address : 12 * 60 * 60 * 1000 = 12 hour + parallelcnt: 32, // Parallel processing count + command4: 'ping', // Basic IP address check use this command for IPv4 : ping command + command6: 'ping6', // Basic IP address check use this command for IPv6 + params: '-c 1', // Common ping command parameters + timeoutparam: '-W', // Timeout parameter name for ping command + timeoutms: 5000 // Timeout millisecond for each checking : 5000ms + }, + + allowcredauth: true, // allow CORS access for authorization by credential + + expiration: { // Expiration for Tokens + roletoken: 86400, // Expire time(sec) for RoleToken : 24 * 60 * 60 = 1 day + regroletoken: 315360000 // Expire time(sec) for register host : 10 * 356 * 24 * 60 * 60 = 10 years(no expire) + } + }; + } + + // + // methods + // + configureAccessLogName(r3apikey, val) { + if (r3apikey.localeCompare(ACCESSLOGNAME) == 0) { + this.data.accesslogname = val; + } + } + + configureAllowCredAuth(r3apikey, val) { + if (r3apikey.localeCompare(ALLOWCREDAUTH) == 0) { + if( val.localeCompare("true") ) { + this.data.allowcredauth = true; + } else { + this.data.allowcredauth = false; + } + } + } + + configureCA(r3apikey, val) { + if (r3apikey.localeCompare(CA) == 0) { + this.data.ca = val; + } + } + + configureCERT(r3apikey, val) { + if (r3apikey.localeCompare(CERT) == 0) { + this.data.cert = val; + } + } + + configureChkConfigType(r3apikey, val) { + if (r3apikey.localeCompare(CHKIPCONFIG_TYPE) == 0) { + this.data.chkipconfig_type = val; + } + } + + configureConfirmTenant(r3apikey, val) { + if (r3apikey.localeCompare(CONFIRMTENANT) == 0) { + if( val.localeCompare("true") ) { + this.data.confirmtenant = true; + } else { + this.data.confirmtenant = false; + } + } + } + + configureConsoleLogName(r3apikey, val) { + if (r3apikey.localeCompare(CONSOLELOGNAME) == 0) { + this.data.consolelogname = val; + } + } + + configureCorsIps(r3apikey, val) { + if (r3apikey.localeCompare(CORSIPS) == 0) { + // NOTE: CORSIPS data is in a csv data like "a=b,c=d" + let iparray = []; + let spos = 0; // startPos + let pos = 0; + do { + pos = val.indexOf(',', spos); + if (this.debug) { + console.log('pos=' + pos); + } + if (pos !== -1) { // found a comma + iparray.push(val.substring(spos, pos)); + } else { + iparray.push(val.substr(spos)); + } + spos = pos + 1; + } while(pos !== -1); + this.data.corsips = iparray; + } + } + + configureK2hdkcConfig(r3apikey, val) { + if (r3apikey.localeCompare(K2HDKC_CONFIG) == 0) { + this.data.k2hdkc.config = val; + } + } + + configureK2hdkcPort(r3apikey, val) { + if (r3apikey.localeCompare(K2HDKC_PORT) == 0) { + this.data.k2hdkc.port = val; + } + } + + configureK2hr3AdminDelhostRole(r3apikey, val) { + if (r3apikey.localeCompare(K2HR3ADMIN_DELHOSTROLE) == 0) { + this.data.k2hr3admin.delhostrole = val; + } + } + + configurek2hr3AdminTenant(r3apikey, val) { + if (r3apikey.localeCompare(K2HR3ADMIN_TENANT) == 0) { + this.data.k2hr3admin.tenant = val; + } + } + + configureKeystoneEpfile(r3apikey, val) { + if (r3apikey.localeCompare(KEYSTONE_EPFILE) == 0) { + this.data.keystone.epfile = val; } - if (pos !== -1) { // found a comma - iparray.push(val.substring(spos, pos)); - } else { - iparray.push(val.substr(spos)); + } + + configureKeystoneEplist(r3apikey, val) { + if (r3apikey.localeCompare(KEYSTONE_EPLIST) == 0) { + this.data.keystone.eplist = val; } - spos = pos + 1; - } while(pos !== -1); - this.data.corsips = iparray; } - } - configureK2hdkcConfig(r3apikey, val) { - if (r3apikey.localeCompare(K2HDKC_CONFIG) == 0) { - this.data.k2hdkc.config = val; + configureKeystoneEptype(r3apikey, val) { + if (r3apikey.localeCompare(KEYSTONE_EPTYPE) == 0) { + this.data.keystone.eptype = val; + } } - } - configureK2hdkcPort(r3apikey, val) { - if (r3apikey.localeCompare(K2HDKC_PORT) == 0) { - this.data.k2hdkc.port = val; + configureKeystonType(r3apikey, val) { + if (r3apikey.localeCompare(KEYSTONE_TYPE) == 0) { + this.data.keystone.type = val; + } } - } - configureK2hr3AdminDelhostRole(r3apikey, val) { - if (r3apikey.localeCompare(K2HR3ADMIN_DELHOSTROLE) == 0) { - this.data.k2hr3admin.delhostrole = val; + configureKeystonTypeOpts(r3apikey, val) { + // if the value of r3apikey is same with the value of keystone type, + // use the r3apikey as the key of the value + if (r3apikey.localeCompare(this.data.keystone.type) == 0) { + var tmp = {[r3apikey] : val}; + this.data = Object.assign(this.data, tmp); + } } - } - configurek2hr3AdminTenant(r3apikey, val) { - if (r3apikey.localeCompare(K2HR3ADMIN_TENANT) == 0) { - this.data.k2hr3admin.tenant = val; + configureLogdir(r3apikey, val) { + if (r3apikey.localeCompare(LOGDIR) == 0) { + this.data.logdir = val; + } } - } - configureKeystoneEpfile(r3apikey, val) { - if (r3apikey.localeCompare(KEYSTONE_EPFILE) == 0) { - this.data.keystone.epfile = val; + configureLogrotateOptCompress(r3apikey, val) { + if (r3apikey.localeCompare(LOGROTATEOPT_COMPRESS) == 0) { + this.data.logrotateopt.compress = val; + } } - } - configureKeystoneEplist(r3apikey, val) { - if (r3apikey.localeCompare(KEYSTONE_EPLIST) == 0) { - this.data.keystone.eplist = val; + configureLogrotateOptInitialRotation(r3apikey, val) { + if (r3apikey.localeCompare(LOGROTATEOPT_INITIALROTATION) == 0) { + if( val.localeCompare("true") ) { + this.data.logrotateopt.initialRotation = true; + } else { + this.data.logrotateopt.initialRotation = false; + } + } } - } - configureKeystoneEptype(r3apikey, val) { - if (r3apikey.localeCompare(KEYSTONE_EPTYPE) == 0) { - this.data.keystone.eptype = val; + configureLogrotateOptInternal(r3apikey, val) { + if (r3apikey.localeCompare(LOGROTATEOPT_INTERVAL) == 0) { + this.data.logrotateopt.interval = val; + } } - } - configureKeystonType(r3apikey, val) { - if (r3apikey.localeCompare(KEYSTONE_TYPE) == 0) { - this.data.keystone.type = val; + configureMultiproc(r3apikey, val) { + if (r3apikey.localeCompare(MULTIPROC) == 0) { + if( val.localeCompare("true") ) { + this.data.multiproc = true; + } else { + this.data.multiproc = false; + } + } } - } - configureLogdir(r3apikey, val) { - if (r3apikey.localeCompare(LOGDIR) == 0) { - this.data.logdir = val; + configurePort(r3apikey, val){ + if (r3apikey.localeCompare(PORT) == 0) { + this.data.port = val; + } } - } - configureLogrotateOptCompress(r3apikey, val) { - if (r3apikey.localeCompare(LOGROTATEOPT_COMPRESS) == 0) { - this.data.logrotateopt.compress = val; + configurePrivatekey(r3apikey, val) { + if (r3apikey.localeCompare(PRIVATEKEY) == 0) { + this.data.privatekey = val; + } } - } - configureLogrotateOptInitialRotation(r3apikey, val) { - if (r3apikey.localeCompare(LOGROTATEOPT_INITIALROTATION) == 0) { - if( val.localeCompare("true") ) { - this.data.logrotateopt.initialRotation = true; - } else { - this.data.logrotateopt.initialRotation = false; - } + configureRunuser(r3apikey, val) { + if (r3apikey.localeCompare(RUNUSER) == 0) { + this.data.runuser = val; + } } - } - configureLogrotateOptInternal(r3apikey, val) { - if (r3apikey.localeCompare(LOGROTATEOPT_INTERVAL) == 0) { - this.data.logrotateopt.interval = val; + configureScheme(r3apikey, val) { + if (r3apikey.localeCompare(SCHEME) == 0) { + this.data.scheme = val; + } } - } - configureMultiproc(r3apikey, val) { - if (r3apikey.localeCompare(MULTIPROC) == 0) { - if( val.localeCompare("true") ) { - this.data.multiproc = true; - } else { - this.data.multiproc = false; - } + configureUserdataAlgorithm(r3apikey, val) { + if (r3apikey.localeCompare(USERDATA_ALGORITHM) == 0) { + this.data.userdata.algorithm = val; + } } - } - configurePort(r3apikey, val){ - if (r3apikey.localeCompare(PORT) == 0) { - this.data.port = val; + configureUserdataBaseUri(r3apikey, val) { + if (r3apikey.localeCompare(USERDATA_BASEURI) == 0) { + this.data.userdata.baseuri = val; + } } - } - configurePrivatekey(r3apikey, val) { - if (r3apikey.localeCompare(PRIVATEKEY) == 0) { - this.data.privatekey = val; + configureUserdataCcTempl(r3apikey, val) { + if (r3apikey.localeCompare(USERDATA_CC_TEMPL) == 0) { + this.data.userdata.cc_templ = val; + } } - } - configureRunuser(r3apikey, val) { - if (r3apikey.localeCompare(RUNUSER) == 0) { - this.data.runuser = val; - } - } + configureUserdataErrScriptTempl(r3apikey, val) { + if (r3apikey.localeCompare(USERDATA_ERRSCRIPT_TEMPL) == 0) { + this.data.userdata.errscript_templ = val; + } + } - configureScheme(r3apikey, val) { - if (r3apikey.localeCompare(SCHEME) == 0) { - this.data.scheme = val; - } - } - - configureUserdataAlgorithm(r3apikey, val) { - if (r3apikey.localeCompare(USERDATA_ALGORITHM) == 0) { - this.data.userdata.algorithm = val; - } - } - - configureUserdataBaseUri(r3apikey, val) { - if (r3apikey.localeCompare(USERDATA_BASEURI) == 0) { - this.data.userdata.baseuri = val; - } - } - - configureUserdataCcTempl(r3apikey, val) { - if (r3apikey.localeCompare(USERDATA_CC_TEMPL) == 0) { - this.data.userdata.cc_templ = val; - } - } - - configureUserdataErrScriptTempl(r3apikey, val) { - if (r3apikey.localeCompare(USERDATA_ERRSCRIPT_TEMPL) == 0) { - this.data.userdata.errscript_templ = val; - } - } - - configureUserdataScriptTempl(r3apikey, val) { - if (r3apikey.localeCompare(USERDATA_SCRIPT_TEMPL) == 0) { - this.data.userdata.script_templ = val; - } - } - - configureWatcherLogname(r3apikey, val) { - if (r3apikey.localeCompare(WATCHERLOGNAME) == 0) { - this.data.watcherlogname = val; - } - } - - configureWconsoleLogname(r3apikey, val) { - if (r3apikey.localeCompare(WCONSOLELOGNAME) == 0) { - this.data.wconsolelogname = val; - } - } - - // configure - // This method binds ini items with json items and it also changes ini item data format to json data format. - // - // Params:: - // $1 data item name, which name starts with "k2hr3_api_" - // $2 value of the item - // - // Returns:: - // true on success - // - configure(key, val) { - let p = key.startsWith('k2hr3_api_'); - if (!p) { - console.log('key is not for k2hr3_api'); - return false; - } - let r3apikey = key.slice(9+1); // strlen(k2hr3_api_) + 1 - this.configureAccessLogName(r3apikey, val); - this.configureAllowCredAuth(r3apikey, val); - this.configureCA(r3apikey, val); - this.configureCERT(r3apikey, val); - this.configureChkConfigType(r3apikey, val); - this.configureConfirmTenant(r3apikey, val); - this.configureConsoleLogName(r3apikey, val); - this.configureCorsIps(r3apikey, val); - this.configureK2hdkcConfig(r3apikey, val); - this.configureK2hdkcPort(r3apikey, val); - this.configureK2hr3AdminDelhostRole(r3apikey, val); - this.configurek2hr3AdminTenant(r3apikey, val); - this.configureKeystoneEpfile(r3apikey, val); - this.configureKeystoneEplist(r3apikey, val); - this.configureKeystoneEptype(r3apikey, val); - this.configureKeystonType(r3apikey, val); - this.configureLogdir(r3apikey, val); - this.configureLogrotateOptCompress(r3apikey, val); - this.configureLogrotateOptInitialRotation(r3apikey, val); - this.configureLogrotateOptInternal(r3apikey, val); - this.configureMultiproc(r3apikey, val); - this.configurePort(r3apikey, val); - this.configurePrivatekey(r3apikey, val); - this.configureRunuser(r3apikey, val); - this.configureScheme(r3apikey, val); - this.configureUserdataAlgorithm(r3apikey, val); - this.configureUserdataBaseUri(r3apikey, val); - this.configureUserdataCcTempl(r3apikey, val); - this.configureUserdataErrScriptTempl(r3apikey, val); - this.configureUserdataScriptTempl(r3apikey, val); - this.configureWatcherLogname(r3apikey, val); - this.configureWconsoleLogname(r3apikey, val); - this.configured = true; - } - - // dump - // This method writes k2hr3-api data to a json file. - // - // Params:: - // $1 path of a json file - // - // Returns:: - // true on success - // - dumpTo(path) { - if (!this.configured) { - console.error("have not configured yet."); - return false; - } - var jsondata = JSON.stringify(this, null, ' '); - if (jsondata) { - fs.writeFileSync(path, jsondata); - } - return true; - } - - // toJSON - // This method is called back from JSON.stringify - // - // Returns:: - // a json object of k2hr3-api data - // - toJSON() { - return this.data; - } + configureUserdataScriptTempl(r3apikey, val) { + if (r3apikey.localeCompare(USERDATA_SCRIPT_TEMPL) == 0) { + this.data.userdata.script_templ = val; + } + } + + configureWatcherLogname(r3apikey, val) { + if (r3apikey.localeCompare(WATCHERLOGNAME) == 0) { + this.data.watcherlogname = val; + } + } + + configureWconsoleLogname(r3apikey, val) { + if (r3apikey.localeCompare(WCONSOLELOGNAME) == 0) { + this.data.wconsolelogname = val; + } + } + + // configure + // This method binds ini items with json items and it also changes ini item data format to json data format. + // + // Params:: + // $1 data item name, which name starts with "k2hr3_api_" + // $2 value of the item + // + // Returns:: + // true on success + // + configure(key, val) { + let p = key.startsWith('k2hr3_api_'); + if (!p) { + console.log('key is not for k2hr3_api'); + return false; + } + let r3apikey = key.slice(9+1); // strlen(k2hr3_api_) + 1 + this.configureAccessLogName(r3apikey, val); + this.configureAllowCredAuth(r3apikey, val); + this.configureCA(r3apikey, val); + this.configureCERT(r3apikey, val); + this.configureChkConfigType(r3apikey, val); + this.configureConfirmTenant(r3apikey, val); + this.configureConsoleLogName(r3apikey, val); + this.configureCorsIps(r3apikey, val); + this.configureK2hdkcConfig(r3apikey, val); + this.configureK2hdkcPort(r3apikey, val); + this.configureK2hr3AdminDelhostRole(r3apikey, val); + this.configurek2hr3AdminTenant(r3apikey, val); + this.configureKeystoneEpfile(r3apikey, val); + this.configureKeystoneEplist(r3apikey, val); + this.configureKeystoneEptype(r3apikey, val); + this.configureKeystonType(r3apikey, val); + this.configureKeystonTypeOpts(r3apikey, val); + this.configureLogdir(r3apikey, val); + this.configureLogrotateOptCompress(r3apikey, val); + this.configureLogrotateOptInitialRotation(r3apikey, val); + this.configureLogrotateOptInternal(r3apikey, val); + this.configureMultiproc(r3apikey, val); + this.configurePort(r3apikey, val); + this.configurePrivatekey(r3apikey, val); + this.configureRunuser(r3apikey, val); + this.configureScheme(r3apikey, val); + this.configureUserdataAlgorithm(r3apikey, val); + this.configureUserdataBaseUri(r3apikey, val); + this.configureUserdataCcTempl(r3apikey, val); + this.configureUserdataErrScriptTempl(r3apikey, val); + this.configureUserdataScriptTempl(r3apikey, val); + this.configureWatcherLogname(r3apikey, val); + this.configureWconsoleLogname(r3apikey, val); + this.configured = true; + } + + // dump + // This method writes k2hr3-api data to a json file. + // + // Params:: + // $1 path of a json file + // + // Returns:: + // true on success + // + dumpTo(path) { + if (!this.configured) { + console.error("have not configured yet."); + return false; + } + var jsondata = JSON.stringify(this, null, ' '); + if (jsondata) { + fs.writeFileSync(path, jsondata); + } + return true; + } + + // toJSON + // This method is called back from JSON.stringify + // + // Returns:: + // a json object of k2hr3-api data + // + toJSON() { + return this.data; + } } module.exports = { - R3apiJson + R3apiJson } + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/devcluster/api/r3clusterini.js b/devcluster/api/r3clusterini.js index 42c144f..838b65b 100644 --- a/devcluster/api/r3clusterini.js +++ b/devcluster/api/r3clusterini.js @@ -17,107 +17,147 @@ * CREATE: Tue Nov 12 2019 * REVISION: */ + // // This program generates a local.json of k2hr3-api from a k2hr3-utils setup.ini // 'use strict'; const fs = require('fs'); -//const path = require('path'); -//const srcdir = path.resolve(__dirname); +const path = require('path'); +const srcdir = path.resolve(__dirname); // // R3clusterIni // represents cluster ini file // class R3clusterIni { - // - // Params:: - // $1 a path to k2hr3_utils ini file - // $2 k2hr3_api or k2hr3_app) - // - // Returns:: - // a R3clusterIni object on success - // throws exception on failure - // - constructor(ini, component) { - // properties - this.index = 0; // position of data processing - this.debug = false; - this.component = component || ''; // k2hr3-api or k2hr3-app - - // cluster parameters - this.ini = ini || 'setup.ini'; - this.keys = []; - this.vals = []; - - // parses a ini file and puts them to the key and value array members - try { - let buf = fs.readFileSync(this.ini, "utf8"); - // 1. split data by a line feed - let p = buf.indexOf('\n'); - do { - if (p !== -1) { - const line = buf.slice(0, p); - if (this.debug) { - console.log('line=' + line); - } - let pos = line.indexOf('='); - if (pos !== -1) { - let key = line.substring(0, pos); - if (typeof key === 'string' && key.length !== 0) { - let val = line.substring(pos + 1); - if (this.debug) { - console.log('key=' + key + ' val=' + val); - } - // 2. picks up data of the component only - if (key.startsWith(component)) { - this.keys.push(key); - this.vals.push(val); - } - } - } - buf = buf.slice(p + 1); + // + // Params:: + // $1 a path to k2hr3_utils ini file + // $2 k2hr3_api or k2hr3_app) + // + // Returns:: + // a R3clusterIni object on success + // throws exception on failure + // + constructor(ini, component) { + // properties + this.index = 0; // position of data processing + this.debug = false; + this.component = component || ''; // k2hr3-api or k2hr3-app + + // cluster parameters + this.ini = ini || 'setup.ini'; + this.keys = []; + this.vals = []; + + // parses a ini file and puts them to the key and value array members + try { + let buf = fs.readFileSync(this.ini, "utf8"); + + // 1. split data by a line feed + let p = buf.indexOf('\n'); + do { + if (p !== -1) { + const line = buf.slice(0, p); + if (this.debug) { + console.log('line=' + line); + } + + let pos = line.indexOf('='); + if (pos !== -1) { + let key = line.substring(0, pos); + if (typeof key === 'string' && key.length !== 0) { + let val = line.substring(pos + 1); + if (this.debug) { + console.log('key=' + key + ' val=' + val); + } + + // 2. picks up data of the component only + if (key.startsWith(component)) { + this.keys.push(key); + this.vals.push(val); + } + if (key.localeCompare("env") == 0) { + this.env = val; + } + } + } + buf = buf.slice(p + 1); + } + p = buf.indexOf('\n'); + } while(p !== -1); + } catch (err) { + console.error(err.name + ' ' + err.message); + throw err; + } + + // defines data.somedata if r3clusterini_k2hr3_api_ext.js exists. + try { + let extfile = path.join(srcdir, 'r3clusterini_k2hr3_api_ext.js'); + fs.accessSync(extfile, fs.constants.R_OK); + + // 1. filename + // r3clusterini_k2hr3_api_ext.js + + // 2. class name + // R3initExtraData + + // 3. methods + // getData + const extData = require(extfile); + let instance = new extData.R3iniExtraData(); + console.log(this.env); + console.log('instance.setEnv(this.env)'); + instance.setEnv(this.env); + this.keys.push(instance.getKey()); + this.vals.push(instance.getData()); + } catch (err) { + console.log('no access to r3clusterini_k2hr3_api_ext.js, just skipping it;)'); } - p = buf.indexOf('\n'); - } while(p !== -1); - } catch (err) { - console.error(err.name + ' ' + err.message); - throw err; } - } - - // - // methods - // - // next method - // iterates the key and value array - // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Iteration_protocols - // - // Returns:: - // a pair of a key and a value - // - [Symbol.iterator]() { - return { - next: () => { - if (this.index < this.keys.length) { - let pos = this.index++; - return {value: [this.keys[pos], this.vals[pos]], done: false}; - } else { - this.index = 0; - return {done: true}; + + // + // methods + // + // next method + // iterates the key and value array + // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Iteration_protocols + // + // Returns:: + // a pair of a key and a value + // + [Symbol.iterator]() { + return { + next: () => { + if (this.index < this.keys.length) { + let pos = this.index++; + return {value: [this.keys[pos], this.vals[pos]], done: false}; + } else { + this.index = 0; + return {done: true}; + } + } } - } } - } } // for debug -//var cluster = new R3clusterIni(path.join(srcdir, 'setup_app_centos.ini'), 'k2hr3_api'); -//for (const val of cluster) { -// console.log(val); -//} +// var cluster = new R3clusterIni(path.join(srcdir, 'setup_api_centos.ini'), 'k2hr3_api'); +// for (const val of cluster) { +// console.log(val); +// } module.exports = { - R3clusterIni + R3clusterIni } + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/devcluster/api/setup_api.sh b/devcluster/api/setup_api.sh index d7f21e0..2b9bbf1 100644 --- a/devcluster/api/setup_api.sh +++ b/devcluster/api/setup_api.sh @@ -48,30 +48,30 @@ NPM_ARCHIVE_FILE= IDENTITY_ENDPOINT= if ! test -r "${SRCDIR}/../cluster_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" + exit 1 fi . ${SRCDIR}/../cluster_functions # Parses cli args while true; do - case "${1-}" in - -d) DEBUG=1;; - -f) shift; NPM_ARCHIVE_FILE="${1-}";; - -h) usage_api;; - -i) shift; IDENTITY_ENDPOINT="${1-}";; - -r) DRYRUN=1;; - -v) version;; - *) break;; - esac - shift + case "${1-}" in + -d) DEBUG=1;; + -f) shift; NPM_ARCHIVE_FILE="${1-}";; + -h) usage_api;; + -i) shift; IDENTITY_ENDPOINT="${1-}";; + -r) DRYRUN=1;; + -v) version;; + *) break;; + esac + shift done # Determines the debug mode if test "${DEBUG}" -eq 1; then - TAG="$(basename $0) -s" + TAG="$(basename $0) -s" else - TAG=$(basename $0) + TAG=$(basename $0) fi # The first message is always visible. @@ -87,35 +87,35 @@ logger -t ${TAG} -p user.info "1. Initializes environments" setup_os_env RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_os_env should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_os_env should return zero, not ${RET}" + exit 1 fi # Loads default settings setup_ini_env RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" + exit 1 fi # IDENTITY_ENDPOINT passed as an argument will override k2hr3_api_identity_endpoint defined in the ini file. if test -n "${IDENTITY_ENDPOINT}"; then - k2hr3_api_identity_endpoint=${IDENTITY_ENDPOINT} - # update the value in setup_${COMPONENT}_${OS_NAME}.ini. - for ini_file in ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ${SRCDIR}/setup_${COMPONENT}_default.ini; do - if test -f "${ini_file}"; then - logger -t ${TAG} -p user.debug "configure_ini_file ${ini_file} k2hr3_api_identity_endpoint" - configure_ini_file ${ini_file} k2hr3_api_identity_endpoint - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" - exit 1 - fi - else - logger -t ${TAG} -p user.warn "${ini_file} not found. Skip updating" - fi - done + k2hr3_api_identity_endpoint=${IDENTITY_ENDPOINT} + # update the value in setup_${COMPONENT}_${OS_NAME}.ini. + for ini_file in ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ${SRCDIR}/setup_${COMPONENT}_default.ini; do + if test -f "${ini_file}"; then + logger -t ${TAG} -p user.debug "configure_ini_file ${ini_file} k2hr3_api_identity_endpoint" + configure_ini_file ${ini_file} k2hr3_api_identity_endpoint + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" + exit 1 + fi + else + logger -t ${TAG} -p user.warn "${ini_file} not found. Skip updating" + fi + done fi ######## @@ -126,8 +126,8 @@ logger -t ${TAG} -p user.info "2. Ensures that the k2hr3_api data directory exis # Loads functions defined in setup_chmpx_functions if ! test -r "${SRCDIR}/../chmpx/setup_chmpx_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../chmpx/setup_chmpx_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../chmpx/setup_chmpx_functions should exist" + exit 1 fi . ./chmpx/setup_chmpx_functions @@ -137,8 +137,8 @@ runuser=$(eval echo "\${$runuser_varname}") make_k2hdkc_data_dir ${runuser} ${k2hdkc_data_dir} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "make_k2hdkc_data_dir should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "make_k2hdkc_data_dir should return zero, not ${RET}" + exit 1 fi ######## @@ -152,8 +152,8 @@ k2hdkc_conf_dir=$(dirname ${chmpx_conf_file}) make_k2hdkc_conf_dir ${k2hdkc_conf_dir} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "make_k2hdkc_conf_dir should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "make_k2hdkc_conf_dir should return zero, not ${RET}" + exit 1 fi ######## @@ -166,26 +166,26 @@ logger -t ${TAG} -p user.info "4. Adds a new package repository" enable_packagecloud_io_repository ${package_script_base_url-} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_packagecloud_io_repository should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "enable_packagecloud_io_repository should return zero, not ${RET}" + exit 1 fi # Enables the nodesource repo enable_nodesource_repository ${nodesource_url-} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_nodesource_repository should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "enable_nodesource_repository should return zero, not ${RET}" + exit 1 fi # Enables the softwarecollections repo if test "${OS_NAME}" = "centos"; then - setup_package_repository ${copr_url-} - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_package_repository should return zero, not ${RET}" - exit 1 - fi + setup_package_repository ${copr_url-} + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_package_repository should return zero, not ${RET}" + exit 1 + fi fi ######## @@ -198,77 +198,62 @@ logger -t ${TAG} -p user.info "5. Installs OS dependent packages" # define empty ${package_install_pkg} value in their initial configuration file. # We call the setup_install_os_packages function if package_install_pkgs defined. if test -n "${package_install_pkgs-}"; then - setup_install_os_packages "${package_install_pkgs-}" - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" - exit 1 - fi + setup_install_os_packages "${package_install_pkgs-}" + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" + exit 1 + fi else - logger -t ${TAG} -p user.err "package_install_pkgs is zero" + logger -t ${TAG} -p user.err "package_install_pkgs is zero" fi ######## # 6. Configures the chmpx slave default configuration -# The default slave.ini contains dummy server name. You need to change it. +# The default chmpx.ini contains dummy server name. You need to change it. # logger -t ${TAG} -p user.info "6. Configures the default chmpx slave configuration" # Configures the chmpx slave default configuration file in INI file format -configure_chmpx_slave_ini ${SRCDIR}/../chmpx/slave.ini ${chmpx_server_name} +configure_chmpx_chmpx_ini ${SRCDIR}/../chmpx/chmpx.ini ${chmpx_server_name} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "configure_chmpx_slave_ini should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "configure_chmpx_chmpx_ini should return zero, not ${RET}" + exit 1 fi ######## # 7. Installs the configured chmpx slave config file -# k2hr3_api uses a configuration file(for instance /etc/k2hdkc/slave.ini) for chmpx. +# k2hr3_api uses a configuration file(for instance /etc/k2hdkc/chmpx.ini) for chmpx. # logger -t ${TAG} -p user.info "7. Installs the configured chmpx slave config file" # Installs the configured chmpx slave config file in INI format to ${chmpx_conf_file} -install_chmpx_conf ${SRCDIR}/../chmpx/slave.ini ${chmpx_conf_file} +install_chmpx_conf ${SRCDIR}/../chmpx/chmpx.ini ${chmpx_conf_file} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_chmpx_conf should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "install_chmpx_conf should return zero, not ${RET}" + exit 1 fi -######## -# 8. Configures the chmpx slave's service manager default configuration -# We recommend chmpx slave process works as a service by systemd. -# -logger -t ${TAG} -p user.info "8. Configures the chmpx slave's service manager default configuration" - -# Determines the service management file which file format depends on a service manager of the target OS -if test "${SERVICE_MANAGER}" = "systemd"; then - service_manager_file=${SRCDIR}/../service_manager/chmpx-slave.service -else - logger -t ${TAG} -p user.err "SERVICE_MANAGER must be either systemd, not ${SERVICE_MANAGER}" - exit 1 -fi -# Configures the chmpx's service manager default configuration -is_k2hdkc=0 -configure_chmpx_service_manager_file ${SERVICE_MANAGER} ${service_manager_file} ${k2hr3_api_runuser} ${chmpx_conf_file} ${chmpx_msg_max} ${is_k2hdkc} ${chmpx_loglevel} -RET=$? -if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "configure_chmpx_service_manager_file should return zero, not ${RET}" - exit 1 -fi - -######## -# 9. Installs the chmpx-slave service manager configuration and enables it -# systemd controls chmpx. -# -logger -t ${TAG} -p user.info "9. Installs the chmpx-slave service manager configuration and enables it" - -install_service_manager_conf ${SERVICE_MANAGER} chmpx-slave -RET=$? -if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_service_manager_conf should return zero, not ${RET}" - exit 1 +# Installs the override.conf to ${chmpx_override_conf_file} +if test -f "${SRCDIR}/../chmpx/override.conf"; then + # 1. replaces k2hdkc.ini with chmpx.ini + # FIXME hardcoding + logger -t ${TAG} -p user.debug "perl -pi -e \"s|= k2hdkc.ini|= chmpx.ini|g\" ${SRCDIR}/../chmpx/override.conf" + perl -pi -e "s|= k2hdkc.ini|= chmpx.ini|g" ${SRCDIR}/../chmpx/override.conf + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + # 2. installs override.conf + install_chmpx_conf ${SRCDIR}/../chmpx/override.conf ${chmpx_override_conf_file} + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "install_chmpx_conf should return zero, not ${RET}" + exit 1 + fi fi ######## @@ -278,15 +263,15 @@ fi logger -t ${TAG} -p user.info "10. Installs devel packages to build the k2hdkc node module" if test -n "${package_install_dev_pkgs}"; then - setup_install_os_packages "${package_install_dev_pkgs}" - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" - exit 1 - fi + setup_install_os_packages "${package_install_dev_pkgs}" + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" + exit 1 + fi else - logger -t ${TAG} -p user.err "package_install_dev_pkgs should be nonzero, ${package_install_dev_pkgs}" - exit 1 + logger -t ${TAG} -p user.err "package_install_dev_pkgs should be nonzero, ${package_install_dev_pkgs}" + exit 1 fi ######## @@ -298,21 +283,21 @@ fi logger -t ${TAG} -p user.info "11. Installs npm packages" if ! test -n "${npm_default_user}"; then - logger -t ${TAG} -p user.err "npm_default_user should be nonzero, ${npm_default_user}" - exit 1 + logger -t ${TAG} -p user.err "npm_default_user should be nonzero, ${npm_default_user}" + exit 1 fi add_npm_user ${npm_default_user} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "add_npm_user should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "add_npm_user should return zero, not ${RET}" + exit 1 fi setup_npm_userhome ${npm_default_user} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_npm_userhome should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_npm_userhome should return zero, not ${RET}" + exit 1 fi # Runs api/setup_api_node_module.sh as node command executer @@ -320,19 +305,19 @@ node_api_module_sh="${SRCDIR}/setup_api_node_module.sh" # Adds the DEBUG option if DEBUG is enabled if test "${DEBUG}" -eq 1; then - node_api_module_sh="${node_api_module_sh} -d" + node_api_module_sh="${node_api_module_sh} -d" fi # Adds the NPM_ARCHIVE_FILE option if NPM_ARCHIVE_FILE exists if test -n "${NPM_ARCHIVE_FILE}"; then - if test -f "${NPM_ARCHIVE_FILE}"; then - # Remenber to call 'basename' function - # Because an archive file stays /home/k2hr3/k2hr3-api-0.0.1.tgz - node_api_module_sh="${node_api_module_sh} -f $(basename ${NPM_ARCHIVE_FILE})" - else - logger -t ${TAG} -p user.err "${NPM_ARCHIVE_FILE} must be a URL" - node_api_module_sh="${node_api_module_sh} -f ${NPM_ARCHIVE_FILE}" - fi + if test -f "${NPM_ARCHIVE_FILE}"; then + # Remenber to call 'basename' function + # Because an archive file stays /home/k2hr3/k2hr3-api-0.0.1.tgz + node_api_module_sh="${node_api_module_sh} -f $(basename ${NPM_ARCHIVE_FILE})" + else + logger -t ${TAG} -p user.err "${NPM_ARCHIVE_FILE} must be a URL" + node_api_module_sh="${node_api_module_sh} -f ${NPM_ARCHIVE_FILE}" + fi fi ######## @@ -347,12 +332,12 @@ fi # $ sudo su - k2hr3 sh -c "sh ./setup_api_node_module.sh -d" logger -t ${TAG} -p user.debug "sudo su - ${npm_default_user} sh -c \"${node_api_module_sh}\"" if test -z "${DRYRUN-}"; then - sudo su - ${npm_default_user} sh -c "sh ${node_api_module_sh}" - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - exit 1 - fi + sudo su - ${npm_default_user} sh -c "sh ${node_api_module_sh}" + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + exit 1 + fi fi # A workaround for root owner logs in the ${npm_run_user} directory @@ -367,8 +352,8 @@ fi patch_for_change_logdir_owner ${npm_default_user} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_npm_userhome should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_npm_userhome should return zero, not ${RET}" + exit 1 fi ######## @@ -378,24 +363,24 @@ fi logger -t ${TAG} -p user.info "14. Configures the k2hr3-api's service manager default configuration" if ! test -r "${SRCDIR}/setup_${COMPONENT}_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/setup_${COMPONENT}_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/setup_${COMPONENT}_functions should exist" + exit 1 fi . ${SRCDIR}/setup_${COMPONENT}_functions # Determines the service management file which file format depends on a service manager of the target OS if test "${SERVICE_MANAGER}" = "systemd"; then - service_manager_file=${SRCDIR}/../service_manager/k2hr3-api.service + service_manager_file=${SRCDIR}/../service_manager/k2hr3-api.service else - logger -t ${TAG} -p user.err "SERVICE_MANAGER must be either systemd, not ${SERVICE_MANAGER}" - exit 1 + logger -t ${TAG} -p user.err "SERVICE_MANAGER must be either systemd, not ${SERVICE_MANAGER}" + exit 1 fi # Configures the k2hr3-api's service manager default configuration configure_k2hr3_api_service_manager_file ${SERVICE_MANAGER} ${service_manager_file} ${k2hr3_api_runuser} ${node_debug} ${node_path} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "configure_k2hr3_api_service_manager_file should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "configure_k2hr3_api_service_manager_file should return zero, not ${RET}" + exit 1 fi ######## @@ -407,21 +392,28 @@ logger -t ${TAG} -p user.info "15. Installs the k2hr3-api service manager config install_service_manager_conf ${SERVICE_MANAGER} k2hr3-api RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_service_manager_conf should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "install_service_manager_conf should return zero, not ${RET}" + exit 1 fi ######## # Start the service! # -logger -t ${TAG} -p user.debug "sudo systemctl restart chmpx-slave.service" +logger -t ${TAG} -p user.debug "sudo systemctl enable chmpx.service" if test -z "${DRYRUN-}"; then - sudo systemctl restart chmpx-slave.service - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "'sudo systemctl restart chmpx-slave.service' should return zero, not ${RESULT}" - exit 1 - fi + sudo systemctl enable chmpx.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "'sudo systemctl enable chmpx.service' should return zero, not ${RESULT}" + exit 1 + fi + logger -t ${TAG} -p user.debug "sudo systemctl start chmpx.service" + sudo systemctl start chmpx.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "'sudo systemctl start chmpx.service' should return zero, not ${RESULT}" + exit 1 + fi fi # A workaround for an old configuration value in k2hdkc @@ -430,7 +422,7 @@ fi # "eplist" takes a region name as a key and an Identity service endpoint as a value. # ``` # "eplist": { -# "RegionOne": "http://172.16.0.1/identity" +# "RegionOne": "http://172.16.0.1/identity" # } # ``` # k2hr3-api saves the value as a subkey of "yrn:yahoo::::keystone" in k2hdkc. @@ -442,32 +434,32 @@ fi # Deletes the region name key in cluster installation process. Every deployment # script should work idempotently for continuous integration. # -logger -t ${TAG} -p user.debug "sleep 20 for chmpx-slave to start the service" +logger -t ${TAG} -p user.debug "sleep 20 for chmpx to start the service" if test -z "${DRYRUN-}"; then - sleep 20 - DATAFILE=/tmp/devcluster.data - cat >> ${DATAFILE} << EOF + sleep 20 + DATAFILE=/tmp/devcluster.data + cat >> ${DATAFILE} << EOF p yrn:yahoo::::keystone rmsub yrn:yahoo::::keystone all quit EOF - logger -t ${TAG} -p user.debug "sudo -u ${k2hr3_api_runuser} k2hdkclinetool -conf ${k2hr3_api_k2hdkc_config} -ctlport ${k2hr3_api_k2hdkc_port} -run ${DATAFILE}" - sudo -u ${k2hr3_api_runuser} k2hdkclinetool -conf ${k2hr3_api_k2hdkc_config} -ctlport ${k2hr3_api_k2hdkc_port} -run ${DATAFILE} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "k2hdkclinetool should return zero, not ${RESULT}" - exit 1 - fi - - - logger -t ${TAG} -p user.debug "sudo systemctl restart k2hr3-${COMPONENT}.service" - sudo systemctl restart k2hr3-${COMPONENT}.service - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "'sudo systemctl restart k2hr3-${COMPONENT}.service' should return zero, not ${RESULT}" - exit 1 - fi + logger -t ${TAG} -p user.debug "sudo -u ${k2hr3_api_runuser} k2hdkclinetool -conf ${k2hr3_api_k2hdkc_config} -ctlport ${k2hr3_api_k2hdkc_port} -run ${DATAFILE}" + sudo -u ${k2hr3_api_runuser} k2hdkclinetool -conf ${k2hr3_api_k2hdkc_config} -ctlport ${k2hr3_api_k2hdkc_port} -run ${DATAFILE} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "k2hdkclinetool should return zero, not ${RESULT}" + exit 1 + fi + + + logger -t ${TAG} -p user.debug "sudo systemctl restart k2hr3-${COMPONENT}.service" + sudo systemctl restart k2hr3-${COMPONENT}.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "'sudo systemctl restart k2hr3-${COMPONENT}.service' should return zero, not ${RESULT}" + exit 1 + fi fi # The final message displays the time elapsed. @@ -477,7 +469,10 @@ logger -t $(basename $0) -s -p user.info "completed in ${ELAPSED} seconds" exit 0 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/api/setup_api_centos.ini b/devcluster/api/setup_api_centos.ini index 96344c6..a61d268 100644 --- a/devcluster/api/setup_api_centos.ini +++ b/devcluster/api/setup_api_centos.ini @@ -38,11 +38,14 @@ npm_global_dir=/home/k2hr3/.npm-global #[package] package_script_base_url=https://packagecloud.io/install/repositories/antpickax/stable package_install_pkgs="nodejs k2htpdtor libfullock k2hash chmpx k2hdkc" -package_install_dev_pkgs="libfullock-devel k2hash-devel chmpx-devel k2hdkc-devel" +package_install_dev_pkgs="devtoolset-7 python3 libfullock-devel k2hash-devel chmpx-devel k2hdkc-devel" nodesource_url=https://rpm.nodesource.com/setup_10.x # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/api/setup_api_debian.ini b/devcluster/api/setup_api_debian.ini index da5de6c..29a50b2 100644 --- a/devcluster/api/setup_api_debian.ini +++ b/devcluster/api/setup_api_debian.ini @@ -42,7 +42,10 @@ nodesource_url=https://deb.nodesource.com/setup_10.x package_install_dev_pkgs="g++ make libfullock-dev k2hash-dev chmpx-dev k2hdkc-dev" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/api/setup_api_default.ini b/devcluster/api/setup_api_default.ini index 6a58e16..0f98ac6 100644 --- a/devcluster/api/setup_api_default.ini +++ b/devcluster/api/setup_api_default.ini @@ -19,11 +19,11 @@ #[chmpx] chmpx_msg_max=1024 -chmpx_conf_file=/etc/antpickax/slave.ini -chmpx_systemd_unit_file=/etc/systemd/system/chmpx-slave.service +chmpx_conf_file=/etc/antpickax/chmpx.ini chmpx_server_name=localhost k2hdkc_data_dir=/var/k2hdkc/data chmpx_loglevel=dump +chmpx_override_conf_file=/etc/antpickax/override.conf #[k2hr3_api] k2hr3_api_region=RegionOne @@ -42,7 +42,7 @@ k2hr3_api_k2hr3admin_tenant=demo k2hr3_api_k2hr3admin_delhostrole=delhostrole k2hr3_api_confirmtenant=false k2hr3_api_allowcredauth=true -k2hr3_api_k2hdkc_config="/etc/antpickax/slave.ini" +k2hr3_api_k2hdkc_config="/etc/antpickax/chmpx.ini" k2hr3_api_k2hdkc_port=8031 # [node] @@ -61,7 +61,10 @@ package_install_dev_pkgs="devtoolset-7 libfullock-devel k2hash-devel chmpx-devel copr_url="https://copr.fedorainfracloud.org/coprs/rhscl/centos-release-scl/repo/epel-7/rhscl-centos-release-scl-epel-7.repo" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/api/setup_api_fedora.ini b/devcluster/api/setup_api_fedora.ini index c0cbb78..5a927d6 100644 --- a/devcluster/api/setup_api_fedora.ini +++ b/devcluster/api/setup_api_fedora.ini @@ -41,7 +41,10 @@ nodesource_url=https://rpm.nodesource.com/setup_10.x package_install_dev_pkgs="gcc-c++ libfullock-devel k2hash-devel chmpx-devel k2hdkc-devel" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/api/setup_api_functions b/devcluster/api/setup_api_functions index 50a85e7..99a4898 100644 --- a/devcluster/api/setup_api_functions +++ b/devcluster/api/setup_api_functions @@ -35,65 +35,74 @@ # This function is designed for unit tests. # configure_k2hr3_api_service_manager_file() { - _service_manager=${1:?"service_manager should be nonzero"} - _service_manager_file=${2:?"service_manager_file should be nonzero"} - _k2hr3_api_runuser=${3:?"k2hr3_api_runner should be nonzero. Check if it is defined in setup_api_*.ini"} - _node_debug=${4:-LOGLEVEL_ERR} - _node_path=${5:-/usr/bin/node} + _service_manager=${1:?"service_manager should be nonzero"} + _service_manager_file=${2:?"service_manager_file should be nonzero"} + _k2hr3_api_runuser=${3:?"k2hr3_api_runner should be nonzero. Check if it is defined in setup_api_*.ini"} + _node_debug=${4:-LOGLEVEL_ERR} + _node_path=${5:-/usr/bin/node} - logger -t ${TAG} -p user.debug "configure_k2hr3_api_service_manager_file _service_manager=${_service_manager} _service_manager_file=${_service_manager_file} _k2hr3_api_runuser=${_k2hr3_api_runuser} _node_debug=${_node_debug} _node_path=${_node_path}" + logger -t ${TAG} -p user.debug "configure_k2hr3_api_service_manager_file _service_manager=${_service_manager} _service_manager_file=${_service_manager_file} _k2hr3_api_runuser=${_k2hr3_api_runuser} _node_debug=${_node_debug} _node_path=${_node_path}" - if ! test -f "${service_manager_file}"; then - logger -t ${TAG} -p user.err "${_service_manager_file} should exist" - return 1 - fi + if ! test -f "${service_manager_file}"; then + logger -t ${TAG} -p user.err "${_service_manager_file} should exist" + return 1 + fi - if test "${_service_manager}" = "systemd"; then - if test -n "${_k2hr3_api_runuser}"; then - NPM_USER_HOME=$(eval echo "~${_k2hr3_api_runuser}") - # Replaces "WorkingDirectory=/home/k2hr3" with a user defined value - logger -t ${TAG} -p user.debug "perl -pi -e \"s|WorkingDirectory=.*$|WorkingDirectory=${NPM_USER_HOME}|g\" ${_service_manager_file}" - perl -pi -e "s|WorkingDirectory=.*$|WorkingDirectory=${NPM_USER_HOME}|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - # Replaces "Environment=HOME=/home/k2hr3" with a user defined value - logger -t ${TAG} -p user.debug "perl -pi -e \"s|Environment=HOME=.*$|Environment=HOME=${NPM_USER_HOME}|g\" ${_service_manager_file}" - perl -pi -e "s|Environment=HOME=.*$|Environment=HOME=${NPM_USER_HOME}|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - # Replaces "Environment=NODE_DEBUG=LOGLEVEL_ERR" with Environment=NODE_DEBUG=${_node_debug} - logger -t ${TAG} -p user.debug "perl -pi -e \"s|Environment=NODE_DEBUG=.*$|Environment=NODE_DEBUG=${_node_debug}|g\" ${_service_manager_file}" - perl -pi -e "s|Environment=NODE_DEBUG=.*$|Environment=NODE_DEBUG=${_node_debug}|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - # Replaces "ExecStart=/usr/bin/node /home/k2hr3/k2hr3-api/bin/www" with ExecStart=${_node_path} /home/k2hr3/k2hr3-api/bin/www - logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStart=.*$|ExecStart=${_node_path} ${NPM_USER_HOME}/k2hr3-api/bin/www|g\" ${_service_manager_file}" - perl -pi -e "s|ExecStart=.*$|ExecStart=${_node_path} ${NPM_USER_HOME}/k2hr3-api/bin/www|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "k2hr3_api_runuser must be nonzero" - return 1 - fi - else - logger -t ${TAG} -p user.err "SERVICE_MANAGER is either systemd, not ${SERVICE_MANAGER}" - return 1 - fi - return 0 + if test "${_service_manager}" = "systemd"; then + if test -n "${_k2hr3_api_runuser}"; then + NPM_USER_HOME=$(eval echo "~${_k2hr3_api_runuser}") + + # Replaces "WorkingDirectory=/home/k2hr3" with a user defined value + logger -t ${TAG} -p user.debug "perl -pi -e \"s|WorkingDirectory=.*$|WorkingDirectory=${NPM_USER_HOME}|g\" ${_service_manager_file}" + perl -pi -e "s|WorkingDirectory=.*$|WorkingDirectory=${NPM_USER_HOME}|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + + # Replaces "Environment=HOME=/home/k2hr3" with a user defined value + logger -t ${TAG} -p user.debug "perl -pi -e \"s|Environment=HOME=.*$|Environment=HOME=${NPM_USER_HOME}|g\" ${_service_manager_file}" + perl -pi -e "s|Environment=HOME=.*$|Environment=HOME=${NPM_USER_HOME}|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + + # Replaces "Environment=NODE_DEBUG=LOGLEVEL_ERR" with Environment=NODE_DEBUG=${_node_debug} + logger -t ${TAG} -p user.debug "perl -pi -e \"s|Environment=NODE_DEBUG=.*$|Environment=NODE_DEBUG=${_node_debug}|g\" ${_service_manager_file}" + perl -pi -e "s|Environment=NODE_DEBUG=.*$|Environment=NODE_DEBUG=${_node_debug}|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + + # Replaces "ExecStart=/usr/bin/node /home/k2hr3/k2hr3-api/bin/www" with ExecStart=${_node_path} /home/k2hr3/k2hr3-api/bin/www + logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStart=.*$|ExecStart=${_node_path} ${NPM_USER_HOME}/k2hr3-api/bin/www|g\" ${_service_manager_file}" + perl -pi -e "s|ExecStart=.*$|ExecStart=${_node_path} ${NPM_USER_HOME}/k2hr3-api/bin/www|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "k2hr3_api_runuser must be nonzero" + return 1 + fi + else + logger -t ${TAG} -p user.err "SERVICE_MANAGER is either systemd, not ${SERVICE_MANAGER}" + return 1 + fi + return 0 } # -# EOF +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/api/setup_api_node_module.sh b/devcluster/api/setup_api_node_module.sh index dacb241..922601f 100644 --- a/devcluster/api/setup_api_node_module.sh +++ b/devcluster/api/setup_api_node_module.sh @@ -49,25 +49,25 @@ NPM_ARCHIVE_FILE= # Parses cli args while true; do - case "${1-}" in - -d) DEBUG=1;; - -f) shift; NPM_ARCHIVE_FILE="${1-}";; - -h) usage;; - -t) shift; TAG="${1-}";; - -v) version;; - *) break;; - esac - shift + case "${1-}" in + -d) DEBUG=1;; + -f) shift; NPM_ARCHIVE_FILE="${1-}";; + -h) usage;; + -t) shift; TAG="${1-}";; + -v) version;; + *) break;; + esac + shift done # Determines the TAG if test -z "${TAG-}"; then - # Determines the debug mode - if test "${DEBUG}" -eq 1; then - TAG="$(basename $0) -s" - else - TAG=$(basename $0) - fi + # Determines the debug mode + if test "${DEBUG}" -eq 1; then + TAG="$(basename $0) -s" + else + TAG=$(basename $0) + fi fi # The first message is always visible. @@ -75,14 +75,14 @@ logger -t $(basename $0) -s -p user.info "$(basename $0) ${VERSION}" # Loads cluster common functions if ! test -r "${SRCDIR}/../cluster_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" + exit 1 fi . ${SRCDIR}/../cluster_functions # Loads functions if setup_app_node_module_functions file exists if test -r "${SRCDIR}/setup_${COMPONENT}_node_module_functions"; then - . ${SRCDIR}/setup_${COMPONENT}_node_module_functions + . ${SRCDIR}/setup_${COMPONENT}_node_module_functions fi npm_init @@ -90,8 +90,8 @@ logger -t ${TAG} -p user.debug "npm_init" npm_init RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "npm_init should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "npm_init should return zero, not ${RET}" + exit 1 fi ######## @@ -100,32 +100,33 @@ fi # Check if a compiler exists in PATH if test "${OS_NAME}" = "centos" -a "${OS_VERSION}" != "8"; then - # checkif devtoolset-? in package_install_dev_pkgs - for devtoolset in devtoolset-7 devtoolset-6 devtoolset-4; do - if test -f "/opt/rh/${devtoolset}/enable"; then - logger -t ${TAG} -p user.debug "echo ${package_install_dev_pkgs} | grep ${devtoolset}" - echo ${package_install_dev_pkgs} | grep ${devtoolset} > /dev/null 2>&1 - RESULT=$? - if test "${RESULT}" -eq 0; then - logger -t ${TAG} -p user.debug "source /opt/rh/${devtoolset}/enable" - set +u - source /opt/rh/${devtoolset}/enable - set -u - break - else - logger -t ${TAG} -p user.warn "RESULT should be zero, not ${RESULT}" - fi - else - logger -t ${TAG} -p user.err "[NO] no ${devtoolset} found" - exit 1 - fi - done - # No devtoolset in centos means a fatal error. - GPP_PATH=$(which g++) - if test "${GPP_PATH}" = ""; then - logger -t ${TAG} -p user.err "g++ should found, not ${GPP_PATH}" - exit 1 - fi + # checkif devtoolset-? in package_install_dev_pkgs + for devtoolset in devtoolset-7 devtoolset-6 devtoolset-4; do + if test -f "/opt/rh/${devtoolset}/enable"; then + logger -t ${TAG} -p user.debug "echo ${package_install_dev_pkgs} | grep ${devtoolset}" + echo ${package_install_dev_pkgs} | grep ${devtoolset} > /dev/null 2>&1 + RESULT=$? + if test "${RESULT}" -eq 0; then + logger -t ${TAG} -p user.debug "source /opt/rh/${devtoolset}/enable" + set +u + source /opt/rh/${devtoolset}/enable + set -u + break + else + logger -t ${TAG} -p user.warn "RESULT should be zero, not ${RESULT}" + fi + else + logger -t ${TAG} -p user.err "[NO] no ${devtoolset} found" + exit 1 + fi + done + + # No devtoolset in centos means a fatal error. + GPP_PATH=$(which g++) + if test "${GPP_PATH}" = ""; then + logger -t ${TAG} -p user.err "g++ should found, not ${GPP_PATH}" + exit 1 + fi fi # @@ -133,55 +134,45 @@ fi # TMPDIR=$(mktemp -d) if ! test -d "${TMPDIR}"; then - logger -t ${TAG} -p user.err "[NO] no ${TMPDIR}" - exit 1 + logger -t ${TAG} -p user.err "[NO] no ${TMPDIR}" + exit 1 fi cd ${TMPDIR} # Detects a package archive file. if ! test -n "${NPM_ARCHIVE_FILE}"; then - # this command overrite existing k2hr3-api-*.tgz. - npm pack k2hr3-${COMPONENT} - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] npm pack k2hr3-${COMPONENT}" - rm -rf ${TMPDIR} - exit 1 - fi - NPM_ARCHIVE_FILE=$(ls k2hr3-${COMPONENT}-*.tgz) + # this command overrite existing k2hr3-api-*.tgz. + npm pack k2hr3-${COMPONENT} + if test "${?}" != 0; then + logger -t ${TAG} -p user.err "[NO] npm pack k2hr3-${COMPONENT}" + rm -rf ${TMPDIR} + exit 1 + fi + NPM_ARCHIVE_FILE=$(ls k2hr3-${COMPONENT}-*.tgz) fi # Unzips the package archive file. tar xzf ${NPM_ARCHIVE_FILE} if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] tar xzf ${NPM_ARCHIVE_FILE}" - rm -rf ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] tar xzf ${NPM_ARCHIVE_FILE}" + rm -rf ${TMPDIR} + exit 1 fi # Package directory shows up after unzip the archive file if ! test -d "package"; then - logger -t ${TAG} -p user.err "[NO] no package dir" - rm -rf ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] no package dir" + rm -rf ${TMPDIR} + exit 1 fi cd package -# Runs package-json.js if exists. -if test -f "${SRCDIR}/package-json.js"; then - node ${SRCDIR}/package-json.js - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] node ${SRCDIR}/package-json.js" - rm -rf ${SRCDIR} - exit 1 - fi -fi - # Makes a node app environment in this directory npm install if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] npm install" - rm -rf ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] npm install" + rm -rf ${TMPDIR} + exit 1 fi ######## @@ -192,25 +183,26 @@ logger -t ${TAG} -p user.debug "12. Configures the local.json for the k2hr3-${CO # Runs local-json.js if exists. if test -f "${SRCDIR}/local-json.js"; then - node ${SRCDIR}/local-json.js ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ./local.json - if test "${?}" != 0; then - rm -rf ${TMPDIR} - logger -t ${TAG} -p user.err "node ${SRCDIR}/local-json.js ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ./local.json" - exit 1 - fi - if test -f "./local.json"; then - install -C -D -g users -m 0444 -o ${USER} -v ./local.json ./config/local.json - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] install -C -D -g users -m 0444 -o ${USER} -v ./local.json ./config/local.json" - rm -rf ${TMPDIR} - exit 1 - fi - else - logger -t ${TAG} -p user.err "[NO] ./local.json not found" - exit 1 - fi + node ${SRCDIR}/local-json.js ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ./local.json + if test "${?}" != 0; then + rm -rf ${TMPDIR} + logger -t ${TAG} -p user.err "node ${SRCDIR}/local-json.js ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ./local.json" + exit 1 + fi + + if test -f "./local.json"; then + install -C -D -g users -m 0444 -o ${USER} -v ./local.json ./config/local.json + if test "${?}" != 0; then + logger -t ${TAG} -p user.err "[NO] install -C -D -g users -m 0444 -o ${USER} -v ./local.json ./config/local.json" + rm -rf ${TMPDIR} + exit 1 + fi + else + logger -t ${TAG} -p user.err "[NO] ./local.json not found" + exit 1 + fi else - logger -t ${TAG} -p user.debug "${SRCDIR}/local-json.js not found, which is not a problem." + logger -t ${TAG} -p user.debug "${SRCDIR}/local-json.js not found, which is not a problem." fi ######## @@ -221,67 +213,69 @@ logger -t ${TAG} -p user.debug "13. Installs the configured local.json of the k2 # Invokes an error if no local.json found if ! test -f "./config/local.json"; then - logger -t ${TAG} -p user.err "[NO] no ./config/local.json found" - rm -rf ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] no ./config/local.json found" + rm -rf ${TMPDIR} + exit 1 fi # Copies something like a nodejs libraries to the "lib" directory for file in ${SRCDIR}/*.js; do - if test -f "${file}"; then - install -C -g users -m 0444 -o ${USER} -v ${file} ./lib/ - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] install -C -D -m 0444 -o ${USER} -v ${file} ./lib/" - rm -rf ${TMPDIR} - exit 1 - fi - else - logger -t ${TAG} -p user.err "[NO] ${file} not found" - rm -rf ${TMPDIR} - exit 1 - fi + if test -f "${file}"; then + install -C -g users -m 0444 -o ${USER} -v ${file} ./lib/ + if test "${?}" != 0; then + logger -t ${TAG} -p user.err "[NO] install -C -D -m 0444 -o ${USER} -v ${file} ./lib/" + rm -rf ${TMPDIR} + exit 1 + fi + else + logger -t ${TAG} -p user.err "[NO] ${file} not found" + rm -rf ${TMPDIR} + exit 1 + fi done # Installs server a cert and a key if test -f "${SRCDIR}/key.pem" -a -f "${SRCDIR}/cert.pem"; then - install -C -D -g users -m 0400 -o ${USER} -v ${SRCDIR}/key.pem ./config/key.pem - install -C -D -g users -m 0444 -o ${USER} -v ${SRCDIR}/cert.pem ./config/cert.pem + install -C -D -g users -m 0400 -o ${USER} -v ${SRCDIR}/key.pem ./config/key.pem + install -C -D -g users -m 0444 -o ${USER} -v ${SRCDIR}/cert.pem ./config/cert.pem else - openssl genrsa 2024 > ./config/key.pem - if ! test -f "./config/key.pem"; then - logger -t ${TAG} -p user.err "[NO] ./config/key.pem not found" - rm -rf ${TMPDIR} - exit 1 - fi - chmod 400 ./config/key.pem - openssl req -new -key ./config/key.pem -sha256 -config ${SRCDIR}/openssl_sample.conf > ./config/cert.csr - openssl x509 -req -days 3650 -signkey ./config/key.pem < ./config/cert.csr > ./config/cert.pem + openssl genrsa 2024 > ./config/key.pem + if ! test -f "./config/key.pem"; then + logger -t ${TAG} -p user.err "[NO] ./config/key.pem not found" + rm -rf ${TMPDIR} + exit 1 + fi + chmod 400 ./config/key.pem + openssl req -new -key ./config/key.pem -sha256 -config ${SRCDIR}/openssl_sample.conf > ./config/cert.csr + openssl x509 -req -days 3650 -signkey ./config/key.pem < ./config/cert.csr > ./config/cert.pem fi cd ${HOME} if test -d "k2hr3-${COMPONENT}.old"; then - NOW=$(date +%s) - mv -f k2hr3-${COMPONENT}.old k2hr3-${COMPONENT}.old.${NOW} - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] mv -f k2hr3-${COMPONENT}.old k2hr3-${COMPONENT}.old.${NOW}" - rm -rf ${SRCDIR} - exit 1 - fi + NOW=$(date +%s) + mv -f k2hr3-${COMPONENT}.old k2hr3-${COMPONENT}.old.${NOW} + if test "${?}" != 0; then + logger -t ${TAG} -p user.err "[NO] mv -f k2hr3-${COMPONENT}.old k2hr3-${COMPONENT}.old.${NOW}" + rm -rf ${SRCDIR} + exit 1 + fi fi + if test -d "k2hr3-${COMPONENT}"; then - mv k2hr3-${COMPONENT} k2hr3-${COMPONENT}.old - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] mv k2hr3-${COMPONENT} k2hr3-${COMPONENT}.old" - rm -rf ${SRCDIR} - exit 1 - fi + mv k2hr3-${COMPONENT} k2hr3-${COMPONENT}.old + if test "${?}" != 0; then + logger -t ${TAG} -p user.err "[NO] mv k2hr3-${COMPONENT} k2hr3-${COMPONENT}.old" + rm -rf ${SRCDIR} + exit 1 + fi fi + mv ${TMPDIR}/package k2hr3-${COMPONENT} if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] mv ${TMPDIR}/package k2hr3-${COMPONENT}" - mv k2hr3-${COMPONENT}.old k2hr3-${COMPONENT} - rm -rf ${SRCDIR} ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] mv ${TMPDIR}/package k2hr3-${COMPONENT}" + mv k2hr3-${COMPONENT}.old k2hr3-${COMPONENT} + rm -rf ${SRCDIR} ${TMPDIR} + exit 1 fi # The final message displays the time elapsed. @@ -291,7 +285,10 @@ logger -t $(basename $0) -s -p user.info "completed in ${ELAPSED} seconds" exit 0 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/app/local-json.js b/devcluster/app/local-json.js index 4d8c13c..d49d710 100644 --- a/devcluster/app/local-json.js +++ b/devcluster/app/local-json.js @@ -17,6 +17,7 @@ * CREATE: Tue Nov 12 2019 * REVISION: */ + // // This program generates a local.json of k2hr3-app from a k2hr3-utils setup.ini // @@ -27,21 +28,31 @@ const srcdir = path.resolve(__dirname); const process = require('process'); if ( process.argv.length != 4) { - let err = "Usage: node " + process.argv[1] + " "; - console.error(err); - throw new Error(err); + let err = "Usage: node " + process.argv[1] + " "; + console.error(err); + throw new Error(err); } + const input = process.argv[2]; const output = process.argv[3]; try { - let rci = require(path.join(srcdir, 'r3clusterini.js')); - let raj = require(path.join(srcdir, 'r3appjson.js')); - let cluster = new rci.R3clusterIni(input, 'k2hr3_app'); - let r3app= new raj.R3appJson(); - for (const val of cluster) { - r3app.configure(val[0], val[1]); // key, value - } - r3app.dumpTo(output); + let rci = require(path.join(srcdir, 'r3clusterini.js')); + let raj = require(path.join(srcdir, 'r3appjson.js')); + let cluster = new rci.R3clusterIni(input, 'k2hr3_app'); + let r3app = new raj.R3appJson(); + for (const val of cluster) { + r3app.configure(val[0], val[1]); // key, value + } + r3app.dumpTo(output); } catch (err) { - console.error(err.name + ' ' + err.message); + console.error(err.name + ' ' + err.message); } + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/devcluster/app/local_app.json b/devcluster/app/local_app.json index 8d93b1c..09f6c14 100644 --- a/devcluster/app/local_app.json +++ b/devcluster/app/local_app.json @@ -1,3 +1,22 @@ +/* + * K2HR3 Utils + * + * Copyright 2019 Yahoo! Japan Corporation. + * + * K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers + * common management information for the cloud. + * K2HR3 can dynamically manage information as "who", "what", "operate". + * These are stored as roles, resources, policies in K2hdkc, and the + * client system can dynamically read and modify these information. + * + * For the full copyright and license information, please view + * the license file that was distributed with this source code. + * + * AUTHOR: Hirotaka Wakabayashi + * CREATE: Tue Nov 12 2019 + * REVISION: + */ + // // [KEY-VALUE] // scheme : F/E server scheme(http or https) @@ -27,3 +46,12 @@ "apiport": 443, "rejectUnauthorized": false } + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/devcluster/app/r3appjson.js b/devcluster/app/r3appjson.js index 002de28..e92b40a 100644 --- a/devcluster/app/r3appjson.js +++ b/devcluster/app/r3appjson.js @@ -17,6 +17,7 @@ * CREATE: Tue Nov 12 2019 * REVISION: */ + // // This program generates a local.json of k2hr3-app from a k2hr3-utils setup.ini // @@ -24,9 +25,9 @@ const fs = require('fs'); const ACCESSLOGNAME = 'accesslogname'; -const APIHOST = 'apihost'; -const APIPORT = 'apiport'; -const APISCHEME = 'apischeme'; +const APIHOST = 'apihost'; +const APIPORT = 'apiport'; +const APISCHEME = 'apischeme'; const APPMENU = 'appmenu'; const CA = 'ca'; const CERT = 'cert'; @@ -49,307 +50,303 @@ const VALIDATOR = 'validator'; // a class to represent k2hr3-app parameters // class R3appJson { - constructor() { - // properties of this object - this.debug = false; - this.configured = false; - - // k2hr3-app parameters - this.data = { - scheme: 'http', // This nodejs server scheme - port: 80, // This nodejs server port - multiproc: true, // Run multi processes mode - runuser: '', // User for process owner - privatekey: '', // Private key path for https - cert: '', // Certification file path for https - ca: '', // CA path for https - logdir: null, // Path for logging directory - fixedlogdir: null, // Fixed log directory - accesslogname: 'access.log', // Access log name - accesslogform: 'combined', // Access log format by morgan - consolelogname: null, // Console(Error) log name - logrotateopt: { // rotating-file-stream option object - compress: 'gzip', // gzip : compression method of rotated files. - interval: '6h', // 6 hour : the time interval to rotate the file. - initialRotation: true, // true : initial rotation based on not-rotated file timestamp. - path: null // null : the base path for files.(* this value is replace by 'logdir') - /* - * [NOTE] following option is not specified now. - * - rotationTime: true, // true : makes rotated file name with time of rotation. - highWaterMark: null, // null : proxied to new stream. - history: null, // null : the history filename. - immutable: null, // null : never mutates file names. - maxFiles: null, // null : the maximum number of rotated files to keep. - maxSize: null, // null : the maximum size of rotated files to keep. - mode: null, // null : proxied to fs.createWriteStream - rotate: null, // null : enables the classical UNIX logrotate behaviour. - size: null // null : the file size to rotate the file. - */ - }, - apihost: 'localhost', // API host - apischeme: 'http', // API scheme - apiport: 3001, // API port + constructor() { + // properties of this object + this.debug = false; + this.configured = false; - userdata: '', // User Data Script for OpenStack - secretyaml: '', // Secret Yaml for kubernetes - sidecaryaml: '', // Sidecar Yaml for kubernetes - appmenu: null, // The menu array for application - validator: 'userValidateDebug', // Validator object module - validobj: null, // Generated(required) validator object module - rejectunauthorized: true, // reject mode - lang: 'en', // Language for javascript application - extrouter: { // Configuration of Router module to be expanded - /* - * [NOTE] Define the following objects as an array. - * Define one object for one extended Router. - * - routername: { - name: 'file path', // Specify JS file name(except js extension) for defining Router. The "/router" directory is current. - path: 'route top path', // Specify the router entry path(ex. "/myenter"). - config: {} // Specify the configuration required for the extended router. (Value, array, object) - }, - ... - */ - } - }; - } + // k2hr3-app parameters + this.data = { + scheme: 'http', // This nodejs server scheme + port: 80, // This nodejs server port + multiproc: true, // Run multi processes mode + runuser: '', // User for process owner + privatekey: '', // Private key path for https + cert: '', // Certification file path for https + ca: '', // CA path for https + logdir: null, // Path for logging directory + fixedlogdir: null, // Fixed log directory + accesslogname: 'access.log', // Access log name + accesslogform: 'combined', // Access log format by morgan + consolelogname: null, // Console(Error) log name + logrotateopt: { // rotating-file-stream option object + compress: 'gzip', // gzip : compression method of rotated files. + interval: '6h', // 6 hour : the time interval to rotate the file. + initialRotation: true, // true : initial rotation based on not-rotated file timestamp. + path: null // null : the base path for files.(* this value is replace by 'logdir') + /* + * [NOTE] following option is not specified now. + * + rotationTime: true, // true : makes rotated file name with time of rotation. + highWaterMark: null, // null : proxied to new stream. + history: null, // null : the history filename. + immutable: null, // null : never mutates file names. + maxFiles: null, // null : the maximum number of rotated files to keep. + maxSize: null, // null : the maximum size of rotated files to keep. + mode: null, // null : proxied to fs.createWriteStream + rotate: null, // null : enables the classical UNIX logrotate behaviour. + size: null // null : the file size to rotate the file. + */ + }, + apihost: 'localhost', // API host + apischeme: 'http', // API scheme + apiport: 3001, // API port - // - // methods - // - configureAccessLogName(r3appkey, val) { - if (r3appkey.localeCompare(ACCESSLOGNAME) == 0) { - this.data.accesslogname = val; + userdata: '', // User Data Script for OpenStack + secretyaml: '', // Secret Yaml for kubernetes + sidecaryaml: '', // Sidecar Yaml for kubernetes + appmenu: null, // The menu array for application + validator: 'userValidateDebug', // Validator object module + validobj: null, // Generated(required) validator object module + rejectUnauthorized: true, // reject mode + lang: 'en', // Language for javascript application + }; } - } - configureApiHost(r3appkey, val) { - if (r3appkey.localeCompare(APIHOST) == 0) { - this.data.apihost = val; + // + // methods + // + configureAccessLogName(r3appkey, val) { + if (r3appkey.localeCompare(ACCESSLOGNAME) == 0) { + this.data.accesslogname = val; + } } - } - configureApiPort(r3appkey, val) { - if (r3appkey.localeCompare(APIPORT) == 0) { - this.data.apiport = val; + configureApiHost(r3appkey, val) { + if (r3appkey.localeCompare(APIHOST) == 0) { + this.data.apihost = val; + } } - } - configureApiScheme(r3appkey, val) { - if (r3appkey.localeCompare(APISCHEME) == 0) { - this.data.apischeme = val; + configureApiPort(r3appkey, val) { + if (r3appkey.localeCompare(APIPORT) == 0) { + this.data.apiport = val; + } } - } - configureAppMenu(r3appkey, val) { - if (r3appkey.localeCompare(APPMENU) == 0) { - this.data.appmenu = []; - let menus = []; - let spos = 0; // startPos - let pos = 0; - do { - pos = val.indexOf(',', spos); - if (this.debug) { - console.log('pos=' + pos); - } - if (pos !== -1) { // found a comma - menus.push(val.substring(spos, pos)); - } else { - menus.push(val.substr(spos)); - } - spos = pos + 1; - } while(pos !== -1); - for(let menu of menus) { - let pos = menu.indexOf('=', 0); - if (pos !== -1) { // found a equal - let name = menu.substring(0, pos); - let url = menu.substring(pos + 1); - let obj = {} - obj.name = name; - obj.url = url; - console.log(obj); - this.data.appmenu.push(obj); - } - } - + configureApiScheme(r3appkey, val) { + if (r3appkey.localeCompare(APISCHEME) == 0) { + this.data.apischeme = val; + } } - } - configureCA(r3appkey, val) { - if (r3appkey.localeCompare(CA) == 0) { - this.data.ca = val; + configureAppMenu(r3appkey, val) { + if (r3appkey.localeCompare(APPMENU) == 0) { + this.data.appmenu = []; + let menus = []; + let spos = 0; // startPos + let pos = 0; + do { + pos = val.indexOf(',', spos); + if (this.debug) { + console.log('pos=' + pos); + } + if (pos !== -1) { // found a comma + menus.push(val.substring(spos, pos)); + } else { + menus.push(val.substr(spos)); + } + spos = pos + 1; + } while(pos !== -1); + + for(let menu of menus) { + let pos = menu.indexOf('=', 0); + if (pos !== -1) { // found a equal + let name = menu.substring(0, pos); + let url = menu.substring(pos + 1); + let obj = {} + obj.name = name; + obj.url = url; + console.log(obj); + this.data.appmenu.push(obj); + } + } + } } - } - configureCert(r3appkey, val) { - if (r3appkey.localeCompare(CERT) == 0) { - this.data.cert = val; + configureCA(r3appkey, val) { + if (r3appkey.localeCompare(CA) == 0) { + this.data.ca = val; + } } - } - configureConsoleLogName(r3appkey, val) { - if (r3appkey.localeCompare(CONSOLELOGNAME) == 0) { - this.data.consolelogname = val; + configureCert(r3appkey, val) { + if (r3appkey.localeCompare(CERT) == 0) { + this.data.cert = val; + } } - } - configureExtRouter(r3appkey, val) { - if (r3appkey.localeCompare(EXTROUTER) == 0) { - this.data.extrouter = val; + configureConsoleLogName(r3appkey, val) { + if (r3appkey.localeCompare(CONSOLELOGNAME) == 0) { + this.data.consolelogname = val; + } } - } - configureLogDir(r3appkey, val) { - if (r3appkey.localeCompare(LOGDIR) == 0) { - this.data.logdir = val; + configureExtrouter(r3appkey, val) { + if (r3appkey.localeCompare(EXTROUTER) == 0) { + this.data.extrouter = val; + } } - } - configureLogrotateOptCompress(r3appkey, val) { - if (r3appkey.localeCompare(LOGROTATEOPT_COMPRESS) == 0) { - this.data.logrotateopt.compress = val; + configureLogDir(r3appkey, val) { + if (r3appkey.localeCompare(LOGDIR) == 0) { + this.data.logdir = val; + } } - } - configureLogrotateOptInitialRotation(r3appkey, val) { - if (r3appkey.localeCompare(LOGROTATEOPT_INITIALROTATION) == 0) { - if( val.localeCompare("true") ) { - this.data.logrotateopt.initialRotation = true; - } else { - this.data.logrotateopt.initialRotation = false; - } + configureLogrotateOptCompress(r3appkey, val) { + if (r3appkey.localeCompare(LOGROTATEOPT_COMPRESS) == 0) { + this.data.logrotateopt.compress = val; + } } - } - configureLogrotateOptInterval(r3appkey, val) { - if (r3appkey.localeCompare(LOGROTATEOPT_INTERVAL) == 0) { - this.data.logrotateopt.interval = val; + configureLogrotateOptInitialRotation(r3appkey, val) { + if (r3appkey.localeCompare(LOGROTATEOPT_INITIALROTATION) == 0) { + if( val.localeCompare("true") == 0 ) { + this.data.logrotateopt.initialRotation = true; + } else { + this.data.logrotateopt.initialRotation = false; + } + } } - } - configureMultiProc(r3appkey, val) { - if (r3appkey.localeCompare(MULTIPROC) == 0) { - if( val.localeCompare("true") ) { - this.data.multiproc = true; - } else { - this.data.multiproc = false; - } + configureLogrotateOptInterval(r3appkey, val) { + if (r3appkey.localeCompare(LOGROTATEOPT_INTERVAL) == 0) { + this.data.logrotateopt.interval = val; + } } - } - configurePort(r3appkey, val) { - if (r3appkey.localeCompare(PORT) == 0) { - this.data.port = val; + configureMultiProc(r3appkey, val) { + if (r3appkey.localeCompare(MULTIPROC) == 0) { + if( val.localeCompare("true") == 0 ) { + this.data.multiproc = true; + } else { + this.data.multiproc = false; + } + } } - } - configurePrivateKey(r3appkey, val) { - if (r3appkey.localeCompare(PRIVATEKEY) == 0) { - this.data.privatekey = val; + configurePort(r3appkey, val) { + if (r3appkey.localeCompare(PORT) == 0) { + this.data.port = val; + } } - } - configureRejectUnAuthorized(r3appkey, val) { - if (r3appkey.localeCompare(REJECTUNAUTHORIZED) == 0) { - if( val.localeCompare("true") ) { - this.data.rejectunauthorized = true; - } else { - this.data.rejectunauthorized = false; - } + configurePrivateKey(r3appkey, val) { + if (r3appkey.localeCompare(PRIVATEKEY) == 0) { + this.data.privatekey = val; + } } - } - configureRunUser(r3appkey, val) { - if (r3appkey.localeCompare(RUNUSER) == 0) { - this.data.runuser = val; + configureRejectUnAuthorized(r3appkey, val) { + if (r3appkey.localeCompare(REJECTUNAUTHORIZED) == 0) { + if( val.localeCompare("true") == 0 ) { + this.data.rejectUnauthorized = true; + } else { + this.data.rejectUnauthorized = false; + } + } } - } - configureScheme(r3appkey, val) { - if (r3appkey.localeCompare(SCHEME) == 0) { - this.data.scheme = val; + configureRunUser(r3appkey, val) { + if (r3appkey.localeCompare(RUNUSER) == 0) { + this.data.runuser = val; + } } - } - configureValidator(r3appkey, val) { - if (r3appkey.localeCompare(VALIDATOR) == 0) { - this.data.validator = val; + configureScheme(r3appkey, val) { + if (r3appkey.localeCompare(SCHEME) == 0) { + this.data.scheme = val; + } } - } - // configure - // This method binds ini items with json items and it also changes ini item data format to json data format. - // - // Params:: - // $1 data item name, which name starts with "k2hr3_app_" - // $2 value of the item - // - // Returns:: - // true on success - // - configure(key, val) { - let p = key.startsWith('k2hr3_app_'); - if (!p) { - console.log('key is not for k2hr3_app'); - return false; + configureValidator(r3appkey, val) { + if (r3appkey.localeCompare(VALIDATOR) == 0) { + this.data.validator = val; + } } - let r3appkey = key.slice(9+1); // strlen(k2hr3_app_) + 1 - this.configureAccessLogName(r3appkey, val); - this.configureApiHost(r3appkey, val); - this.configureApiPort(r3appkey, val); - this.configureApiScheme(r3appkey, val); - this.configureAppMenu(r3appkey, val); - this.configureCA(r3appkey, val); - this.configureCert(r3appkey, val); - this.configureConsoleLogName(r3appkey, val); - this.configureExtRouter(r3appkey, val); - this.configureLogDir(r3appkey, val); - this.configureLogrotateOptCompress(r3appkey, val); - this.configureLogrotateOptInitialRotation(r3appkey, val); - this.configureLogrotateOptInterval(r3appkey, val); - this.configureMultiProc(r3appkey, val); - this.configurePort(r3appkey, val); - this.configurePrivateKey(r3appkey, val); - this.configureRejectUnAuthorized(r3appkey, val); - this.configureRunUser(r3appkey, val); - this.configureScheme(r3appkey, val); - this.configureValidator(r3appkey, val); - this.configured = true; - } - // dump - // This method writes k2hr3-api data to a json file. - // - // Params:: - // $1 path of a json file - // - // Returns:: - // true on success - // - dumpTo(path) { - if (!this.configured) { - console.error("have not configured yet."); - return false; + // configure + // This method binds ini items with json items and it also changes ini item data format to json data format. + // + // Params:: + // $1 data item name, which name starts with "k2hr3_app_" + // $2 value of the item + // + // Returns:: + // true on success + // + configure(key, val) { + let p = key.startsWith('k2hr3_app_'); + if (!p) { + console.log('key is not for k2hr3_app'); + return false; + } + let r3appkey = key.slice(9+1); // strlen(k2hr3_app_) + 1 + this.configureAccessLogName(r3appkey, val); + this.configureApiHost(r3appkey, val); + this.configureApiPort(r3appkey, val); + this.configureApiScheme(r3appkey, val); + this.configureAppMenu(r3appkey, val); + this.configureCA(r3appkey, val); + this.configureCert(r3appkey, val); + this.configureConsoleLogName(r3appkey, val); + this.configureExtrouter(r3appkey, val); + this.configureLogDir(r3appkey, val); + this.configureLogrotateOptCompress(r3appkey, val); + this.configureLogrotateOptInitialRotation(r3appkey, val); + this.configureLogrotateOptInterval(r3appkey, val); + this.configureMultiProc(r3appkey, val); + this.configurePort(r3appkey, val); + this.configurePrivateKey(r3appkey, val); + this.configureRejectUnAuthorized(r3appkey, val); + this.configureRunUser(r3appkey, val); + this.configureScheme(r3appkey, val); + this.configureValidator(r3appkey, val); + this.configured = true; } - var jsondata = JSON.stringify(this, null, ' '); - if (jsondata) { - fs.writeFileSync(path, jsondata); + + // dump + // This method writes k2hr3-api data to a json file. + // + // Params:: + // $1 path of a json file + // + // Returns:: + // true on success + // + dumpTo(path) { + if (!this.configured) { + console.error("have not configured yet."); + return false; + } + var jsondata = JSON.stringify(this, null, ' '); + if (jsondata) { + fs.writeFileSync(path, jsondata); + } + return true; } - return true; - } - // toJSON - // This method is called back from JSON.stringify - // - // Returns:: - // a json object of k2hr3-api data - // - toJSON() { - return this.data; - } + // toJSON + // This method is called back from JSON.stringify + // + // Returns:: + // a json object of k2hr3-api data + // + toJSON() { + return this.data; + } } module.exports = { - R3appJson + R3appJson } + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/devcluster/app/r3clusterini.js b/devcluster/app/r3clusterini.js index d70bdca..8a33453 100644 --- a/devcluster/app/r3clusterini.js +++ b/devcluster/app/r3clusterini.js @@ -17,8 +17,9 @@ * CREATE: Tue Nov 12 2019 * REVISION: */ + // -// This program generates a local.json of k2hr3-app from a k2hr3-utils setup.ini +// This program generates a local.json of k2hr3-api from a k2hr3-utils setup.ini // 'use strict'; @@ -31,116 +32,129 @@ const srcdir = path.resolve(__dirname); // represents cluster ini file // class R3clusterIni { - // - // Params:: - // $1 a path to k2hr3_utils ini file - // $2 k2hr3_api or k2hr3_app) - // - // Returns:: - // a R3clusterIni object on success - // throws exception on failure - // - constructor(ini, component) { - // properties - this.index = 0; // position of data processing - this.debug = false; - this.component = component || ''; // k2hr3-api or k2hr3-app - this.env = 'local'; + // + // Params:: + // $1 a path to k2hr3_utils ini file + // $2 k2hr3_api or k2hr3_app) + // + // Returns:: + // a R3clusterIni object on success + // throws exception on failure + // + constructor(ini, component) { + // properties + this.index = 0; // position of data processing + this.debug = false; + this.component = component || ''; // k2hr3-api or k2hr3-app - // cluster parameters - this.ini = ini || 'setup.ini'; - this.keys = []; - this.vals = []; + // cluster parameters + this.ini = ini || 'setup.ini'; + this.keys = []; + this.vals = []; - // parses a ini file and puts them to the key and value array members - try { - let buf = fs.readFileSync(this.ini, "utf8"); - // 1. split data by a line feed - let p = buf.indexOf('\n'); - do { - if (p !== -1) { - const line = buf.slice(0, p); - if (this.debug) { - console.log('line=' + line); - } - let pos = line.indexOf('='); - if (pos !== -1) { - let key = line.substring(0, pos); - if (typeof key === 'string' && key.length !== 0) { - let val = line.substring(pos + 1); - if (this.debug) { - console.log('key=' + key + ' val=' + val); - } - // 2. picks up data of the component only - if (key.startsWith(component)) { - this.keys.push(key); - this.vals.push(val); - if (key.localeCompare("k2hr3_app_extrouter_env") == 0) { - this.env = val; - } - } - } - } - buf = buf.slice(p + 1); + // parses a ini file and puts them to the key and value array members + try { + let buf = fs.readFileSync(this.ini, "utf8"); + + // 1. split data by a line feed + let p = buf.indexOf('\n'); + do { + if (p !== -1) { + const line = buf.slice(0, p); + if (this.debug) { + console.log('line=' + line); + } + let pos = line.indexOf('='); + if (pos !== -1) { + let key = line.substring(0, pos); + if (typeof key === 'string' && key.length !== 0) { + let val = line.substring(pos + 1); + if (this.debug) { + console.log('key=' + key + ' val=' + val); + } + + // 2. picks up data of the component only + if (key.startsWith(component)) { + this.keys.push(key); + this.vals.push(val); + } + if (key.localeCompare("env") == 0) { + this.env = val; + } + } + } + buf = buf.slice(p + 1); + } + p = buf.indexOf('\n'); + } while(p !== -1); + } catch (err) { + console.error(err.name + ' ' + err.message); + throw err; + } + + // defines data.somedata if r3clusterini_k2hr3_api_ext.js exists. + try { + let extfile = path.join(srcdir, 'r3clusterini_k2hr3_app_ext.js'); + fs.accessSync(extfile, fs.constants.R_OK); + + // 1. filename + // r3clusterini_k2hr3_app_ext.js + + // 2. class name + // R3initExtraData + + // 3. methods + // getData + const extData = require(extfile); + let instance = new extData.R3iniExtraData(); + instance.setEnv(this.env); + this.keys.push(instance.getKey()); + this.vals.push(instance.getData()); + } catch (err) { + console.log('no access to k2hr3_app_local_json_ext.js, just skipping it;)'); } - p = buf.indexOf('\n'); - } while(p !== -1); - } catch (err) { - console.error(err.name + ' ' + err.message); - throw err; - } - // defines data.extrouter if k2hr3_app_extrouter.js file exists - try { - let extfile = path.join(srcdir, 'k2hr3_app_extrouter.js'); // - fs.accessSync(extfile, fs.constants.R_OK); - // constrains of data.extrouter generator class - // 1. filename - // k2hr3_app_extroute.js - // 2. class name - // R3initExtrouter - // 3. methods - // getData - const extrouter = require(extfile); - let instance = new extrouter.R3iniExtrouter(); - instance.setEnv(this.env); - this.keys.push('k2hr3_app_extrouter'); - this.vals.push(instance.getData()); - } catch (err) { - console.log('no access to k2hr3_app_extrouter.js, just skipping it;)'); } - } - // - // methods - // - // next method - // iterates the key and value array - // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Iteration_protocols - // - // Returns:: - // a pair of a key and a value - // - [Symbol.iterator]() { - return { - next: () => { - if (this.index < this.keys.length) { - let pos = this.index++; - return {value: [this.keys[pos], this.vals[pos]], done: false}; - } else { - this.index = 0; - return {done: true}; + // + // methods + // + // next method + // iterates the key and value array + // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Iteration_protocols + // + // Returns:: + // a pair of a key and a value + // + [Symbol.iterator]() { + return { + next: () => { + if (this.index < this.keys.length) { + let pos = this.index++; + return {value: [this.keys[pos], this.vals[pos]], done: false}; + } else { + this.index = 0; + return {done: true}; + } + } } - } } - } } // for debug // var cluster = new R3clusterIni(path.join(srcdir, 'setup_app_centos.ini'), 'k2hr3_app'); // for (const val of cluster) { -// console.log(val); +// console.log(val); // } module.exports = { - R3clusterIni + R3clusterIni } + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/devcluster/app/setup_app.sh b/devcluster/app/setup_app.sh index 5878754..27d5a29 100644 --- a/devcluster/app/setup_app.sh +++ b/devcluster/app/setup_app.sh @@ -47,29 +47,29 @@ VERSION=0.10.0 NPM_ARCHIVE_FILE= if ! test -r "${SRCDIR}/../cluster_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" + exit 1 fi . ${SRCDIR}/../cluster_functions # Parses cli args while true; do - case "${1-}" in - -d) DEBUG=1;; - -f) shift; NPM_ARCHIVE_FILE="${1-}";; - -h) usage;; - -r) DRYRUN=1;; - -v) version;; - *) break;; - esac - shift + case "${1-}" in + -d) DEBUG=1;; + -f) shift; NPM_ARCHIVE_FILE="${1-}";; + -h) usage;; + -r) DRYRUN=1;; + -v) version;; + *) break;; + esac + shift done # DEBUG determines the logger option if test "${DEBUG}" -eq 1; then - TAG="$(basename $0) -s" + TAG="$(basename $0) -s" else - TAG=$(basename $0) + TAG=$(basename $0) fi # The first message is always visible. @@ -82,8 +82,8 @@ logger -t $(basename $0) -s -p user.info "$(basename $0) ${VERSION}" logger -t ${TAG} -p user.info "1. Initializes environments" if ! test -r "${SRCDIR}/../cluster_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" + exit 1 fi . ${SRCDIR}/../cluster_functions @@ -91,16 +91,16 @@ fi setup_os_env RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_os_env should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_os_env should return zero, not ${RET}" + exit 1 fi # Loads default settings setup_ini_env RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" + exit 1 fi ######## @@ -113,26 +113,26 @@ logger -t ${TAG} -p user.info "2. Adds a new package repository" enable_packagecloud_io_repository ${package_script_base_url-} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_packagecloud_io_repository should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "enable_packagecloud_io_repository should return zero, not ${RET}" + exit 1 fi # Enables the nodesource repo enable_nodesource_repository ${nodesource_url-} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_nodesource_repository should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "enable_nodesource_repository should return zero, not ${RET}" + exit 1 fi # Enables the softwarecollections repo if test "${OS_NAME}" = "centos"; then - setup_package_repository ${copr_url-} - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_package_repository should return zero, not ${RET}" - exit 1 - fi + setup_package_repository ${copr_url-} + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_package_repository should return zero, not ${RET}" + exit 1 + fi fi ######## @@ -145,14 +145,14 @@ logger -t ${TAG} -p user.info "3. Installs OS dependent packages" # define empty ${package_install_pkg} value in their initial configuration file. # We call the setup_install_os_packages function if package_install_pkgs defined. if test -n "${package_install_pkgs-}"; then - setup_install_os_packages "${package_install_pkgs-}" - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" - exit 1 - fi + setup_install_os_packages "${package_install_pkgs-}" + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" + exit 1 + fi else - logger -t ${TAG} -p user.err "package_install_pkgs is zero" + logger -t ${TAG} -p user.err "package_install_pkgs is zero" fi ######## @@ -162,22 +162,22 @@ fi logger -t ${TAG} -p user.info "4. Install the k2hr3-app npm package" if ! test -n "${npm_default_user}"; then - logger -t ${TAG} -p user.err "npm_default_user should be nonzero, ${npm_default_user}" - exit 1 + logger -t ${TAG} -p user.err "npm_default_user should be nonzero, ${npm_default_user}" + exit 1 fi add_npm_user "${npm_default_user}" RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "add_npm_user should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "add_npm_user should return zero, not ${RET}" + exit 1 fi setup_npm_userhome "${npm_default_user}" RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_npm_userhome should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_npm_userhome should return zero, not ${RET}" + exit 1 fi # Runs app/setup_app_node_module.sh as node command executer @@ -185,19 +185,19 @@ app_node_module_sh="${SRCDIR}/setup_app_node_module.sh -t ${TAG}" # Adds the DEBUG option if DEBUG is enabled if test "${DEBUG}" -eq 1; then - app_node_module_sh="${app_node_module_sh} -d" + app_node_module_sh="${app_node_module_sh} -d" fi # Adds the NPM_ARCHIVE_FILE option if NPM_ARCHIVE_FILE exists if test -n "${NPM_ARCHIVE_FILE}"; then - if test -f "${NPM_ARCHIVE_FILE}"; then - # Remenber to call 'basename' function - # Because an archive file stays /home/k2hr3/k2hr3-app-0.0.1.tgz - app_node_module_sh="${app_node_module_sh} -f $(basename ${NPM_ARCHIVE_FILE})" - else - logger -t ${TAG} -p user.debug "${NPM_ARCHIVE_FILE} must be a URL" - app_node_module_sh="${app_node_module_sh} -f ${NPM_ARCHIVE_FILE}" - fi + if test -f "${NPM_ARCHIVE_FILE}"; then + # Remenber to call 'basename' function + # Because an archive file stays /home/k2hr3/k2hr3-app-0.0.1.tgz + app_node_module_sh="${app_node_module_sh} -f $(basename ${NPM_ARCHIVE_FILE})" + else + logger -t ${TAG} -p user.debug "${NPM_ARCHIVE_FILE} must be a URL" + app_node_module_sh="${app_node_module_sh} -f ${NPM_ARCHIVE_FILE}" + fi fi ######## @@ -212,12 +212,12 @@ fi # $ sudo su - k2hr3 sh -c "sh ./setup_app_node_module.sh -d" logger -t ${TAG} -p user.info "sudo su - ${npm_default_user} sh -c \"${app_node_module_sh}\"" if test -z "${DRYRUN-}"; then - sudo su - ${npm_default_user} sh -c "sh ${app_node_module_sh}" - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - exit 1 - fi + sudo su - ${npm_default_user} sh -c "sh ${app_node_module_sh}" + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + exit 1 + fi fi # A workaround for the root owned log file problem. @@ -232,8 +232,8 @@ fi patch_for_change_logdir_owner ${npm_default_user} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_npm_userhome should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_npm_userhome should return zero, not ${RET}" + exit 1 fi ######## @@ -242,24 +242,25 @@ fi # logger -t ${TAG} -p user.info "7. Configures the k2hr3-app's service manager default configuration" if ! test -r "${SRCDIR}/setup_${COMPONENT}_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/setup_${COMPONENT}_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/setup_${COMPONENT}_functions should exist" + exit 1 fi . ${SRCDIR}/setup_${COMPONENT}_functions # Determines the service management file which file format depends on a service manager of the target OS if test "${SERVICE_MANAGER}" = "systemd"; then - service_manager_file=${SRCDIR}/../service_manager/k2hr3-app.service + service_manager_file=${SRCDIR}/../service_manager/k2hr3-app.service else - logger -t ${TAG} -p user.err "SERVICE_MANAGER must be either systemd, not ${SERVICE_MANAGER}" - exit 1 + logger -t ${TAG} -p user.err "SERVICE_MANAGER must be either systemd, not ${SERVICE_MANAGER}" + exit 1 fi + # Configures the k2hr3-app's service manager default configuration configure_k2hr3_app_service_manager_file ${SERVICE_MANAGER} ${service_manager_file} ${k2hr3_app_runuser} ${node_debug} ${node_path} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "configure_k2hr3_app_service_manager_file should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "configure_k2hr3_app_service_manager_file should return zero, not ${RET}" + exit 1 fi ######## @@ -271,8 +272,8 @@ logger -t ${TAG} -p user.info "8. Installs the k2hr3-app service manager configu install_service_manager_conf ${SERVICE_MANAGER} k2hr3-app RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_service_manager_conf should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "install_service_manager_conf should return zero, not ${RET}" + exit 1 fi ######## @@ -280,12 +281,12 @@ fi # logger -t ${TAG} -p user.debug "sudo systemctl restart k2hr3-${COMPONENT}.service" if test -z "${DRYRUN-}"; then - sudo systemctl restart k2hr3-${COMPONENT}.service - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "'sudo systemctl restart k2hr3-${COMPONENT}.service' should return zero, not ${RESULT}" - exit 1 - fi + sudo systemctl restart k2hr3-${COMPONENT}.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "'sudo systemctl restart k2hr3-${COMPONENT}.service' should return zero, not ${RESULT}" + exit 1 + fi fi # The final message displays the time elapsed. @@ -295,7 +296,10 @@ logger -t $(basename $0) -s -p user.info "completed in ${ELAPSED} seconds" exit 0 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/app/setup_app_centos.ini b/devcluster/app/setup_app_centos.ini index 86a596b..200d60c 100644 --- a/devcluster/app/setup_app_centos.ini +++ b/devcluster/app/setup_app_centos.ini @@ -37,7 +37,10 @@ nodesource_url=https://rpm.nodesource.com/setup_10.x package_install_pkgs="nodejs" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/app/setup_app_debian.ini b/devcluster/app/setup_app_debian.ini index 964117d..d91a9b6 100644 --- a/devcluster/app/setup_app_debian.ini +++ b/devcluster/app/setup_app_debian.ini @@ -36,7 +36,10 @@ npm_default_user=k2hr3 nodesource_url=https://deb.nodesource.com/setup_10.x # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/app/setup_app_default.ini b/devcluster/app/setup_app_default.ini index abf9ac4..5b52c57 100644 --- a/devcluster/app/setup_app_default.ini +++ b/devcluster/app/setup_app_default.ini @@ -46,7 +46,10 @@ package_script_base_url=https://packagecloud.io/install/repositories/antpickax/s package_install_pkgs="nodejs" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/app/setup_app_fedora.ini b/devcluster/app/setup_app_fedora.ini index c102b69..94d12bf 100644 --- a/devcluster/app/setup_app_fedora.ini +++ b/devcluster/app/setup_app_fedora.ini @@ -37,7 +37,10 @@ nodesource_url=https://rpm.nodesource.com/setup_10.x package_script_base_url=https://packagecloud.io/install/repositories/antpickax/current # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/app/setup_app_functions b/devcluster/app/setup_app_functions index ba9312e..66c1749 100644 --- a/devcluster/app/setup_app_functions +++ b/devcluster/app/setup_app_functions @@ -35,65 +35,74 @@ # This function is designed for unit tests. # configure_k2hr3_app_service_manager_file() { - _service_manager=${1:?"service_manager should be nonzero"} - _service_manager_file=${2:?"service_manager_file should be nonzero"} - _k2hr3_app_runuser=${3:?"k2hr3_app_runner should be nonzero. Check if it is defined in setup_app_*.ini"} - _node_debug=${4:-LOGLEVEL_ERR} - _node_path=${5:-/usr/bin/node} + _service_manager=${1:?"service_manager should be nonzero"} + _service_manager_file=${2:?"service_manager_file should be nonzero"} + _k2hr3_app_runuser=${3:?"k2hr3_app_runner should be nonzero. Check if it is defined in setup_app_*.ini"} + _node_debug=${4:-LOGLEVEL_ERR} + _node_path=${5:-/usr/bin/node} - logger -t ${TAG} -p user.debug "configure_k2hr3_app_service_manager_file _service_manager=${_service_manager} _service_manager_file=${_service_manager_file} _k2hr3_app_runuser=${_k2hr3_app_runuser} _node_debug=${_node_debug} _node_path=${_node_path}" + logger -t ${TAG} -p user.debug "configure_k2hr3_app_service_manager_file _service_manager=${_service_manager} _service_manager_file=${_service_manager_file} _k2hr3_app_runuser=${_k2hr3_app_runuser} _node_debug=${_node_debug} _node_path=${_node_path}" - if ! test -f "${service_manager_file}"; then - logger -t ${TAG} -p user.err "${_service_manager_file} should exist" - return 1 - fi + if ! test -f "${service_manager_file}"; then + logger -t ${TAG} -p user.err "${_service_manager_file} should exist" + return 1 + fi - if test "${_service_manager}" = "systemd"; then - if test -n "${_k2hr3_app_runuser}"; then - NPM_USER_HOME=$(eval echo "~${_k2hr3_app_runuser}") - # Replaces "WorkingDirectory=/home/k2hr3" with a user defined value - logger -t ${TAG} -p user.debug "perl -pi -e \"s|WorkingDirectory=.*$|WorkingDirectory=${NPM_USER_HOME}|g\" ${_service_manager_file}" - perl -pi -e "s|WorkingDirectory=.*$|WorkingDirectory=${NPM_USER_HOME}|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - # Replaces "Environment=HOME=/home/k2hr3" with a user defined value - logger -t ${TAG} -p user.debug "perl -pi -e \"s|Environment=HOME=.*$|Environment=HOME=${NPM_USER_HOME}|g\" ${_service_manager_file}" - perl -pi -e "s|Environment=HOME=.*$|Environment=HOME=${NPM_USER_HOME}|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - # Replaces "Environment=NODE_DEBUG=LOGLEVEL_ERR" with Environment=NODE_DEBUG=${_node_debug} - logger -t ${TAG} -p user.debug "perl -pi -e \"s|Environment=NODE_DEBUG=.*$|Environment=NODE_DEBUG=${_node_debug}|g\" ${_service_manager_file}" - perl -pi -e "s|Environment=NODE_DEBUG=.*$|Environment=NODE_DEBUG=${_node_debug}|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - # Replaces "ExecStart=/usr/bin/node /home/k2hr3/k2hr3-app/bin/www" with ExecStart=${_node_path} /home/k2hr3/k2hr3-app/bin/www - logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStart=.*$|ExecStart=${_node_path} ${NPM_USER_HOME}/k2hr3-app/bin/www|g\" ${_service_manager_file}" - perl -pi -e "s|ExecStart=.*$|ExecStart=${_node_path} ${NPM_USER_HOME}/k2hr3-app/bin/www|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "k2hr3_app_runuser must be nonzero" - return 1 - fi - else - logger -t ${TAG} -p user.err "SERVICE_MANAGER is either systemd, not ${SERVICE_MANAGER}" - return 1 - fi - return 0 + if test "${_service_manager}" = "systemd"; then + if test -n "${_k2hr3_app_runuser}"; then + NPM_USER_HOME=$(eval echo "~${_k2hr3_app_runuser}") + + # Replaces "WorkingDirectory=/home/k2hr3" with a user defined value + logger -t ${TAG} -p user.debug "perl -pi -e \"s|WorkingDirectory=.*$|WorkingDirectory=${NPM_USER_HOME}|g\" ${_service_manager_file}" + perl -pi -e "s|WorkingDirectory=.*$|WorkingDirectory=${NPM_USER_HOME}|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + + # Replaces "Environment=HOME=/home/k2hr3" with a user defined value + logger -t ${TAG} -p user.debug "perl -pi -e \"s|Environment=HOME=.*$|Environment=HOME=${NPM_USER_HOME}|g\" ${_service_manager_file}" + perl -pi -e "s|Environment=HOME=.*$|Environment=HOME=${NPM_USER_HOME}|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + + # Replaces "Environment=NODE_DEBUG=LOGLEVEL_ERR" with Environment=NODE_DEBUG=${_node_debug} + logger -t ${TAG} -p user.debug "perl -pi -e \"s|Environment=NODE_DEBUG=.*$|Environment=NODE_DEBUG=${_node_debug}|g\" ${_service_manager_file}" + perl -pi -e "s|Environment=NODE_DEBUG=.*$|Environment=NODE_DEBUG=${_node_debug}|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + + # Replaces "ExecStart=/usr/bin/node /home/k2hr3/k2hr3-app/bin/www" with ExecStart=${_node_path} /home/k2hr3/k2hr3-app/bin/www + logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStart=.*$|ExecStart=${_node_path} ${NPM_USER_HOME}/k2hr3-app/bin/www|g\" ${_service_manager_file}" + perl -pi -e "s|ExecStart=.*$|ExecStart=${_node_path} ${NPM_USER_HOME}/k2hr3-app/bin/www|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "k2hr3_app_runuser must be nonzero" + return 1 + fi + else + logger -t ${TAG} -p user.err "SERVICE_MANAGER is either systemd, not ${SERVICE_MANAGER}" + return 1 + fi + return 0 } # -# EOF +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/app/setup_app_node_module.sh b/devcluster/app/setup_app_node_module.sh index d85eea4..e80ce84 100644 --- a/devcluster/app/setup_app_node_module.sh +++ b/devcluster/app/setup_app_node_module.sh @@ -49,25 +49,25 @@ NPM_ARCHIVE_FILE= # Parses cli args while true; do - case "${1-}" in - -d) DEBUG=1;; - -f) shift; NPM_ARCHIVE_FILE="${1-}";; - -h) usage_app_node_module;; - -t) shift; TAG="${1-}";; - -v) version;; - *) break;; - esac - shift + case "${1-}" in + -d) DEBUG=1;; + -f) shift; NPM_ARCHIVE_FILE="${1-}";; + -h) usage_app_node_module;; + -t) shift; TAG="${1-}";; + -v) version;; + *) break;; + esac + shift done # Determines the TAG if test -z "${TAG-}"; then - # Determines the debug mode - if test "${DEBUG}" -eq 1; then - TAG="$(basename $0) -s" - else - TAG=$(basename $0) - fi + # Determines the debug mode + if test "${DEBUG}" -eq 1; then + TAG="$(basename $0) -s" + else + TAG=$(basename $0) + fi fi # The first message is always visible. @@ -75,14 +75,14 @@ logger -t $(basename $0) -s -p user.info "$(basename $0) ${VERSION}" # Loads cluster common functions if ! test -r "${SRCDIR}/../cluster_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" + exit 1 fi . ${SRCDIR}/../cluster_functions # Loads functions if setup_app_node_module_functions file exists if test -r "${SRCDIR}/setup_${COMPONENT}_node_module_functions"; then - . ${SRCDIR}/setup_${COMPONENT}_node_module_functions + . ${SRCDIR}/setup_${COMPONENT}_node_module_functions fi # npm_init @@ -90,8 +90,8 @@ logger -t ${TAG} -p user.debug "npm_init" npm_init RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "npm_init should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "npm_init should return zero, not ${RET}" + exit 1 fi ######## @@ -103,29 +103,29 @@ fi # TMPDIR=$(mktemp -d) if ! test -d "${TMPDIR}"; then - logger -t ${TAG} -p user.err "[NO] no ${TMPDIR}" - exit 1 + logger -t ${TAG} -p user.err "[NO] no ${TMPDIR}" + exit 1 fi cd ${TMPDIR} # Detects a package archive file. if ! test -n "${NPM_ARCHIVE_FILE}"; then - # this command overrite existing k2hr3-app-*.tgz. - npm pack k2hr3-${COMPONENT} - if test "${?}" != 0; then + # this command overrite existing k2hr3-app-*.tgz. + npm pack k2hr3-${COMPONENT} + if test "${?}" != 0; then logger -t ${TAG} -p user.err "[NO] npm pack k2hr3-${COMPONENT}" rm -rf ${TMPDIR} exit 1 - fi - NPM_ARCHIVE_FILE=$(ls k2hr3-${COMPONENT}-*.tgz) + fi + NPM_ARCHIVE_FILE=$(ls k2hr3-${COMPONENT}-*.tgz) fi # Unzips the package archive file. tar xzf ${NPM_ARCHIVE_FILE} if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] tar xzf ${NPM_ARCHIVE_FILE}" - rm -rf ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] tar xzf ${NPM_ARCHIVE_FILE}" + rm -rf ${TMPDIR} + exit 1 fi # Package directory shows up after unzip the archive file. @@ -136,22 +136,12 @@ if ! test -d "package"; then fi cd package -# Runs package-json.js if exists. -if test -f "${SRCDIR}/package-json.js"; then - node ${SRCDIR}/package-json.js - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] node ${SRCDIR}/package-json.js" - rm -rf ${SRCDIR} - exit 1 - fi -fi - # Makes a node app environment in this directory npm install if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] npm install" - rm -rf ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] npm install" + rm -rf ${TMPDIR} + exit 1 fi ######## @@ -162,25 +152,26 @@ logger -t ${TAG} -p user.info "5. Configures the default local.json of the k2hr3 # Runs local-json.js if exists. if test -f "${SRCDIR}/local-json.js"; then - node ${SRCDIR}/local-json.js ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ./local.json - if test "${?}" != 0; then - rm -rf ${TMPDIR} - logger -t ${TAG} -p user.err "node ${SRCDIR}/local-json.js ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ./local.json" - exit 1 - fi - if test -f "./local.json"; then - install -C -D -g users -m 0444 -o ${USER} -v ./local.json ./config/local.json - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] install -C -D -g users -m 0444 -o ${USER} -v ./local.json ./config/local.json" - rm -rf ${TMPDIR} - exit 1 - fi - else - logger -t ${TAG} -p user.err "[NO] ./local.json not found" - exit 1 - fi + node ${SRCDIR}/local-json.js ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ./local.json + if test "${?}" != 0; then + rm -rf ${TMPDIR} + logger -t ${TAG} -p user.err "node ${SRCDIR}/local-json.js ${SRCDIR}/setup_${COMPONENT}_${OS_NAME}.ini ./local.json" + exit 1 + fi + + if test -f "./local.json"; then + install -C -D -g users -m 0444 -o ${USER} -v ./local.json ./config/local.json + if test "${?}" != 0; then + logger -t ${TAG} -p user.err "[NO] install -C -D -g users -m 0444 -o ${USER} -v ./local.json ./config/local.json" + rm -rf ${TMPDIR} + exit 1 + fi + else + logger -t ${TAG} -p user.err "[NO] ./local.json not found" + exit 1 + fi else - logger -t ${TAG} -p user.debug "${SRCDIR}/local-json.js not found, which is not a problem." + logger -t ${TAG} -p user.debug "${SRCDIR}/local-json.js not found, which is not a problem." fi ######## @@ -191,105 +182,52 @@ logger -t ${TAG} -p user.info "6. Installs the configured local.json of the k2hr # Invokes an error if no local.json found if ! test -f "./config/local.json"; then - logger -t ${TAG} -p user.err "[NO] no ./config/local.json found" - rm -rf ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] no ./config/local.json found" + rm -rf ${TMPDIR} + exit 1 fi -# Copies something like a nodejs libraries to the "lib" directory -for file in ${SRCDIR}/routes/*.js; do - if test -f "${file}"; then - install -C -g users -m 0444 -o ${USER} -v ${file} ./routes/ - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] install -C -D -m 0444 -o ${USER} -v ${file} ./routes/" - rm -rf ${TMPDIR} - exit 1 - fi - else - logger -t ${TAG} -p user.err "[NO] ${file} not found" - rm -rf ${TMPDIR} - exit 1 - fi -done -for file in ${SRCDIR}/routes/lib/*.js; do - if test -f "${file}"; then - install -C -D -g users -m 0444 -o ${USER} -v ${file} ./routes/lib/ - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] install -C -D -m 0444 -o ${USER} -v ${file} ./routes/lib/" - rm -rf ${TMPDIR} - exit 1 - fi - else - logger -t ${TAG} -p user.err "[NO] ${file} not found" - rm -rf ${TMPDIR} - exit 1 - fi -done - # Installs server a cert and a key if test -f "${SRCDIR}/key.pem" -a -f "${SRCDIR}/cert.pem"; then - install -C -D -g users -m 0400 -o ${USER} -v ${SRCDIR}/key.pem ./config/key.pem - install -C -D -g users -m 0444 -o ${USER} -v ${SRCDIR}/cert.pem ./config/cert.pem + install -C -D -g users -m 0400 -o ${USER} -v ${SRCDIR}/key.pem ./config/key.pem + install -C -D -g users -m 0444 -o ${USER} -v ${SRCDIR}/cert.pem ./config/cert.pem else - openssl genrsa 2024 > ./config/key.pem - if ! test -f "./config/key.pem"; then - logger -t ${TAG} -p user.err "[NO] ./config/key.pem not found" - rm -rf ${TMPDIR} - exit 1 - fi - chmod 400 ./config/key.pem - openssl req -new -key ./config/key.pem -sha256 -config ${SRCDIR}/openssl_sample.conf > ./config/cert.csr - openssl x509 -req -days 3650 -signkey ./config/key.pem < ./config/cert.csr > ./config/cert.pem -fi -# Copies if key files exist -if test -f "${SRCDIR}/private.pem"; then - install -C -g users -m 0400 -o ${USER} -v ${SRCDIR}/private.pem ./config/ - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] install -C -m 0400 -o ${USER} -v ${SRCDIR}/private.pem ./config/" - rm -rf ${TMPDIR} - exit 1 - fi + openssl genrsa 2024 > ./config/key.pem + if ! test -f "./config/key.pem"; then + logger -t ${TAG} -p user.err "[NO] ./config/key.pem not found" + rm -rf ${TMPDIR} + exit 1 + fi + chmod 400 ./config/key.pem + openssl req -new -key ./config/key.pem -sha256 -config ${SRCDIR}/openssl_sample.conf > ./config/cert.csr + openssl x509 -req -days 3650 -signkey ./config/key.pem < ./config/cert.csr > ./config/cert.pem fi -# Copies if configuration files exist -for file in ${SRCDIR}/*.conf; do - if test -f "${file}"; then - install -C -g users -m 0400 -o ${USER} -v ${file} ./config/ - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] install -C -m 0444 -o ${USER} -v ${file} ./config/" - rm -rf ${TMPDIR} - exit 1 - fi - else - logger -t ${TAG} -p user.err "[NO] ${file} not found" - rm -rf ${TMPDIR} - exit 1 - fi -done cd ${HOME} if test -d "k2hr3-${COMPONENT}.old"; then - NOW=$(date +%s) - mv -f k2hr3-${COMPONENT}.old k2hr3-${COMPONENT}.old.${NOW} - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] mv -f k2hr3-${COMPONENT}.old k2hr3-${COMPONENT}.old.${NOW}" - rm -rf ${SRCDIR} - exit 1 - fi + NOW=$(date +%s) + mv -f k2hr3-${COMPONENT}.old k2hr3-${COMPONENT}.old.${NOW} + if test "${?}" != 0; then + logger -t ${TAG} -p user.err "[NO] mv -f k2hr3-${COMPONENT}.old k2hr3-${COMPONENT}.old.${NOW}" + rm -rf ${SRCDIR} + exit 1 + fi fi + if test -d "k2hr3-${COMPONENT}"; then - mv k2hr3-${COMPONENT} k2hr3-${COMPONENT}.old - if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] mv k2hr3-${COMPONENT} k2hr3-${COMPONENT}.old" - rm -rf ${SRCDIR} - exit 1 - fi + mv k2hr3-${COMPONENT} k2hr3-${COMPONENT}.old + if test "${?}" != 0; then + logger -t ${TAG} -p user.err "[NO] mv k2hr3-${COMPONENT} k2hr3-${COMPONENT}.old" + rm -rf ${SRCDIR} + exit 1 + fi fi mv ${TMPDIR}/package k2hr3-${COMPONENT} if test "${?}" != 0; then - logger -t ${TAG} -p user.err "[NO] mv ${TMPDIR}/package k2hr3-${COMPONENT}" - mv k2hr3-${COMPONENT}.old k2hr3-${COMPONENT} - rm -rf ${SRCDIR} ${TMPDIR} - exit 1 + logger -t ${TAG} -p user.err "[NO] mv ${TMPDIR}/package k2hr3-${COMPONENT}" + mv k2hr3-${COMPONENT}.old k2hr3-${COMPONENT} + rm -rf ${SRCDIR} ${TMPDIR} + exit 1 fi # The final message displays the time elapsed. @@ -299,7 +237,10 @@ logger -t $(basename $0) -s -p user.info "completed in ${ELAPSED} seconds" exit 0 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/chmpx/slave.ini b/devcluster/chmpx/chmpx.ini similarity index 85% rename from devcluster/chmpx/slave.ini rename to devcluster/chmpx/chmpx.ini index d885f27..772dc39 100644 --- a/devcluster/chmpx/slave.ini +++ b/devcluster/chmpx/chmpx.ini @@ -36,15 +36,15 @@ DATE = Wed, 19 Apr 2017 08:10:17 +0900 GROUP = K2HR3DKC MODE = SLAVE DELIVERMODE = hash -MAXCHMPX = 256 +MAXCHMPX = 256 REPLICA = 1 -MAXMQSERVER = 8 -MAXMQCLIENT = 256 -MQPERATTACH = 1 +MAXMQSERVER = 8 +MAXMQCLIENT = 256 +MQPERATTACH = 1 MAXQPERSERVERMQ = 8 -MAXQPERCLIENTMQ = 16 -MAXMQPERCLIENT = 256 -MAXHISTLOG = 0 +MAXQPERCLIENTMQ = 16 +MAXMQPERCLIENT = 256 +MAXHISTLOG = 0 #PORT = 8030 CTLPORT = 8031 SELFCTLPORT = 8031 @@ -71,7 +71,7 @@ K2HMAXELE = 16 # SERVER NODES SECTION # [SVRNODE] -NAME = localhost +NAME = localhost PORT = 8020 CTLPORT = 8021 SSL = no @@ -84,7 +84,10 @@ NAME = [.]* CTLPORT = 8031 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/chmpx/server.ini b/devcluster/chmpx/k2hdkc.ini similarity index 82% rename from devcluster/chmpx/server.ini rename to devcluster/chmpx/k2hdkc.ini index a46916f..e1ab0c9 100644 --- a/devcluster/chmpx/server.ini +++ b/devcluster/chmpx/k2hdkc.ini @@ -36,15 +36,15 @@ DATE = Wed, 19 Apr 2017 08:10:17 +0900 GROUP = K2HR3DKC MODE = SERVER DELIVERMODE = hash -MAXCHMPX = 256 +MAXCHMPX = 256 REPLICA = 1 -MAXMQSERVER = 8 -MAXMQCLIENT = 128 -MQPERATTACH = 8 +MAXMQSERVER = 8 +MAXMQCLIENT = 128 +MQPERATTACH = 8 MAXQPERSERVERMQ = 8 -MAXQPERCLIENTMQ = 8 -MAXMQPERCLIENT = 16 -MAXHISTLOG = 0 +MAXQPERCLIENTMQ = 8 +MAXMQPERCLIENT = 16 +MAXHISTLOG = 0 PORT = 8020 CTLPORT = 8021 SELFCTLPORT = 8021 @@ -71,7 +71,7 @@ K2HMAXELE = 16 # SERVER NODES SECTION # [SVRNODE] -NAME = localhost +NAME = localhost PORT = 8020 CTLPORT = 8021 SSL = no @@ -90,12 +90,12 @@ CTLPORT = 8031 #RCVTIMEOUT = 1000 ### Default(1000), timeout ms for receiving command result. #SVRNODEINI = ### Default(empty = same this file) #REPLCLUSTERINI = ### Default(empty), for DTOR INI FILE because transaction chmpx is different from this file - ### everything about dtor setting is specified in replclusterini file. - ### If needs, you can set that dtor runs with plugin and putting file(transaction). + ### everything about dtor setting is specified in replclusterini file. + ### If needs, you can set that dtor runs with plugin and putting file(transaction). #DTORTHREADCNT = 1 ### Default(1), you MUST set same as the value in k2htpdtor configuration file #DTORCTP = path.so ### Default(k2htpdtor.so), custom transaction plugin path -K2HTYPE = file ### Default(file), parameter can be set M/MEM/MEMORY / F/FILE / T/TEMP/TEMPORARY -K2HFILE = /var/lib/k2hdkc/k2hdkc.k2h +K2HTYPE = file ### Default(file), parameter can be set M/MEM/MEMORY / F/FILE / T/TEMP/TEMPORARY +K2HFILE = /var/lib/k2hdkc/k2hdkc.k2h K2HFULLMAP = on ### Default(on) K2HINIT = no ### Default(no) K2HMASKBIT = 8 @@ -112,7 +112,10 @@ MAXTHREAD = 20 ### Default(100), maximum processing thread count #REDUCETIME = 30 ### Default(30), time(second) for reducing processing thread to minimum thread count. # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/chmpx/override.conf b/devcluster/chmpx/override.conf index 6e86c72..6819460 100644 --- a/devcluster/chmpx/override.conf +++ b/devcluster/chmpx/override.conf @@ -35,6 +35,11 @@ k2hdkc-service-helper.conf:SUBPROCESS_USER = k2hr3 k2hdkc-service-helper.conf:WAIT_DEPENDPROC_PIDFILE = /var/run/antpickax/chmpx.pid k2hdkc-service-helper.conf:WAIT_SEC_AFTER_DEPENDPROC_UP = 30 +#chmpx-service-helper.conf:LOGDIR = /var/log/antpickax +#chmpx-service-helper.conf:SUBPROCESS_LOGFILE = chmpx.log +chmpx-service-helper.conf:SUBPROCESS_OPTIONS = -d dump +k2hdkc-service-helper.conf:SUBPROCESS_OPTIONS = -d dump + # # Local variables: # tab-width: 4 @@ -43,4 +48,3 @@ k2hdkc-service-helper.conf:WAIT_SEC_AFTER_DEPENDPROC_UP = 30 # vim600: noexpandtab sw=4 ts=4 fdm=marker # vim<600: noexpandtab sw=4 ts=4 # - diff --git a/devcluster/chmpx/setup_chmpx_functions b/devcluster/chmpx/setup_chmpx_functions index 3a958ca..d24e3bf 100644 --- a/devcluster/chmpx/setup_chmpx_functions +++ b/devcluster/chmpx/setup_chmpx_functions @@ -30,35 +30,35 @@ # 0 on success # 1 on failure # -configure_chmpx_server_ini() { - _chmpx_server_ini_file=${1:?"chmpx_server_ini_file must be nonzero"} - _chmpx_server_name=${2:?"chmpx_server_name must be nonzero"} - _k2hdkc_data_dir=${3:?"k2hdkc_data_dir must be nonzero"} +configure_chmpx_k2hdkc_ini() { + _chmpx_k2hdkc_ini_file=${1:?"chmpx_k2hdkc_ini_file must be nonzero"} + _chmpx_server_name=${2:?"chmpx_server_name must be nonzero"} + _k2hdkc_data_dir=${3:?"k2hdkc_data_dir must be nonzero"} - logger -t ${TAG} -p user.debug "configure_chmpx_server_ini _chmpx_server_ini_file=${_chmpx_server_ini_file} _chmpx_server_name=${_chmpx_server_name} _k2hdkc_data_dir=${_k2hdkc_data_dir}" + logger -t ${TAG} -p user.debug "configure_chmpx_k2hdkc_ini _chmpx_k2hdkc_ini_file=${_chmpx_k2hdkc_ini_file} _chmpx_server_name=${_chmpx_server_name} _k2hdkc_data_dir=${_k2hdkc_data_dir}" - if test -f "${_chmpx_server_ini_file}" -a -n "${_chmpx_server_name}" -a -n "${_k2hdkc_data_dir}"; then - logger -t ${TAG} -p user.debug "perl -pi -e \"BEGIN{undef $/;} s|\[SVRNODE\].*\nPORT|[SVRNODE]\nNAME = ${_chmpx_server_name}\nPORT|smg\" ${_chmpx_server_ini_file}" - perl -pi -e "BEGIN{undef $/;} s|\[SVRNODE\].*\nPORT|[SVRNODE]\nNAME = ${_chmpx_server_name}\nPORT|smg" ${_chmpx_server_ini_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - logger -t ${TAG} -p user.debug "perl -pi -e \"s|^K2HFILE.*$|K2HFILE = ${_k2hdkc_data_dir}/k2hdkc.k2h|g\" ${_chmpx_server_ini_file}" - perl -pi -e "s|^K2HFILE.*$|K2HFILE = ${_k2hdkc_data_dir}/k2hdkc.k2h|g" ${_chmpx_server_ini_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "_chmpx_server_name should be nonzero, ${_chmpx_server_name}" - logger -t ${TAG} -p user.err "_k2hdkc_data_dir should be nonzero, ${_k2hdkc_data_dir}" - logger -t ${TAG} -p user.err "${_chmpx_server_ini_file} should exists" - return 1 - fi - return 0 + if test -f "${_chmpx_k2hdkc_ini_file}" -a -n "${_chmpx_server_name}" -a -n "${_k2hdkc_data_dir}"; then + logger -t ${TAG} -p user.debug "perl -pi -e \"BEGIN{undef $/;} s|\[SVRNODE\].*\nPORT|[SVRNODE]\nNAME = ${_chmpx_server_name}\nPORT|smg\" ${_chmpx_k2hdkc_ini_file}" + perl -pi -e "BEGIN{undef $/;} s|\[SVRNODE\].*\nPORT|[SVRNODE]\nNAME = ${_chmpx_server_name}\nPORT|smg" ${_chmpx_k2hdkc_ini_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + logger -t ${TAG} -p user.debug "perl -pi -e \"s|^K2HFILE.*$|K2HFILE = ${_k2hdkc_data_dir}/k2hdkc.k2h|g\" ${_chmpx_k2hdkc_ini_file}" + perl -pi -e "s|^K2HFILE.*$|K2HFILE = ${_k2hdkc_data_dir}/k2hdkc.k2h|g" ${_chmpx_k2hdkc_ini_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "_chmpx_server_name should be nonzero, ${_chmpx_server_name}" + logger -t ${TAG} -p user.err "_k2hdkc_data_dir should be nonzero, ${_k2hdkc_data_dir}" + logger -t ${TAG} -p user.err "${_chmpx_k2hdkc_ini_file} should exists" + return 1 + fi + return 0 } # Configures the chmpx slave's default configuration @@ -71,26 +71,26 @@ configure_chmpx_server_ini() { # 0 on success # 1 on failure # -configure_chmpx_slave_ini() { - _chmpx_slave_ini_file=${1:?"chmpx_slave_ini_file must be nonzero"} - _chmpx_server_name=${2:?"chmpx_server_name must be nonzero"} +configure_chmpx_chmpx_ini() { + _chmpx_chmpx_ini_file=${1:?"chmpx_chmpx_ini_file must be nonzero"} + _chmpx_server_name=${2:?"chmpx_server_name must be nonzero"} - logger -t ${TAG} -p user.debug "configure_chmpx_slave_ini _chmpx_slave_ini_file=${_chmpx_slave_ini_file} _chmpx_server_name=${_chmpx_server_name}" + logger -t ${TAG} -p user.debug "configure_chmpx_chmpx_ini _chmpx_chmpx_ini_file=${_chmpx_chmpx_ini_file} _chmpx_server_name=${_chmpx_server_name}" - if test -f "${_chmpx_slave_ini_file}" -a -n "${_chmpx_server_name}"; then - logger -t ${TAG} -p user.debug "perl -pi -e \"BEGIN{undef $/;} s|\[SVRNODE\].*\\nPORT|[SVRNODE]\\nNAME = ${_chmpx_server_name}\\nPORT|smg\" ${_chmpx_slave_ini_file}\n" - perl -pi -e "BEGIN{undef $/;} s|\[SVRNODE\].*\nPORT|[SVRNODE]\nNAME = ${_chmpx_server_name}\nPORT|smg" ${_chmpx_slave_ini_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "${_chmpx_slave_ini_file} must exist" - logger -t ${TAG} -p user.err "chmpx_server_name should be nonzero, ${_chmpx_server_name}" - return 1 - fi - return 0 + if test -f "${_chmpx_chmpx_ini_file}" -a -n "${_chmpx_server_name}"; then + logger -t ${TAG} -p user.debug "perl -pi -e \"BEGIN{undef $/;} s|\[SVRNODE\].*\\nPORT|[SVRNODE]\\nNAME = ${_chmpx_server_name}\\nPORT|smg\" ${_chmpx_chmpx_ini_file}\n" + perl -pi -e "BEGIN{undef $/;} s|\[SVRNODE\].*\nPORT|[SVRNODE]\nNAME = ${_chmpx_server_name}\nPORT|smg" ${_chmpx_chmpx_ini_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "${_chmpx_chmpx_ini_file} must exist" + logger -t ${TAG} -p user.err "chmpx_server_name should be nonzero, ${_chmpx_server_name}" + return 1 + fi + return 0 } # Installs the configured chmpx config file @@ -104,29 +104,29 @@ configure_chmpx_slave_ini() { # 1 on failure # install_chmpx_conf() { - _src_chmpx_conf_file=${1:?"src_chmpx_conf_file must be nonzero"} - _dst_chmpx_conf_file=${2:?"dst_chmpx_conf_file must be nonzero"} + _src_chmpx_conf_file=${1:?"src_chmpx_conf_file must be nonzero"} + _dst_chmpx_conf_file=${2:?"dst_chmpx_conf_file must be nonzero"} - logger -t ${TAG} -p user.debug "install_chmpx_conf _src_chmpx_conf_file=${_src_chmpx_conf_file} _dst_chmpx_conf_file=${_dst_chmpx_conf_file}" - # A dry run returns 0 - if test -n "${DRYRUN-}"; then - return 0 - fi + logger -t ${TAG} -p user.debug "install_chmpx_conf _src_chmpx_conf_file=${_src_chmpx_conf_file} _dst_chmpx_conf_file=${_dst_chmpx_conf_file}" + # A dry run returns 0 + if test -n "${DRYRUN-}"; then + return 0 + fi - if test -n "${_src_chmpx_conf_file}" -a -n "${_dst_chmpx_conf_file}"; then - logger -t ${TAG} -p user.debug "sudo install -C -m 0644 -o root -v ${_src_chmpx_conf_file} ${_dst_chmpx_conf_file}" - sudo install -C -m 0644 -o root -v ${_src_chmpx_conf_file} ${_dst_chmpx_conf_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "src_chmpx_conf_file should be nonzero, ${_src_chmpx_conf_file}" - logger -t ${TAG} -p user.err "dst_chmpx_conf_file should be nonzero, ${_dst_chmpx_conf_file}" - return 1 - fi - return 0 + if test -n "${_src_chmpx_conf_file}" -a -n "${_dst_chmpx_conf_file}"; then + logger -t ${TAG} -p user.debug "sudo install -C -m 0644 -o root -v ${_src_chmpx_conf_file} ${_dst_chmpx_conf_file}" + sudo install -C -m 0644 -o root -v ${_src_chmpx_conf_file} ${_dst_chmpx_conf_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "src_chmpx_conf_file should be nonzero, ${_src_chmpx_conf_file}" + logger -t ${TAG} -p user.err "dst_chmpx_conf_file should be nonzero, ${_dst_chmpx_conf_file}" + return 1 + fi + return 0 } # Configures the chmpx, chmpx-slave and k2hdkc's service manager default configuration @@ -148,73 +148,73 @@ install_chmpx_conf() { # COMPONENT # configure_chmpx_service_manager_file() { - _service_manager=${1:?"service_manager must be nonzero"} - _service_manager_file=${2:?"service_manager_file must be nonzero"} - _k2hr3_dkc_runuser=${3:?"k2hr3_${COMPONENT}_runuser must be nonzero"} - _chmpx_conf_file=${4:?"chmpx_conf_file must be nonzero"} - _chmpx_msg_max=${5:?"chmpx_msg_max must be nonzero"} - _is_k2hdkc=${6:-} - _loglevel=${7:-err} + _service_manager=${1:?"service_manager must be nonzero"} + _service_manager_file=${2:?"service_manager_file must be nonzero"} + _k2hr3_dkc_runuser=${3:?"k2hr3_${COMPONENT}_runuser must be nonzero"} + _chmpx_conf_file=${4:?"chmpx_conf_file must be nonzero"} + _chmpx_msg_max=${5:?"chmpx_msg_max must be nonzero"} + _is_k2hdkc=${6:-} + _loglevel=${7:-err} - logger -t ${TAG} -p user.debug "configure_chmpx_service_manager_file _service_manager=${_service_manager} _service_manager_file=${_service_manager_file} _k2hr3_dkc_runuser=${_k2hr3_dkc_runuser} _chmpx_conf_file=${_chmpx_conf_file} _chmpx_msg_max=${_chmpx_msg_max} _is_k2hdkc=${_is_k2hdkc} _loglevel=${_loglevel}" + logger -t ${TAG} -p user.debug "configure_chmpx_service_manager_file _service_manager=${_service_manager} _service_manager_file=${_service_manager_file} _k2hr3_dkc_runuser=${_k2hr3_dkc_runuser} _chmpx_conf_file=${_chmpx_conf_file} _chmpx_msg_max=${_chmpx_msg_max} _is_k2hdkc=${_is_k2hdkc} _loglevel=${_loglevel}" - if test "${_service_manager}" = "systemd"; then - if test -f "${_service_manager_file}"; then - # Replaces "User=k2hr3" with a user defined value - if test -n "${_k2hr3_dkc_runuser}"; then - logger -t ${TAG} -p user.debug "perl -pi -e \"s|User=.*$|User=${_k2hr3_dkc_runuser}|g\" ${_service_manager_file}" - perl -pi -e "s|User=.*$|User=${_k2hr3_dkc_runuser}|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "k2hr3_dkc_runuser must be nonzero" - return 1 - fi + if test "${_service_manager}" = "systemd"; then + if test -f "${_service_manager_file}"; then + # Replaces "User=k2hr3" with a user defined value + if test -n "${_k2hr3_dkc_runuser}"; then + logger -t ${TAG} -p user.debug "perl -pi -e \"s|User=.*$|User=${_k2hr3_dkc_runuser}|g\" ${_service_manager_file}" + perl -pi -e "s|User=.*$|User=${_k2hr3_dkc_runuser}|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "k2hr3_dkc_runuser must be nonzero" + return 1 + fi - # Replaces "fs.mqueue.msg_max=264" with a user defined value - if test -n "${_chmpx_msg_max}"; then - logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStartPre=.*fs.mqueue.msg_max=\d+$|ExecStartPre=/sbin/sysctl fs.mqueue.msg_max=${_chmpx_msg_max}|g\" ${_service_manager_file}" - perl -pi -e "s|ExecStartPre=.*fs.mqueue.msg_max=\d+$|ExecStartPre=/sbin/sysctl fs.mqueue.msg_max=${_chmpx_msg_max}|g" ${_service_manager_file} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "service_manager_file must be nonzero" - return 1 - fi + # Replaces "fs.mqueue.msg_max=264" with a user defined value + if test -n "${_chmpx_msg_max}"; then + logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStartPre=.*fs.mqueue.msg_max=\d+$|ExecStartPre=/sbin/sysctl fs.mqueue.msg_max=${_chmpx_msg_max}|g\" ${_service_manager_file}" + perl -pi -e "s|ExecStartPre=.*fs.mqueue.msg_max=\d+$|ExecStartPre=/sbin/sysctl fs.mqueue.msg_max=${_chmpx_msg_max}|g" ${_service_manager_file} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "service_manager_file must be nonzero" + return 1 + fi - # Replaces "/etc/k2hdkc/server.ini" with a user defined value - if test -n "${_chmpx_conf_file}"; then - if test "${_is_k2hdkc}" -eq 1; then - logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStart=.*$|ExecStart=/usr/bin/k2hdkc -conf ${_chmpx_conf_file} -d ${_loglevel}|g\" ${_service_manager_file}" - perl -pi -e "s|ExecStart=.*$|ExecStart=/usr/bin/k2hdkc -conf ${_chmpx_conf_file} -d ${_loglevel}|g" ${_service_manager_file} - else - logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStart=.*$|ExecStart=/usr/bin/chmpx -conf ${_chmpx_conf_file} -d ${_loglevel}|g\" ${_service_manager_file}" - perl -pi -e "s|ExecStart=.*$|ExecStart=/usr/bin/chmpx -conf ${_chmpx_conf_file} -d ${_loglevel}|g" ${_service_manager_file} - fi - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "chmpx_conf_file must be nonzero" - return 1 - fi - else - logger -t ${TAG} -p user.err "${_service_manager_file} should exists" - return 1 - fi - else - logger -t ${TAG} -p user.err "${_service_manager} is either systemd, not ${_service_manager}" - return 1 - fi - return 0 + # Replaces "/etc/k2hdkc/k2hdkc.ini" with a user defined value + if test -n "${_chmpx_conf_file}"; then + if test "${_is_k2hdkc}" -eq 1; then + logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStart=.*$|ExecStart=/usr/bin/k2hdkc -conf ${_chmpx_conf_file} -d ${_loglevel}|g\" ${_service_manager_file}" + perl -pi -e "s|ExecStart=.*$|ExecStart=/usr/bin/k2hdkc -conf ${_chmpx_conf_file} -d ${_loglevel}|g" ${_service_manager_file} + else + logger -t ${TAG} -p user.debug "perl -pi -e \"s|ExecStart=.*$|ExecStart=/usr/bin/chmpx -conf ${_chmpx_conf_file} -d ${_loglevel}|g\" ${_service_manager_file}" + perl -pi -e "s|ExecStart=.*$|ExecStart=/usr/bin/chmpx -conf ${_chmpx_conf_file} -d ${_loglevel}|g" ${_service_manager_file} + fi + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "chmpx_conf_file must be nonzero" + return 1 + fi + else + logger -t ${TAG} -p user.err "${_service_manager_file} should exists" + return 1 + fi + else + logger -t ${TAG} -p user.err "${_service_manager} is either systemd, not ${_service_manager}" + return 1 + fi + return 0 } # Makes the k2hdkc data directory @@ -231,55 +231,55 @@ configure_chmpx_service_manager_file() { # OS_NAME # make_k2hdkc_data_dir() { - _runuser=${1:?"runuser must be nonzero"} - _k2hdkc_data_dir=${2:?"k2hdkc_data_dir must be nonzero"} + _runuser=${1:?"runuser must be nonzero"} + _k2hdkc_data_dir=${2:?"k2hdkc_data_dir must be nonzero"} - logger -t ${TAG} -p user.debug "make_k2hdkc_data_dir _runuser=${_runuser} _k2hdkc_data_dir=${_k2hdkc_data_dir}" - # A dry run returns 0 - if test -n "${DRYRUN-}"; then - return 0 - fi + logger -t ${TAG} -p user.debug "make_k2hdkc_data_dir _runuser=${_runuser} _k2hdkc_data_dir=${_k2hdkc_data_dir}" + # A dry run returns 0 + if test -n "${DRYRUN-}"; then + return 0 + fi - if test -n "${_k2hdkc_data_dir}" -a -n ${_runuser}; then - logger -t ${TAG} -p user.debug "id ${_runuser}" - id "${_runuser}" - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.warn "RESULT should be zero, not ${RESULT}" - if test "${OS_NAME}" = "debian" -o "${OS_NAME}" = "ubuntu"; then - logger -t ${TAG} -p user.debug "sudo adduser --disabled-password --gecos \"\" ${_runuser}" - sudo adduser --disabled-password --gecos "" "${_runuser}" - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.debug "sudo adduser ${_runuser}" - sudo adduser "${_runuser}" - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - fi - fi - if test ! -d "${_k2hdkc_data_dir}"; then - logger -t ${TAG} -p user.debug "sudo install -o ${_runuser} -d ${_k2hdkc_data_dir}" - sudo install -o ${_runuser} -d ${_k2hdkc_data_dir} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.warn "k2hdkc_data_dir already exists, ${_k2hdkc_data_dir}" - fi - else - logger -t ${TAG} -p user.err "k2hdkc_data_dir and runuser should be nonzero, ${_k2hdkc_data_dir}, ${_runuser}" - return 1 - fi - return 0 + if test -n "${_k2hdkc_data_dir}" -a -n ${_runuser}; then + logger -t ${TAG} -p user.debug "id ${_runuser}" + id "${_runuser}" + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.warn "RESULT should be zero, not ${RESULT}" + if test "${OS_NAME}" = "debian" -o "${OS_NAME}" = "ubuntu"; then + logger -t ${TAG} -p user.debug "sudo adduser --disabled-password --gecos \"\" ${_runuser}" + sudo adduser --disabled-password --gecos "" "${_runuser}" + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.debug "sudo adduser ${_runuser}" + sudo adduser "${_runuser}" + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + fi + fi + if test ! -d "${_k2hdkc_data_dir}"; then + logger -t ${TAG} -p user.debug "sudo install -o ${_runuser} -d ${_k2hdkc_data_dir}" + sudo install -o ${_runuser} -d ${_k2hdkc_data_dir} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.warn "k2hdkc_data_dir already exists, ${_k2hdkc_data_dir}" + fi + else + logger -t ${TAG} -p user.err "k2hdkc_data_dir and runuser should be nonzero, ${_k2hdkc_data_dir}, ${_runuser}" + return 1 + fi + return 0 } # Makes the k2hdkc conf directory @@ -292,29 +292,32 @@ make_k2hdkc_data_dir() { # 1 on failure # make_k2hdkc_conf_dir() { - _k2hdkc_conf_dir=${1:?"k2hdkc_conf_dir must be nonzero"} + _k2hdkc_conf_dir=${1:?"k2hdkc_conf_dir must be nonzero"} - if test -n "${_k2hdkc_conf_dir}"; then - if test ! -d "${_k2hdkc_conf_dir}"; then - logger -t ${TAG} -p user.debug "sudo install -d ${_k2hdkc_conf_dir}" - sudo install -d ${_k2hdkc_conf_dir} - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.warn "_k2hdkc_conf_dir already exists, ${_k2hdkc_conf_dir}" - fi - else - logger -t ${TAG} -p user.err "k2hdkc_conf_dir should be nonzero, ${_k2hdkc_conf_dir}" - return 1 - fi - return 0 + if test -n "${_k2hdkc_conf_dir}"; then + if test ! -d "${_k2hdkc_conf_dir}"; then + logger -t ${TAG} -p user.debug "sudo install -d ${_k2hdkc_conf_dir}" + sudo install -d ${_k2hdkc_conf_dir} + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.warn "_k2hdkc_conf_dir already exists, ${_k2hdkc_conf_dir}" + fi + else + logger -t ${TAG} -p user.err "k2hdkc_conf_dir should be nonzero, ${_k2hdkc_conf_dir}" + return 1 + fi + return 0 } # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/cluster.sh b/devcluster/cluster.sh index fb2cdff..6c92e9d 100644 --- a/devcluster/cluster.sh +++ b/devcluster/cluster.sh @@ -60,103 +60,103 @@ VERSION=0.9.1 CLUSTER_STARTTIME=$(date +%s) usage_cluster() { - echo "usage : $(basename $0) [-d] [-h] [-i file] [-o file] [-p file] [-r] [-s openstack_url] [-t message_queue_url] [-v]" - echo " -d run in debug mode" - echo " -h display this message and exit" - echo " -i file k2hr3-api package file path(or URL)" - echo " -o file k2hr3-osnl package file path(or URL)" - echo " -p file k2hr3-app package file path(or URL)" - echo " -r run in dry run mode" - echo " -s url OpenStack Identity Service Endpoint(Default: 'http://127.0.0.1/identity')" - echo " -t url TransportURL(Default: 'rabbit://guest:guest@127.0.0.1:5672/')" - echo " -v display version and exit" - echo "" - exit 1 + echo "usage : $(basename $0) [-d] [-h] [-i file] [-o file] [-p file] [-r] [-s openstack_url] [-t message_queue_url] [-v]" + echo " -d run in debug mode" + echo " -h display this message and exit" + echo " -i file k2hr3-api package file path(or URL)" + echo " -o file k2hr3-osnl package file path(or URL)" + echo " -p file k2hr3-app package file path(or URL)" + echo " -r run in dry run mode" + echo " -s url OpenStack Identity Service Endpoint(Default: 'http://127.0.0.1/identity')" + echo " -t url TransportURL(Default: 'rabbit://guest:guest@127.0.0.1:5672/')" + echo " -v display version and exit" + echo "" + exit 1 } # parses cli args while true; do - case "${1-}" in - -d) DEBUG=1;; - -h) usage_cluster;; - -i) shift; API_NPM_ARCHIVE_FILE="${1-}";; - -o) shift; OSNL_PYPI_ARCHIVE_FILE="${1-}";; - -p) shift; APP_NPM_ARCHIVE_FILE="${1-}";; - -r) DRYRUN=1;; - -s) shift; IDENTITY_ENDPOINT="${1-}";; - -t) shift; TRANSPORT_URL="${1-}";; - -v) version;; - *) break;; - esac - shift + case "${1-}" in + -d) DEBUG=1;; + -h) usage_cluster;; + -i) shift; API_NPM_ARCHIVE_FILE="${1-}";; + -o) shift; OSNL_PYPI_ARCHIVE_FILE="${1-}";; + -p) shift; APP_NPM_ARCHIVE_FILE="${1-}";; + -r) DRYRUN=1;; + -s) shift; IDENTITY_ENDPOINT="${1-}";; + -t) shift; TRANSPORT_URL="${1-}";; + -v) version;; + *) break;; + esac + shift done # The first message is always visible. logger -t $(basename $0) -s -p user.info "$(basename $0) ${VERSION}" for component in dkc api app osnl; do - SCRIPT=${component}/setup_${component}.sh - if test -f "${SCRIPT}"; then - if test -n "${DEBUG-}"; then - SCRIPT="${SCRIPT} -d" - fi - if test -n "${DRYRUN-}"; then - SCRIPT="${SCRIPT} -r" - fi - case "${component}" in - dkc) - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT}" - sh ${SCRIPT} - ;; - api) - if test -n "${API_NPM_ARCHIVE_FILE}" -a -n "${IDENTITY_ENDPOINT}"; then - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${API_NPM_ARCHIVE_FILE} -i ${IDENTITY_ENDPOINT}" - sh ${SCRIPT} -f ${API_NPM_ARCHIVE_FILE} -i ${IDENTITY_ENDPOINT} - elif test -n "${API_NPM_ARCHIVE_FILE}" ; then - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${API_NPM_ARCHIVE_FILE}" - sh ${SCRIPT} -f ${API_NPM_ARCHIVE_FILE} - elif test -n "${IDENTITY_ENDPOINT}" ; then - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -i ${IDENTITY_ENDPOINT}" - sh ${SCRIPT} -i ${IDENTITY_ENDPOINT} - else - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT}" - sh ${SCRIPT} - fi - ;; - app) - if test -n "${APP_NPM_ARCHIVE_FILE}"; then - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${APP_NPM_ARCHIVE_FILE}" - sh ${SCRIPT} -f ${APP_NPM_ARCHIVE_FILE} - else - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT}" - sh ${SCRIPT} - fi - ;; - osnl) - if test -n "${OSNL_PYPI_ARCHIVE_FILE}" -a -n "${TRANSPORT_URL}"; then - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${OSNL_PYPI_ARCHIVE_FILE} -t ${TRANSPORT_URL}" - sh ${SCRIPT} -f ${OSNL_PYPI_ARCHIVE_FILE} -t ${TRANSPORT_URL} - elif test -n "${OSNL_PYPI_ARCHIVE_FILE}"; then - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${OSNL_PYPI_ARCHIVE_FILE}" - sh ${SCRIPT} -f ${OSNL_PYPI_ARCHIVE_FILE} - elif test -n "${TRANSPORT_URL}"; then - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -t ${TRANSPORT_URL}" - sh ${SCRIPT} -t ${TRANSPORT_URL} - else - logger -t $(basename $0) -s -p user.info "sh ${SCRIPT}" - sh ${SCRIPT} - fi - ;; - *) break;; - esac - if test "${?}" != 0; then - logger -t $(basename $0) -s -p user.error "[ERROR] ${SCRIPT} should return 0" - exit 1 - fi - else - logger -t $(basename $0) -s -p user.err "[ERROR] no ${SCRIPT}" - exit 1 - fi + SCRIPT=${component}/setup_${component}.sh + if test -f "${SCRIPT}"; then + if test -n "${DEBUG-}"; then + SCRIPT="${SCRIPT} -d" + fi + if test -n "${DRYRUN-}"; then + SCRIPT="${SCRIPT} -r" + fi + case "${component}" in + dkc) + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT}" + sh ${SCRIPT} + ;; + api) + if test -n "${API_NPM_ARCHIVE_FILE}" -a -n "${IDENTITY_ENDPOINT}"; then + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${API_NPM_ARCHIVE_FILE} -i ${IDENTITY_ENDPOINT}" + sh ${SCRIPT} -f ${API_NPM_ARCHIVE_FILE} -i ${IDENTITY_ENDPOINT} + elif test -n "${API_NPM_ARCHIVE_FILE}" ; then + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${API_NPM_ARCHIVE_FILE}" + sh ${SCRIPT} -f ${API_NPM_ARCHIVE_FILE} + elif test -n "${IDENTITY_ENDPOINT}" ; then + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -i ${IDENTITY_ENDPOINT}" + sh ${SCRIPT} -i ${IDENTITY_ENDPOINT} + else + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT}" + sh ${SCRIPT} + fi + ;; + app) + if test -n "${APP_NPM_ARCHIVE_FILE}"; then + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${APP_NPM_ARCHIVE_FILE}" + sh ${SCRIPT} -f ${APP_NPM_ARCHIVE_FILE} + else + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT}" + sh ${SCRIPT} + fi + ;; + osnl) + if test -n "${OSNL_PYPI_ARCHIVE_FILE}" -a -n "${TRANSPORT_URL}"; then + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${OSNL_PYPI_ARCHIVE_FILE} -t ${TRANSPORT_URL}" + sh ${SCRIPT} -f ${OSNL_PYPI_ARCHIVE_FILE} -t ${TRANSPORT_URL} + elif test -n "${OSNL_PYPI_ARCHIVE_FILE}"; then + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -f ${OSNL_PYPI_ARCHIVE_FILE}" + sh ${SCRIPT} -f ${OSNL_PYPI_ARCHIVE_FILE} + elif test -n "${TRANSPORT_URL}"; then + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT} -t ${TRANSPORT_URL}" + sh ${SCRIPT} -t ${TRANSPORT_URL} + else + logger -t $(basename $0) -s -p user.info "sh ${SCRIPT}" + sh ${SCRIPT} + fi + ;; + *) break;; + esac + if test "${?}" != 0; then + logger -t $(basename $0) -s -p user.error "[ERROR] ${SCRIPT} should return 0" + exit 1 + fi + else + logger -t $(basename $0) -s -p user.err "[ERROR] no ${SCRIPT}" + exit 1 + fi done # The final message displays the time elapsed. @@ -166,7 +166,10 @@ logger -t $(basename $0) -s -p user.info "completed in ${ELAPSED} seconds" exit 0 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/cluster_functions b/devcluster/cluster_functions index 5124db5..1698f8a 100644 --- a/devcluster/cluster_functions +++ b/devcluster/cluster_functions @@ -875,6 +875,13 @@ setup_npm_environment() { return 1 fi fi + logger -t ${TAG} -p user.debug "npm config set python /usr/bin/python3" + npm config set python /usr/bin/python3 + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi return 0 } diff --git a/devcluster/dkc/setup_dkc.sh b/devcluster/dkc/setup_dkc.sh index d817bd0..c3fd8b2 100644 --- a/devcluster/dkc/setup_dkc.sh +++ b/devcluster/dkc/setup_dkc.sh @@ -46,28 +46,28 @@ STARTTIME=$(date +%s) VERSION=0.10.0 if ! test -r "${SRCDIR}/../cluster_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" + exit 1 fi . ${SRCDIR}/../cluster_functions # parses cli args while true; do - case "${1-}" in - -d) DEBUG=1;; - -h) usage_dkc;; - -r) DRYRUN=1;; - -v) version;; - *) break;; - esac - shift + case "${1-}" in + -d) DEBUG=1;; + -h) usage_dkc;; + -r) DRYRUN=1;; + -v) version;; + *) break;; + esac + shift done # determines the debug mode if test "${DEBUG}" -eq 1; then - TAG="$(basename $0) -s" + TAG="$(basename $0) -s" else - TAG=$(basename $0) + TAG=$(basename $0) fi # The first message is always visible. @@ -83,16 +83,16 @@ logger -t ${TAG} -p user.info "1. Initializes environments" setup_os_env RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_os_env should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_os_env should return zero, not ${RET}" + exit 1 fi # Loads default settings setup_ini_env RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" + exit 1 fi ######## @@ -103,8 +103,8 @@ logger -t ${TAG} -p user.info "2. Ensures that the k2hdkc data directory exists" # Loads functions defined in setup_chmpx_functions if ! test -r "${SRCDIR}/../chmpx/setup_chmpx_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../chmpx/setup_chmpx_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../chmpx/setup_chmpx_functions should exist" + exit 1 fi . ${SRCDIR}/../chmpx/setup_chmpx_functions @@ -114,8 +114,8 @@ runuser=$(eval echo "\${$runuser_varname}") make_k2hdkc_data_dir ${runuser} ${k2hdkc_data_dir} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "make_k2hdkc_data_dir should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "make_k2hdkc_data_dir should return zero, not ${RET}" + exit 1 fi ######## @@ -129,8 +129,8 @@ k2hdkc_conf_dir=$(dirname ${chmpx_conf_file}) make_k2hdkc_conf_dir ${k2hdkc_conf_dir} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "make_k2hdkc_conf_dir should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "make_k2hdkc_conf_dir should return zero, not ${RET}" + exit 1 fi ######## @@ -143,16 +143,16 @@ logger -t ${TAG} -p user.info "4. Adds a new package repository" enable_packagecloud_io_repository ${package_script_base_url-} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_packagecloud_io_repository should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "enable_packagecloud_io_repository should return zero, not ${RET}" + exit 1 fi # Enables centos-PowerTools if centos enable_dnf_repository ${package_dnf_repo} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_dnf_repository should return zero, not ${RET}" - continue + logger -t ${TAG} -p user.err "enable_dnf_repository should return zero, not ${RET}" + continue fi ######## @@ -164,36 +164,36 @@ logger -t ${TAG} -p user.info "5. Installs OS dependent packages" # Some distros pre-install dkc required packages. In this case, users define # empty ${package_install_pkg} value in their initial configuration file. if test -n "${package_install_pkgs-}"; then - setup_install_os_packages "${package_install_pkgs-}" - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" - exit 1 - fi + setup_install_os_packages "${package_install_pkgs-}" + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" + exit 1 + fi else - logger -t ${TAG} -p user.info "5.1 Installs k2hdkc from source" - make_k2hdkc ${OS_NAME} - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "make_k2hdkc should return zero, not ${RET}" - exit 1 - fi + logger -t ${TAG} -p user.info "5.1 Installs k2hdkc from source" + make_k2hdkc ${OS_NAME} + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "make_k2hdkc should return zero, not ${RET}" + exit 1 + fi fi ######## # 6. Configures the chmpx default configuration -# The default server.ini contains dummy server name. You need to change it. +# The default k2hdkc.ini contains dummy server name. You need to change it. # logger -t ${TAG} -p user.info "6. Configures the default chmpx configuration" # Configures the chmpx default configuration file in INI file format -if test -f "${SRCDIR}/../chmpx/server.ini"; then - configure_chmpx_server_ini ${SRCDIR}/../chmpx/server.ini ${chmpx_server_name} ${k2hdkc_data_dir} - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "configure_chmpx_server_ini should return zero, not ${RET}" - exit 1 - fi +if test -f "${SRCDIR}/../chmpx/k2hdkc.ini"; then + configure_chmpx_k2hdkc_ini ${SRCDIR}/../chmpx/k2hdkc.ini ${chmpx_server_name} ${k2hdkc_data_dir} + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "configure_chmpx_k2hdkc_ini should return zero, not ${RET}" + exit 1 + fi fi ######## @@ -203,56 +203,56 @@ fi logger -t ${TAG} -p user.info "7. Installs the configured chmpx config files" # Installs the configured chmpx config file in INI format to ${chmpx_conf_file} -if test -f "${SRCDIR}/../chmpx/server.ini"; then - install_chmpx_conf ${SRCDIR}/../chmpx/server.ini ${chmpx_conf_file} - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_chmpx_conf should return zero, not ${RET}" - exit 1 - fi +if test -f "${SRCDIR}/../chmpx/k2hdkc.ini"; then + install_chmpx_conf ${SRCDIR}/../chmpx/k2hdkc.ini ${chmpx_conf_file} + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "install_chmpx_conf should return zero, not ${RET}" + exit 1 + fi fi # Installs the override.conf to ${chmpx_override_conf_file} if test -f "${SRCDIR}/../chmpx/override.conf"; then - install_chmpx_conf ${SRCDIR}/../chmpx/override.conf ${chmpx_override_conf_file} - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_chmpx_conf should return zero, not ${RET}" - exit 1 - fi + install_chmpx_conf ${SRCDIR}/../chmpx/override.conf ${chmpx_override_conf_file} + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "install_chmpx_conf should return zero, not ${RET}" + exit 1 + fi fi logger -t ${TAG} -p user.info "8. Configures the chmpx and's service manager default configuration" if test -n "${service_manager_plugin}"; then - logger -t ${TAG} -p user.info "Invokes setup_service_manager in ${service_manager_plugin}.sh" - if test -f "${SRCDIR}/../service_manager/plugin/${service_manager_plugin}.sh"; then - logger -t ${TAG} -p user.debug "source ${SRCDIR}/../service_manager/plugin/${service_manager_plugin}.sh" - source "${SRCDIR}/../service_manager/plugin/${service_manager_plugin}.sh" - setup_service_manager - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_service_manager should return zero, not ${RET}" - exit 1 - fi - else - logger -t ${TAG} -p user.error "${SRCDIR}/../service_manager/plugin/${service_manager_plugin}.sh should exist, but not found" - exit 1 - fi + logger -t ${TAG} -p user.info "Invokes setup_service_manager in ${service_manager_plugin}.sh" + if test -f "${SRCDIR}/../service_manager/plugin/${service_manager_plugin}.sh"; then + logger -t ${TAG} -p user.debug "source ${SRCDIR}/../service_manager/plugin/${service_manager_plugin}.sh" + source "${SRCDIR}/../service_manager/plugin/${service_manager_plugin}.sh" + setup_service_manager + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_service_manager should return zero, not ${RET}" + exit 1 + fi + else + logger -t ${TAG} -p user.error "${SRCDIR}/../service_manager/plugin/${service_manager_plugin}.sh should exist, but not found" + exit 1 + fi else - logger -t ${TAG} -p user.info "Invokes setup_service_manager in default.sh" - if test -f "${SRCDIR}/../service_manager/plugin/default.sh"; then - logger -t ${TAG} -p user.debug "source ${SRCDIR}/../service_manager/plugin/default.sh" - source "${SRCDIR}/../service_manager/plugin/default.sh" - setup_service_manager - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_service_manager should return zero, not ${RET}" - exit 1 - fi - else - logger -t ${TAG} -p user.error "${SRCDIR}/../service_manager/plugin/default.sh should exist, please install the 1.0.5 or higher version." - exit 1 - fi + logger -t ${TAG} -p user.info "Invokes setup_service_manager in default.sh" + if test -f "${SRCDIR}/../service_manager/plugin/default.sh"; then + logger -t ${TAG} -p user.debug "source ${SRCDIR}/../service_manager/plugin/default.sh" + source "${SRCDIR}/../service_manager/plugin/default.sh" + setup_service_manager + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_service_manager should return zero, not ${RET}" + exit 1 + fi + else + logger -t ${TAG} -p user.error "${SRCDIR}/../service_manager/plugin/default.sh should exist, please install the 1.0.5 or higher version." + exit 1 + fi fi # The final message displays the time elapsed. @@ -262,7 +262,10 @@ logger -t $(basename $0) -s -p user.info "completed in ${ELAPSED} seconds" exit 0 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/dkc/setup_dkc_centos.ini b/devcluster/dkc/setup_dkc_centos.ini index f117f59..ac4d27d 100644 --- a/devcluster/dkc/setup_dkc_centos.ini +++ b/devcluster/dkc/setup_dkc_centos.ini @@ -26,7 +26,10 @@ package_script_base_url=https://packagecloud.io/install/repositories/antpickax/s package_dnf_repo=powertools # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/dkc/setup_dkc_debian.ini b/devcluster/dkc/setup_dkc_debian.ini index 894768b..52ad8d9 100644 --- a/devcluster/dkc/setup_dkc_debian.ini +++ b/devcluster/dkc/setup_dkc_debian.ini @@ -25,7 +25,10 @@ chmpx_server_name=localhost package_script_base_url=https://packagecloud.io/install/repositories/antpickax/stable # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/dkc/setup_dkc_default.ini b/devcluster/dkc/setup_dkc_default.ini index 832fd1a..6f37358 100644 --- a/devcluster/dkc/setup_dkc_default.ini +++ b/devcluster/dkc/setup_dkc_default.ini @@ -21,7 +21,6 @@ chmpx_conf_file=/etc/antpickax/k2hdkc.ini chmpx_msg_max=1024 chmpx_server_name=localhost -chmpx_systemd_unit_file=/etc/systemd/system/chmpx.service chmpx_loglevel=dump chmpx_override_conf_file=/etc/antpickax/override.conf @@ -42,7 +41,10 @@ package_dnf_repo= service_manager_plugin=default # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/dkc/setup_dkc_fedora.ini b/devcluster/dkc/setup_dkc_fedora.ini index 3a98955..e4ff92c 100644 --- a/devcluster/dkc/setup_dkc_fedora.ini +++ b/devcluster/dkc/setup_dkc_fedora.ini @@ -25,7 +25,10 @@ chmpx_server_name=localhost package_script_base_url=https://packagecloud.io/install/repositories/antpickax/current # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/osnl/k2hr3-osnl.conf b/devcluster/osnl/k2hr3-osnl.conf index bf53de2..19e137e 100644 --- a/devcluster/osnl/k2hr3-osnl.conf +++ b/devcluster/osnl/k2hr3-osnl.conf @@ -41,7 +41,10 @@ api_url = https://localhost/v1/role #requeue_on_error = False # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/osnl/setup_osnl.sh b/devcluster/osnl/setup_osnl.sh index ce30ac9..c5d6745 100755 --- a/devcluster/osnl/setup_osnl.sh +++ b/devcluster/osnl/setup_osnl.sh @@ -48,30 +48,30 @@ PYPI_ARCHIVE_FILE= TRANSPORT_URL= if ! test -r "${SRCDIR}/../cluster_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/../cluster_functions should exist" + exit 1 fi . ${SRCDIR}/../cluster_functions # parses cli args while true; do - case "${1-}" in - -d) DEBUG=1;; - -f) shift; PYPI_ARCHIVE_FILE="${1-}";; - -h) usage_osnl;; - -r) DRYRUN=1;; - -t) shift; TRANSPORT_URL="${1-}";; - -v) version;; - *) break;; - esac - shift + case "${1-}" in + -d) DEBUG=1;; + -f) shift; PYPI_ARCHIVE_FILE="${1-}";; + -h) usage_osnl;; + -r) DRYRUN=1;; + -t) shift; TRANSPORT_URL="${1-}";; + -v) version;; + *) break;; + esac + shift done # determines the debug mode if test "${DEBUG}" -eq 1; then - TAG="$(basename $0) -s" + TAG="$(basename $0) -s" else - TAG=$(basename $0) + TAG=$(basename $0) fi # The first message is always visible. @@ -87,21 +87,21 @@ logger -t ${TAG} -p user.info "1. Initializes environments" setup_os_env RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_os_env should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_os_env should return zero, not ${RET}" + exit 1 fi # Loads default settings setup_ini_env RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_ini_env should return zero, not ${RET}" + exit 1 fi # TRANSPORT_URL passed as an argument will override k2hr3_osnl_transport_url defined in the ini file. if test -n "${TRANSPORT_URL}"; then - k2hr3_osnl_transport_url=${TRANSPORT_URL} + k2hr3_osnl_transport_url=${TRANSPORT_URL} fi ######## @@ -115,8 +115,8 @@ logger -t ${TAG} -p user.info "2. Adds a new package repository" setup_package_repository ${corp_url-} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_package_repository should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_package_repository should return zero, not ${RET}" + exit 1 fi ######## @@ -130,8 +130,8 @@ logger -t ${TAG} -p user.info "3. Installs system packages" setup_install_os_packages "${package_install_pkgs-}" RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_install_os_packages should return zero, not ${RET}" + exit 1 fi ######## @@ -143,8 +143,8 @@ logger -t ${TAG} -p user.info "4. Installs the k2hr3-osnl pypi package" # Install pypi packages # if ! test -r "${SRCDIR}/setup_${COMPONENT}_functions"; then - logger -t ${TAG} -p user.err "${SRCDIR}/setup_${COMPONENT}_functions should exist" - exit 1 + logger -t ${TAG} -p user.err "${SRCDIR}/setup_${COMPONENT}_functions should exist" + exit 1 fi . ${SRCDIR}/setup_${COMPONENT}_functions @@ -154,8 +154,8 @@ setup_osnl_pypi_module ${PYPI_ARCHIVE_FILE} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_osnl_pypi_module should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "setup_osnl_pypi_module should return zero, not ${RET}" + exit 1 fi ######## @@ -167,13 +167,13 @@ logger -t ${TAG} -p user.info "5. Configures the k2hr3-onsl.conf and Installs it # Configures k2hr3-onsl.conf # for varname in api_url transport_url debug_level; do - logger -t ${TAG} -p user.debug "configure_conf_file ${varname}" - configure_conf_file ${SRCDIR}/k2hr3-osnl.conf ${varname} k2hr3_osnl_ - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "setup_osnl_conf ${varname} should return zero, not ${RET}" - exit 1 - fi + logger -t ${TAG} -p user.debug "configure_conf_file ${varname}" + configure_conf_file ${SRCDIR}/k2hr3-osnl.conf ${varname} k2hr3_osnl_ + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "setup_osnl_conf ${varname} should return zero, not ${RET}" + exit 1 + fi done # @@ -182,8 +182,8 @@ done install_conf ${SRCDIR}/k2hr3-osnl.conf ${k2hr3_osnl_conf_file} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_conf k2hr3_osnl.conf ${k2hr3_osnl_conf_file} should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "install_conf k2hr3_osnl.conf ${k2hr3_osnl_conf_file} should return zero, not ${RET}" + exit 1 fi ######## @@ -194,22 +194,22 @@ logger -t ${TAG} -p user.info "6. Installs a systemd configuration for k2hr3_osn enable_scl_python_path RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_scl_python_path should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "enable_scl_python_path should return zero, not ${RET}" + exit 1 fi logger -t ${TAG} -p user.debug "which k2hr3-osnl" k2hr3_osnl_file=$(which k2hr3-osnl 2>/dev/null) if test "${k2hr3_osnl_file}" = ""; then - logger -t ${TAG} -p user.warn "k2hr3-osnl should found, use /usr/local/bin/k2hr3-osnl instead" - k2hr3_osnl_file="/usr/local/bin/k2hr3-osnl" + logger -t ${TAG} -p user.warn "k2hr3-osnl should found, use /usr/local/bin/k2hr3-osnl instead" + k2hr3_osnl_file="/usr/local/bin/k2hr3-osnl" fi configure_osnl_service_manager_conf ${SERVICE_MANAGER} k2hr3-osnl ${k2hr3_osnl_runuser-} ${k2hr3_osnl_conf_file-} ${k2hr3_osnl_file-} RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "configure_osnl_service_manager_conf should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "configure_osnl_service_manager_conf should return zero, not ${RET}" + exit 1 fi ######## @@ -220,8 +220,8 @@ logger -t ${TAG} -p user.info "7. Registers and enables k2hr3_osnl to systemd" install_service_manager_conf ${SERVICE_MANAGER} k2hr3-osnl RET=$? if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_service_manager_conf should return zero, not ${RET}" - exit 1 + logger -t ${TAG} -p user.err "install_service_manager_conf should return zero, not ${RET}" + exit 1 fi ######## @@ -229,12 +229,12 @@ fi # logger -t ${TAG} -p user.debug "sudo systemctl restart k2hr3-${COMPONENT}.service" if test -z "${DRYRUN-}"; then - sudo systemctl restart k2hr3-${COMPONENT}.service - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "'sudo systemctl restart k2hr3-${COMPONENT}.service' should return zero, not ${RESULT}" - exit 1 - fi + sudo systemctl restart k2hr3-${COMPONENT}.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "'sudo systemctl restart k2hr3-${COMPONENT}.service' should return zero, not ${RESULT}" + exit 1 + fi fi # The final message displays the time elapsed. @@ -244,7 +244,10 @@ logger -t $(basename $0) -s -p user.info "completed in ${ELAPSED} seconds" exit 0 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/osnl/setup_osnl_centos6.ini b/devcluster/osnl/setup_osnl_centos6.ini index 888ed2b..a79d2fd 100644 --- a/devcluster/osnl/setup_osnl_centos6.ini +++ b/devcluster/osnl/setup_osnl_centos6.ini @@ -28,7 +28,10 @@ k2hr3_osnl_api_url=http://localhost/v1/role package_install_pkgs="rh-python35" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/osnl/setup_osnl_centos7.ini b/devcluster/osnl/setup_osnl_centos7.ini index c2a9ee5..9afd1f5 100644 --- a/devcluster/osnl/setup_osnl_centos7.ini +++ b/devcluster/osnl/setup_osnl_centos7.ini @@ -28,7 +28,10 @@ k2hr3_osnl_api_url=http://localhost/v1/role package_install_pkgs="rh-python36" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/osnl/setup_osnl_debian.ini b/devcluster/osnl/setup_osnl_debian.ini index 5f1e36e..58b2b29 100644 --- a/devcluster/osnl/setup_osnl_debian.ini +++ b/devcluster/osnl/setup_osnl_debian.ini @@ -28,7 +28,10 @@ k2hr3_osnl_api_url=http://localhost/v1/role package_install_pkgs="python3-pip python3-oslo.messaging python3-oslo.config" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/osnl/setup_osnl_default.ini b/devcluster/osnl/setup_osnl_default.ini index 495ad82..b7905ef 100644 --- a/devcluster/osnl/setup_osnl_default.ini +++ b/devcluster/osnl/setup_osnl_default.ini @@ -31,7 +31,10 @@ k2hr3_osnl_debug_level=debug package_install_pkgs="" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/osnl/setup_osnl_fedora.ini b/devcluster/osnl/setup_osnl_fedora.ini index 9fee502..109b649 100644 --- a/devcluster/osnl/setup_osnl_fedora.ini +++ b/devcluster/osnl/setup_osnl_fedora.ini @@ -28,7 +28,10 @@ k2hr3_osnl_api_url=http://localhost/v1/role package_install_pkgs="python3 python3-oslo-messaging python3-oslo-config" # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/osnl/setup_osnl_functions b/devcluster/osnl/setup_osnl_functions index 05996d5..9485d2d 100644 --- a/devcluster/osnl/setup_osnl_functions +++ b/devcluster/osnl/setup_osnl_functions @@ -28,47 +28,47 @@ # 1 on failure # setup_osnl_pypi_module() { - _alternative_tgz="${1-}" + _alternative_tgz="${1-}" - logger -t ${TAG} -p user.debug "setup_osnl_pypi_module _alternative_tgz=${_alternative_tgz}" - # A dry run returns 0 - if test -n "${DRYRUN-}"; then - return 0 - fi + logger -t ${TAG} -p user.debug "setup_osnl_pypi_module _alternative_tgz=${_alternative_tgz}" + # A dry run returns 0 + if test -n "${DRYRUN-}"; then + return 0 + fi - if test -n "${_alternative_tgz}"; then - if test "${OS_NAME}" != "centos"; then - logger -t ${TAG} -p user.debug "sudo /usr/bin/python3 -m pip install ${_alternative_tgz}" - sudo /usr/bin/python3 -m pip -q install ${_alternative_tgz} - else - if test "${OS_VERSION}" = "7"; then - logger -t ${TAG} -p user.debug "sudo sh -c \"source /opt/rh/rh-python36/enable && python3 -m pip install ${_alternative_tgz}\"" - sudo sh -c "source /opt/rh/rh-python36/enable && python3 -m pip -q install ${_alternative_tgz}" - else - logger -t ${TAG} -p user.err "OS_VERSION should be 7, not ${OS_VERSION}" - return 1 - fi - fi - else - if test "${OS_NAME}" != "centos"; then - logger -t ${TAG} -p user.debug "sudo /usr/bin/python3 -m pip -q install k2hr3-osnl" - sudo /usr/bin/python3 -m pip -q install k2hr3-osnl - else - if test "${OS_VERSION}" = "7"; then - logger -t ${TAG} -p user.debug "sudo sh -c \"source /opt/rh/rh-python36/enable && python3 -m pip install k2hr3_osnl\"" - sudo sh -c "source /opt/rh/rh-python36/enable && python3 -m pip -q install k2hr3_osnl" - else - logger -t ${TAG} -p user.err "OS_VERSION should be 7, not ${OS_VERSION}" - return 1 - fi - fi - fi - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - return 0 + if test -n "${_alternative_tgz}"; then + if test "${OS_NAME}" != "centos"; then + logger -t ${TAG} -p user.debug "sudo /usr/bin/python3 -m pip install ${_alternative_tgz}" + sudo /usr/bin/python3 -m pip -q install ${_alternative_tgz} + else + if test "${OS_VERSION}" = "7"; then + logger -t ${TAG} -p user.debug "sudo sh -c \"source /opt/rh/rh-python36/enable && python3 -m pip install ${_alternative_tgz}\"" + sudo sh -c "source /opt/rh/rh-python36/enable && python3 -m pip -q install ${_alternative_tgz}" + else + logger -t ${TAG} -p user.err "OS_VERSION should be 7, not ${OS_VERSION}" + return 1 + fi + fi + else + if test "${OS_NAME}" != "centos"; then + logger -t ${TAG} -p user.debug "sudo /usr/bin/python3 -m pip -q install k2hr3-osnl" + sudo /usr/bin/python3 -m pip -q install k2hr3-osnl + else + if test "${OS_VERSION}" = "7"; then + logger -t ${TAG} -p user.debug "sudo sh -c \"source /opt/rh/rh-python36/enable && python3 -m pip install k2hr3_osnl\"" + sudo sh -c "source /opt/rh/rh-python36/enable && python3 -m pip -q install k2hr3_osnl" + else + logger -t ${TAG} -p user.err "OS_VERSION should be 7, not ${OS_VERSION}" + return 1 + fi + fi + fi + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + return 0 } # Configures osnl service manager conf @@ -88,36 +88,39 @@ setup_osnl_pypi_module() { # This function is designed for unit tests. # configure_osnl_service_manager_conf() { - _service_manager="${1:?"service_manager should be nonzero"}" - _service_name="${2:?"service_name should be nonzero"}" - _k2hr3_osnl_runuser="${3:?"k2hr3_osnl_runner should be nonzero. Check if it is defined in setup_osnl_*.ini"}" - _k2hr3_osnl_conf_file="${4:?"k2hr3_osnl_conf_file should be nonzero. Check if it is defined in setup_osnl_*.ini"}" - _k2hr3_osnl_file="${5:?"k2hr3_osnl_file should be nonzero. Check if it is defined in setup_osnl_*.ini"}" + _service_manager="${1:?"service_manager should be nonzero"}" + _service_name="${2:?"service_name should be nonzero"}" + _k2hr3_osnl_runuser="${3:?"k2hr3_osnl_runner should be nonzero. Check if it is defined in setup_osnl_*.ini"}" + _k2hr3_osnl_conf_file="${4:?"k2hr3_osnl_conf_file should be nonzero. Check if it is defined in setup_osnl_*.ini"}" + _k2hr3_osnl_file="${5:?"k2hr3_osnl_file should be nonzero. Check if it is defined in setup_osnl_*.ini"}" - logger -t ${TAG} -p user.debug "configure_osnl_service_manager_conf service_manager=${_service_manager} service_name=${_service_name} _k2hr3_osnl_runuser=${_k2hr3_osnl_runuser} k2hr3_osnl_conf_file=${_k2hr3_osnl_conf_file} k2hr3_osnl_file=${_k2hr3_osnl_file}" + logger -t ${TAG} -p user.debug "configure_osnl_service_manager_conf service_manager=${_service_manager} service_name=${_service_name} _k2hr3_osnl_runuser=${_k2hr3_osnl_runuser} k2hr3_osnl_conf_file=${_k2hr3_osnl_conf_file} k2hr3_osnl_file=${_k2hr3_osnl_file}" - if test "${_service_manager}" = "systemd"; then - if test -f "${SERVICE_MANAGER_DIR}/${_service_name}.service"; then - # ExecStart=/usr/bin/k2hr3-osnl -c /etc/k2hr3/k2hr3-osnl.conf - logger -t ${TAG} -p user.debug "perl -pi -e \"s|^ExecStart=.*$|ExecStart=${k2hr3_osnl_file} -c ${k2hr3_osnl_conf_file}|g\" ${SERVICE_MANAGER_DIR}/${_service_name}.service" - perl -pi -e "s|^ExecStart=.*$|ExecStart=${k2hr3_osnl_file} -c ${k2hr3_osnl_conf_file}|g" ${SERVICE_MANAGER_DIR}/${_service_name}.service - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" - return 1 - fi - else - logger -t ${TAG} -p user.err "${SERVICE_MANAGER_DIR}/${_service_name}.service should exist" - return 1 - fi - else - logger -t ${TAG} -p user.err "SERVICE_MANAGER is either systemd, not ${SERVICE_MANAGER}" - fi - return 0 + if test "${_service_manager}" = "systemd"; then + if test -f "${SERVICE_MANAGER_DIR}/${_service_name}.service"; then + # ExecStart=/usr/bin/k2hr3-osnl -c /etc/k2hr3/k2hr3-osnl.conf + logger -t ${TAG} -p user.debug "perl -pi -e \"s|^ExecStart=.*$|ExecStart=${k2hr3_osnl_file} -c ${k2hr3_osnl_conf_file}|g\" ${SERVICE_MANAGER_DIR}/${_service_name}.service" + perl -pi -e "s|^ExecStart=.*$|ExecStart=${k2hr3_osnl_file} -c ${k2hr3_osnl_conf_file}|g" ${SERVICE_MANAGER_DIR}/${_service_name}.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" + return 1 + fi + else + logger -t ${TAG} -p user.err "${SERVICE_MANAGER_DIR}/${_service_name}.service should exist" + return 1 + fi + else + logger -t ${TAG} -p user.err "SERVICE_MANAGER is either systemd, not ${SERVICE_MANAGER}" + fi + return 0 } # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 # diff --git a/devcluster/service_manager/chmpx-slave.service b/devcluster/service_manager/chmpx-slave.service deleted file mode 100644 index 11bdf36..0000000 --- a/devcluster/service_manager/chmpx-slave.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=chmpx-slave -After=network-online.target - -[Service] -Type=simple -User=k2hr3 -PermissionsStartOnly=true -ExecStartPre=/sbin/sysctl fs.mqueue.msg_max=1024 -ExecStart=/usr/bin/chmpx -conf /etc/antpickax/slave.ini -d dump -Restart=always -PIDFile=/var/run/chmpx.pid - -[Install] -WantedBy=multi-user.target diff --git a/devcluster/service_manager/k2hr3-api.service b/devcluster/service_manager/k2hr3-api.service index 84d83bc..7312ede 100644 --- a/devcluster/service_manager/k2hr3-api.service +++ b/devcluster/service_manager/k2hr3-api.service @@ -1,7 +1,26 @@ +# +# K2HR3 K2HR3 Utilities +# +# Copyright 2020 Yahoo! Japan Corporation. +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# +# For the full copyright and license information, please view +# the licenses file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Thu, 14 Nov 2019 +# REVISION: +# + [Unit] Description=k2hr3-api -Requires=chmpx-slave.service -After=chmpx-slave.service +Requires=chmpx.service +After=chmpx.service [Service] Type=simple @@ -16,3 +35,12 @@ PIDFile=/var/run/k2hr3-api.pid [Install] WantedBy=multi-user.target + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/devcluster/service_manager/k2hr3-app.service b/devcluster/service_manager/k2hr3-app.service index 2fa73dd..d1d3316 100644 --- a/devcluster/service_manager/k2hr3-app.service +++ b/devcluster/service_manager/k2hr3-app.service @@ -1,3 +1,22 @@ +# +# K2HR3 K2HR3 Utilities +# +# Copyright 2020 Yahoo! Japan Corporation. +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# +# For the full copyright and license information, please view +# the licenses file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Thu, 14 Nov 2019 +# REVISION: +# + [Unit] Description=k2hr3-app After=network-online.target @@ -15,3 +34,12 @@ PIDFile=/var/run/k2hr3-app.pid [Install] WantedBy=multi-user.target + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/devcluster/service_manager/k2hr3-osnl.service b/devcluster/service_manager/k2hr3-osnl.service index 3e4a983..2293539 100644 --- a/devcluster/service_manager/k2hr3-osnl.service +++ b/devcluster/service_manager/k2hr3-osnl.service @@ -1,3 +1,22 @@ +# +# K2HR3 K2HR3 Utilities +# +# Copyright 2020 Yahoo! Japan Corporation. +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# +# For the full copyright and license information, please view +# the licenses file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Thu, 14 Nov 2019 +# REVISION: +# + [Unit] Description=K2hR3 OpenStack Notification Listener After=network-online.target @@ -12,3 +31,12 @@ PIDFile=/var/run/k2hr3-osnl.pid [Install] WantedBy=multi-user.target + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/devcluster/service_manager/plugin/default.sh b/devcluster/service_manager/plugin/default.sh index 573979e..e8cf910 100644 --- a/devcluster/service_manager/plugin/default.sh +++ b/devcluster/service_manager/plugin/default.sh @@ -41,55 +41,63 @@ umask 022 function setup_service_manager { - logger -t ${TAG} -p user.info "default.sh setup_service_manager" + logger -t ${TAG} -p user.info "default.sh setup_service_manager" - ######## - # 9. Enables the chmpx service manager - # systemd controls chmpx. - # - logger -t ${TAG} -p user.info "9. Enables the chmpx service manager configuration" + ######## + # 9. Enables the chmpx service manager + # systemd controls chmpx. + # + logger -t ${TAG} -p user.info "9. Enables the chmpx service manager configuration" - enable_service_manager ${SERVICE_MANAGER} chmpx - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_service_manager should return zero, not ${RET}" - exit 1 - fi + enable_service_manager ${SERVICE_MANAGER} chmpx + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "enable_service_manager should return zero, not ${RET}" + exit 1 + fi - ######## - # 11. Enables Installs the k2hdkc service manager configuration - # systemd controls k2hdkc - # - logger -t ${TAG} -p user.info "11. Enables the k2hdkc service manager configuration" + ######## + # 11. Enables Installs the k2hdkc service manager configuration + # systemd controls k2hdkc + # + logger -t ${TAG} -p user.info "11. Enables the k2hdkc service manager configuration" - enable_service_manager ${SERVICE_MANAGER} k2hdkc - RET=$? - if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "enable_service_manager should return zero, not ${RET}" - exit 1 - fi + enable_service_manager ${SERVICE_MANAGER} k2hdkc + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "enable_service_manager should return zero, not ${RET}" + exit 1 + fi - ######## - # Start the service! - # - logger -t ${TAG} -p user.debug "sudo systemctl restart chmpx.service" - if test -z "${DRYRUN-}"; then - sudo systemctl restart chmpx.service - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "'sudo systemctl restart chmpx.service' should return zero, not ${RESULT}" - exit 1 - fi + ######## + # Start the service! + # + logger -t ${TAG} -p user.debug "sudo systemctl restart chmpx.service" + if test -z "${DRYRUN-}"; then + sudo systemctl restart chmpx.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "'sudo systemctl restart chmpx.service' should return zero, not ${RESULT}" + exit 1 + fi - logger -t ${TAG} -p user.debug "sudo systemctl restart k2hdkc.service" - sudo systemctl restart k2hdkc.service - RESULT=$? - if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.err "'sudo systemctl restart k2hdkc.service' should return zero, not ${RESULT}" - exit 1 - fi - fi - logger -t ${TAG} -p user.info "default.sh setup_service_manager done" - return 0 + logger -t ${TAG} -p user.debug "sudo systemctl restart k2hdkc.service" + sudo systemctl restart k2hdkc.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.err "'sudo systemctl restart k2hdkc.service' should return zero, not ${RESULT}" + exit 1 + fi + fi + logger -t ${TAG} -p user.info "default.sh setup_service_manager done" + return 0 } +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/devcluster/test/cluster_test.sh b/devcluster/test/cluster_test.sh index f34324a..af2b6cd 100644 --- a/devcluster/test/cluster_test.sh +++ b/devcluster/test/cluster_test.sh @@ -19,13 +19,16 @@ # testEquality() { - assertEquals 1 1 + assertEquals 1 1 } . /usr/share/shunit2/shunit2 # -# VIM modelines -# -# vim:set ts=4 fenc=utf-8: +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 #