From 52b6a66000274fb6e9b28210dcc221609e79bba8 Mon Sep 17 00:00:00 2001 From: Hirotaka Wakabayashi Date: Tue, 6 Oct 2020 06:31:41 +0900 Subject: [PATCH] Adds features for the new product (#4) * Updates for k2hdkc_dbaas --- devcluster/app/r3clusterini.js | 3 + devcluster/chmpx/server.ini | 2 +- devcluster/cluster_functions | 202 ++++++++++++++++--- devcluster/dkc/setup_dkc.sh | 132 +++++------- devcluster/dkc/setup_dkc_centos.ini | 2 + devcluster/dkc/setup_dkc_default.ini | 6 +- devcluster/service_manager/plugin/default.sh | 157 ++++++++++++++ 7 files changed, 389 insertions(+), 115 deletions(-) create mode 100644 devcluster/service_manager/plugin/default.sh diff --git a/devcluster/app/r3clusterini.js b/devcluster/app/r3clusterini.js index d9ac88b..d70bdca 100644 --- a/devcluster/app/r3clusterini.js +++ b/devcluster/app/r3clusterini.js @@ -75,6 +75,9 @@ class R3clusterIni { if (key.startsWith(component)) { this.keys.push(key); this.vals.push(val); + if (key.localeCompare("k2hr3_app_extrouter_env") == 0) { + this.env = val; + } } } } diff --git a/devcluster/chmpx/server.ini b/devcluster/chmpx/server.ini index 63f70b3..a46916f 100644 --- a/devcluster/chmpx/server.ini +++ b/devcluster/chmpx/server.ini @@ -95,7 +95,7 @@ CTLPORT = 8031 #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/k2hdkc/data/k2hdkc.k2h +K2HFILE = /var/lib/k2hdkc/k2hdkc.k2h K2HFULLMAP = on ### Default(on) K2HINIT = no ### Default(no) K2HMASKBIT = 8 diff --git a/devcluster/cluster_functions b/devcluster/cluster_functions index cab8b79..f3d6a4b 100644 --- a/devcluster/cluster_functions +++ b/devcluster/cluster_functions @@ -116,7 +116,7 @@ setup_os_env() { logger -t ${TAG} -p user.notice "ubuntu configurations are currently equal to debian one" OS_NAME=debian elif test "${OS_NAME}" = "centos"; then - if test "${OS_VERSION}" != "7"; then + if test "${OS_VERSION}" != "7" -a "${OS_VERSION}" != "8"; then logger -t ${TAG} -p user.err "centos7 only currently supported, not ${OS_NAME} ${OS_VERSION}" return 1 fi @@ -162,7 +162,7 @@ setup_ini_env() { logger -t ${TAG} -p user.warn "No ${SRCDIR}/setup_${COMPONENT}_debian.ini Installation continues with setup_default.ini" fi elif test "${OS_NAME}" = "centos"; then - if test "${OS_VERSION}" = "7"; then + if test "${OS_VERSION}" = "7" -o "${OS_VERSION}" = "8"; then if test -f "${SRCDIR}/setup_${COMPONENT}_centos7.ini"; then logger -t ${TAG} -p user.debug "loading ${SRCDIR}/setup_${COMPONENT}_centos7.ini" . ${SRCDIR}/setup_${COMPONENT}_centos7.ini @@ -222,14 +222,14 @@ setup_package_repository() { fi if test "${OS_NAME}" = "centos"; then - logger -t ${TAG} -p user.debug "sudo yum install -y centos-releae-scl" - sudo yum install -q -y centos-release-scl + logger -t ${TAG} -p user.debug "sudo dnf install -y centos-releae-scl" + sudo dnf install -q -y centos-release-scl RESULT=$? if test "${RESULT}" -ne 0; then logger -t ${TAG} -p user.warn "No centos-releae-scl package, ${RESULT}" if test -n "${_copr_url}"; then - sudo yum-config-manager -q --add-repo="${_copr_url}" - sudo yum install -q -y centos-release-scl + sudo dnf-config-manager -q --add-repo="${_copr_url}" + sudo dnf install -q -y centos-release-scl RESULT=$? if test "${RESULT}" -ne 0; then logger -t ${TAG} -p user.err "No centos-releae-scl package, ${RESULT}" @@ -266,8 +266,8 @@ setup_install_os_packages() { if test -n "${_package_install_pkgs}"; then if test "${OS_NAME}" = "centos" -o "${OS_NAME}" = "fedora" ; then - logger -t ${TAG} -p user.debug "sudo yum install -y perl ${_package_install_pkgs}" - sudo yum install -q -y ${_package_install_pkgs} + logger -t ${TAG} -p user.debug "sudo dnf install -y perl ${_package_install_pkgs}" + sudo dnf install -q -y ${_package_install_pkgs} RESULT=$? if test "${RESULT}" -ne 0; then logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" @@ -447,6 +447,7 @@ enable_scl_python_path() { # Params:: # $1 service management file path # $2 service name +# $3 timer or not. 1 if timer. 0 otherwise. # # Returns:: # 0 on success @@ -455,17 +456,23 @@ enable_scl_python_path() { install_service_manager_conf() { _service_manager="${1:?"service_manager should be nonzero"}" _service_name="${2:?"service_name should be nonzero"}" + _is_timer=${3:-} - logger -t ${TAG} -p user.debug "install_service_manager_conf _service_manager=${_service_manager} _service_name=${_service_name}" + logger -t ${TAG} -p user.debug "install_service_manager_conf _service_manager=${_service_manager} _service_name=${_service_name} _is_timer=${_is_timer}" # A dry run returns 0 if test -n "${DRYRUN-}"; then return 0 fi + file_ext="service" + if test "${_is_timer}" = "1"; then + file_ext="timer" + fi + if test "${_service_manager}" = "systemd"; then - if test -f "${SERVICE_MANAGER_DIR}/${_service_name}.service"; then - logger -t ${TAG} -p user.debug "sudo install -C -m 0644 -o root -v ${_service_manager} /etc/systemd/system/${_service_name}.service" - sudo install -C -m 0644 -o root -v ${SERVICE_MANAGER_DIR}/${_service_name}.service /etc/systemd/system/${_service_name}.service + if test -f "${SERVICE_MANAGER_DIR}/${_service_name}.${file_ext}"; then + logger -t ${TAG} -p user.debug "sudo install -C -m 0644 -o root -v ${_service_manager} /lib/systemd/system/${_service_name}.${file_ext}" + sudo install -C -m 0644 -o root -v ${SERVICE_MANAGER_DIR}/${_service_name}.${file_ext} /lib/systemd/system/${_service_name}.${file_ext} RESULT=$? if test "${RESULT}" -ne 0; then logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" @@ -478,21 +485,49 @@ install_service_manager_conf() { logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" return 1 fi - logger -t ${TAG} -p user.debug "sudo systemctl is-active ${_service_name}.service" - sudo systemctl is-active ${_service_name}.service + else + logger -t ${TAG} -p user.err "${SERVICE_MANAGER_DIR}/${_service_name}.${file_ext} should exist" + return 1 + fi + else + logger -t ${TAG} -p user.err "SERVICE_MANAGER is systemd, not ${SERVICE_MANAGER}" + return 1 + fi + return 0 +} + +# Enables a service manager conf +# +# Params:: +# $1 service management file path +# $2 service name +# +# Returns:: +# 0 on success +# 1 on failure +# +enable_service_manager() { + _service_manager="${1:?"service_manager should be nonzero"}" + _service_name="${2:?"service_name should be nonzero"}" + + logger -t ${TAG} -p user.debug "enable_service_manager _service_manager=${_service_manager} _service_name=${_service_name}" + # A dry run returns 0 + if test -n "${DRYRUN-}"; then + return 0 + fi + + if test "${_service_manager}" = "systemd"; then + logger -t ${TAG} -p user.debug "sudo systemctl is-active ${_service_name}.service" + sudo systemctl is-active ${_service_name}.service + RESULT=$? + if test "${RESULT}" -ne 0; then + logger -t ${TAG} -p user.debug "sudo systemctl enable ${_service_name}.service" + sudo systemctl enable ${_service_name}.service RESULT=$? if test "${RESULT}" -ne 0; then - logger -t ${TAG} -p user.debug "sudo systemctl enable ${_service_name}.service" - sudo systemctl enable ${_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 + 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 systemd, not ${SERVICE_MANAGER}" @@ -525,9 +560,9 @@ enable_packagecloud_io_repository() { if test -n "${_package_script_base_url}"; then if test "${OS_NAME}" = "fedora" -o "${OS_NAME}" = "centos"; then package_script_url=${_package_script_base_url}/script.rpm.sh - sudo yum install -q -y curl + sudo dnf install -q -y curl RESULT=$? - logger -t ${TAG} -p user.debug "sudo yum install -y curl, RESULT=${RESULT}" + logger -t ${TAG} -p user.debug "sudo dnf install -y curl, RESULT=${RESULT}" if test "${RESULT}" -ne 0; then logger -t ${TAG} -p user.err "RESULT should be zero, not ${RESULT}" return 1 @@ -607,6 +642,44 @@ enable_nodesource_repository() { return 0 } +# Enables PowerTools repository +# +# Params:: +# $1 the nodesource package url +# +# Returns:: +# 0 on success +# 1 on failure +# +# Uses globals:: +# OS_NAME +# +enable_dnf_repository() { + _reponame=${1-} + + logger -t ${TAG} -p user.debug "enable_dnf_repository _reponame=${_reponame}" + # A dry run returns 0 + if test -n "${DRYRUN-}"; then + return 0 + fi + + if test -n "${_reponame}"; then + if test "${OS_NAME}" = "centos" -a "${OS_VERSION}" = "8"; then + logger -t ${TAG} -p user.debug "sudo dnf config-manager --set-enabled ${_reponame}" + sudo dnf config-manager --set-enabled ${_reponame} + 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.info "No need to enable repos" + return 0 + fi + fi + return 0 +} + # Installs k2hr3 node module local.json # # Params:: @@ -1056,6 +1129,83 @@ npm_init() { return 0 } + +make_k2hdkc() { + + _os_name=${1:?"os_name should be nonzero"} + + if test "${_os_name}" = "debian" -o "${_os_name}" = "ubuntu"; then + _configure_opt="--with-gnutls" + sudo apt-get update -y + sudo apt-get install -y git curl autoconf autotools-dev gcc g++ make gdb libtool pkg-config libyaml-dev libgnutls28-dev + elif test "${_os_name}" = "fedora"; then + _configure_opt="--with-nss" + sudo dnf update -y + sudo dnf install -y git curl autoconf automake gcc gcc-c++ gdb make libtool pkgconfig libyaml-devel nss-devel + elif test "${_os_name}" = "centos" -o "${_os_name}" = "rhel"; then + _configure_opt="--with-nss" + sudo dnf update -y + sudo dnf install -y git curl autoconf automake gcc gcc-c++ gdb make libtool pkgconfig libyaml-devel nss-devel + else + logger -t ${TAG} -p user.error "OS should be debian, ubuntu, fedora, centos or rhel" + return 1 + fi + + logger -t ${TAG} -p user.debug "git clone https://github.com/yahoojapan/k2hdkc" + git clone https://github.com/yahoojapan/k2hdkc + cd k2hdkc + + logger -t ${TAG} -p user.debug "git clone https://github.com/yahoojapan/fullock" + git clone https://github.com/yahoojapan/fullock + logger -t ${TAG} -p user.debug "git clone https://github.com/yahoojapan/k2hash" + git clone https://github.com/yahoojapan/k2hash + logger -t ${TAG} -p user.debug "git clone https://github.com/yahoojapan/chmpx" + git clone https://github.com/yahoojapan/chmpx + + if ! test -d "fullock"; then + echo "no fullock" + return 1 + fi + cd fullock + ./autogen.sh + ./configure --prefix=/usr + make + sudo make install + + if ! test -d "../k2hash"; then + echo "no k2hash" + return 1 + fi + cd ../k2hash + ./autogen.sh + ./configure --prefix=/usr ${_configure_opt} + make + sudo make install + + if ! test -d "../chmpx"; then + echo "no chmpx" + return 1 + fi + cd ../chmpx + ./autogen.sh + ./configure --prefix=/usr ${_configure_opt} + make + sudo make install + + cd .. + ./autogen.sh + ./configure --prefix=/usr ${_configure_opt} + make + sudo make install + + which k2hdkc + if test "${?}" != "0"; then + logger -t ${TAG} -p user.error "no k2hdkc installed" + return 1 + fi + return 0 +} + # # VIM modelines # diff --git a/devcluster/dkc/setup_dkc.sh b/devcluster/dkc/setup_dkc.sh index 5b4e0ee..41bd5e7 100644 --- a/devcluster/dkc/setup_dkc.sh +++ b/devcluster/dkc/setup_dkc.sh @@ -97,7 +97,7 @@ fi ######## # 2. Ensures that the k2hdkc data directory exists -# k2hr3_dkc saves the data to the data directory(for instance /var/k2hdkc/data). +# k2hr3_dkc saves the data to the data directory(for instance /var/lib/k2hdkc/data). # logger -t ${TAG} -p user.info "2. Ensures that the k2hdkc data directory exists" @@ -106,7 +106,7 @@ if ! test -r "${SRCDIR}/../chmpx/setup_chmpx_functions"; then logger -t ${TAG} -p user.err "${SRCDIR}/../chmpx/setup_chmpx_functions should exist" exit 1 fi -. ./chmpx/setup_chmpx_functions +. ${SRCDIR}/../chmpx/setup_chmpx_functions # Makes the k2hrkc data directory runuser_varname=k2hr3_${COMPONENT}_runuser @@ -147,6 +147,14 @@ if test "${RET}" -ne 0; then 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 +fi + ######## # 5. Installs OS dependent packages # k2hr3_dkc needs the k2htpdtor, libfullock, k2hash, chmpx and k2hdkc. @@ -162,6 +170,14 @@ if test -n "${k2hdkc_pkgs-}"; 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 fi ######## @@ -192,93 +208,35 @@ if test "${RET}" -ne 0; then exit 1 fi -######## -# 8. Configures the chmpx's service manager default configuration -# We recommend chmpx process works as a service by systemd. -# -logger -t ${TAG} -p user.info "8. Configures the chmpx'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.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_dkc_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 service manager configuration and enables it -# systemd controls chmpx. -# -logger -t ${TAG} -p user.info "9. Installs the chmpx service manager configuration and enables it" - -install_service_manager_conf ${SERVICE_MANAGER} chmpx -RET=$? -if test "${RET}" -ne 0; then - logger -t ${TAG} -p user.err "install_service_manager_conf should return zero, not ${RET}" - exit 1 -fi - -######## -# 10. Configures the k2hdkc's service manager default configuration -# We recommend k2hdkc processes work as a service by systemd. -# -logger -t ${TAG} -p user.info "10. Configures the k2hdkc'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/k2hdkc.service -else - logger -t ${TAG} -p user.err "SERVICE_MANAGER must be either systemd, not ${SERVICE_MANAGER}" - exit 1 -fi -# Configures the k2hdkc's service manager default configuration -is_k2hdkc=1 -configure_chmpx_service_manager_file ${SERVICE_MANAGER} ${service_manager_file} ${k2hr3_dkc_runuser} ${chmpx_conf_file} ${chmpx_msg_max} ${is_k2hdkc} ${k2hdkc_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 - -######## -# 11. Installs the k2hdkc service manager configuration and enables it -# systemd controls k2hdkc -# -logger -t ${TAG} -p user.info "11. Installs the k2hdkc service manager configuration and enables it" - -install_service_manager_conf ${SERVICE_MANAGER} k2hdkc -RET=$? -if test "${RET}" -ne 0; then - 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.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}" +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.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}" +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 fi diff --git a/devcluster/dkc/setup_dkc_centos.ini b/devcluster/dkc/setup_dkc_centos.ini index 894768b..46edead 100644 --- a/devcluster/dkc/setup_dkc_centos.ini +++ b/devcluster/dkc/setup_dkc_centos.ini @@ -20,9 +20,11 @@ #[chmpx] chmpx_msg_max=1024 chmpx_server_name=localhost +k2hdkc_pkgs="" #[package] package_script_base_url=https://packagecloud.io/install/repositories/antpickax/stable +package_dnf_repo=PowerTools # # VIM modelines diff --git a/devcluster/dkc/setup_dkc_default.ini b/devcluster/dkc/setup_dkc_default.ini index 920f3d9..320631c 100644 --- a/devcluster/dkc/setup_dkc_default.ini +++ b/devcluster/dkc/setup_dkc_default.ini @@ -25,7 +25,7 @@ chmpx_systemd_unit_file=/etc/systemd/system/chmpx.service chmpx_loglevel=dump #[k2hdkc] -k2hdkc_data_dir="/var/k2hdkc/data" +k2hdkc_data_dir="/var/lib/k2hdkc" k2hdkc_systemd_unit_file=/etc/systemd/system/k2hdkc.service k2hdkc_loglevel=dump @@ -35,6 +35,10 @@ k2hr3_dkc_runuser=k2hr3 #[package] package_script_base_url=https://packagecloud.io/install/repositories/antpickax/stable package_install_pkgs="k2htpdtor libfullock k2hash chmpx k2hdkc" +package_dnf_repo= + +#[other] +service_manager_plugin=default # # VIM modelines diff --git a/devcluster/service_manager/plugin/default.sh b/devcluster/service_manager/plugin/default.sh new file mode 100644 index 0000000..09129a7 --- /dev/null +++ b/devcluster/service_manager/plugin/default.sh @@ -0,0 +1,157 @@ +#!/bin/sh +# +# K2HR3 Utilities +# +# Copyright 2018 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: Mon Jul 9 2018 +# REVISION: +# + +# +# A simple script to create a k2hr3-dkc server on localhost +# + +# Sets the default locale. LC_ALL has precedence over other LC* variables. +unset LANG +unset LANGUAGE +LC_ALL=en_US.utf8 +export LC_ALL + +# Sets PATH. setup_*.sh uses useradd command +PATH=${PATH}:/usr/sbin:/sbin + +# an unset parameter expansion will fail +set -u + +# umask 022 is enough +umask 022 + +# defines environments + + +function setup_service_manager { + logger -t ${TAG} -p user.info "default.sh setup_service_manager" + + ######## + # 8. Configures the chmpx's service manager default configuration + # We recommend chmpx process works as a service by systemd. + # + logger -t ${TAG} -p user.info "8. Configures the chmpx'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.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_dkc_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 service manager configuration and enables it + # systemd controls chmpx. + # + logger -t ${TAG} -p user.info "9. Installs the chmpx service manager configuration and enables it" + + install_service_manager_conf ${SERVICE_MANAGER} chmpx + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "install_service_manager_conf 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 + + ######## + # 10. Configures the k2hdkc's service manager default configuration + # We recommend k2hdkc processes work as a service by systemd. + # + logger -t ${TAG} -p user.info "10. Configures the k2hdkc'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/k2hdkc.service + else + logger -t ${TAG} -p user.err "SERVICE_MANAGER must be either systemd, not ${SERVICE_MANAGER}" + exit 1 + fi + # Configures the k2hdkc's service manager default configuration + is_k2hdkc=1 + configure_chmpx_service_manager_file ${SERVICE_MANAGER} ${service_manager_file} ${k2hr3_dkc_runuser} ${chmpx_conf_file} ${chmpx_msg_max} ${is_k2hdkc} ${k2hdkc_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 + + ######## + # 11. Installs the k2hdkc service manager configuration and enables it + # systemd controls k2hdkc + # + logger -t ${TAG} -p user.info "11. Installs the k2hdkc service manager configuration and enables it" + + install_service_manager_conf ${SERVICE_MANAGER} k2hdkc + RET=$? + if test "${RET}" -ne 0; then + logger -t ${TAG} -p user.err "install_service_manager_conf 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 + + 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 +} + +# +# VIM modelines +# +# vim:set ts=4 fenc=utf-8: +#