From 8b68351eb23e24ea1d57e8039152047f049caed5 Mon Sep 17 00:00:00 2001 From: Maurizio Monticelli Date: Thu, 13 Jun 2024 11:18:06 +0200 Subject: [PATCH] refactor: update functions for services --- commands/_internals/services.sh | 29 +++++++++++++++++++++++++++ commands/system/services/available.sh | 15 ++++++-------- commands/system/services/disable.sh | 20 ++++-------------- commands/system/services/enable.sh | 20 ++++-------------- commands/system/services/enabled.sh | 7 +++---- commands/system/services/start.sh | 17 +++------------- commands/system/services/stop.sh | 17 +++------------- commands/system/services/update.sh | 23 +++++++-------------- commands/system/up.sh | 5 ++++- helper/configure-image.sh | 2 ++ services/samba/README.md | 11 ++++++++++ services/samba/docker-compose.yml | 2 +- 12 files changed, 77 insertions(+), 91 deletions(-) create mode 100755 commands/_internals/services.sh create mode 100644 services/samba/README.md diff --git a/commands/_internals/services.sh b/commands/_internals/services.sh new file mode 100755 index 0000000..007d886 --- /dev/null +++ b/commands/_internals/services.sh @@ -0,0 +1,29 @@ +_getServices() { + + local -n return_array=$1 + + for f in services/*; do + if [ -d "$f" ]; then + # Will not run if no directories are available + if [ -f "${f}/docker-compose.yml" ]; then + return_array+=("${f#services/}") + fi + fi + done +} + + +_serviceExists() { + local exists=0 + + _getServices allServices + + if [[ ${allServices[@]} =~ $1 ]] + then + exists=0 + else + exists=1 + fi + + return ${exists} +} diff --git a/commands/system/services/available.sh b/commands/system/services/available.sh index 62b1e60..b58a269 100755 --- a/commands/system/services/available.sh +++ b/commands/system/services/available.sh @@ -6,14 +6,11 @@ function system:services:available() { cd ${ROOT_DIR} _logGreen "Available System services:" - cd services - for f in *; do - if [ -d "$f" ]; then - # Will not run if no directories are available - if [ -f "${f}/docker-compose.yml" ]; then - echo "$f" - fi - fi -done + declare -a allServices + + _getServices allServices + for service in "${allServices[@]}"; do + echo "$service" + done } diff --git a/commands/system/services/disable.sh b/commands/system/services/disable.sh index 438742f..3e8fb1e 100755 --- a/commands/system/services/disable.sh +++ b/commands/system/services/disable.sh @@ -6,26 +6,14 @@ function system:services:disable() { cd ${ROOT_DIR} - if [ -d "services/${1}" ]; then + if _serviceExists ${1}; then _logGreen "System service: ${1} found" else - _logRed "System service: :${1}: not found" + _logRed "System service: ${1} not found" return fi _logYellow "Disable System services: ${1}" - cd services - - for f in *; do - if [ -d "$f" ]; then - # Will not run if no directories are available - if [ -f "${f}/docker-compose.yml" ]; then - if [ "$f" == "${1}" ]; then - rm -f conf.d/${f} - cd ${f} - ${DOCKER_COMPOSE} stop - fi - fi - fi -done + rm -f services/conf.d/${1} + ${DOCKER_COMPOSE} -f services/${1}/docker-compose.yml stop } diff --git a/commands/system/services/enable.sh b/commands/system/services/enable.sh index c8865d9..f0ea691 100755 --- a/commands/system/services/enable.sh +++ b/commands/system/services/enable.sh @@ -6,26 +6,14 @@ function system:services:enable() { cd ${ROOT_DIR} - if [ -d "services/${1}" ]; then + if _serviceExists ${1}; then _logGreen "System service: ${1} found" else - _logRed "System service: :${1}: not found" + _logRed "System service: ${1} not found" return fi - _logYellow "Enable System services: ${1}" - cd services - for f in *; do - if [ -d "$f" ]; then - # Will not run if no directories are available - if [ -f "${f}/docker-compose.yml" ]; then - if [ "$f" == "${1}" ]; then - touch conf.d/${f} - cd ${f} - ${DOCKER_COMPOSE} up -d - fi - fi - fi -done + touch services/conf.d/${1} + ${DOCKER_COMPOSE} -f services/${1}/docker-compose.yml up -d } diff --git a/commands/system/services/enabled.sh b/commands/system/services/enabled.sh index 72303d4..87167a0 100755 --- a/commands/system/services/enabled.sh +++ b/commands/system/services/enabled.sh @@ -5,10 +5,9 @@ function system:services:enabled() { cd ${ROOT_DIR} - _logGreen "Enabled System services: ${1}" - cd services/conf.d + _logGreen "Enabled System services:" - for f in *; do - echo "${f}" + for enabledSerice in services/conf.d/*; do + echo "${enabledSerice#services/conf.d/}" done } diff --git a/commands/system/services/start.sh b/commands/system/services/start.sh index 7dc4571..65bc940 100755 --- a/commands/system/services/start.sh +++ b/commands/system/services/start.sh @@ -6,25 +6,14 @@ function system:services:enable() { cd ${ROOT_DIR} - if [ -d "services/${1}" ]; then + if _serviceExists ${1}; then _logGreen "System service: ${1} found" else - _logRed "System service: :${1}: not found" + _logRed "System service: ${1} not found" return fi _logYellow "Enable System services: ${1}" - cd services - for f in *; do - if [ -d "$f" ]; then - # Will not run if no directories are available - if [ -f "${f}/docker-compose.yml" ]; then - if [ "$f" == "${1}" ]; then - cd ${f} - ${DOCKER_COMPOSE} up -d - fi - fi - fi -done + ${DOCKER_COMPOSE} -f services/${1}/docker-compose.yml up -d } diff --git a/commands/system/services/stop.sh b/commands/system/services/stop.sh index 84bc77b..4c9038d 100755 --- a/commands/system/services/stop.sh +++ b/commands/system/services/stop.sh @@ -6,25 +6,14 @@ function system:services:stop() { cd ${ROOT_DIR} - if [ -d "services/${1}" ]; then + if _serviceExists ${1}; then _logGreen "System service: ${1} found" else - _logRed "System service: :${1}: not found" + _logRed "System service: ${1} not found" return fi _logYellow "Enable System services: ${1}" - cd services - for f in *; do - if [ -d "$f" ]; then - # Will not run if no directories are available - if [ -f "${f}/docker-compose.yml" ]; then - if [ "$f" == "${1}" ]; then - cd ${f} - ${DOCKER_COMPOSE} stop - fi - fi - fi -done + ${DOCKER_COMPOSE} -f services/${1}/docker-compose.yml stop } diff --git a/commands/system/services/update.sh b/commands/system/services/update.sh index 4f47bd3..a6e129d 100755 --- a/commands/system/services/update.sh +++ b/commands/system/services/update.sh @@ -6,27 +6,18 @@ function system:services:update() { cd ${ROOT_DIR} - if [ -d "services/${1}" ]; then + if _serviceExists ${1}; then _logGreen "System service: ${1} found" else - _logRed "System service: :${1}: not found" + _logRed "System service: ${1} not found" return fi _logYellow "Enable System services: ${1}" - cd services - for f in *; do - if [ -d "$f" ]; then - # Will not run if no directories are available - if [ -f "${f}/docker-compose.yml" ]; then - if [ "$f" == "${1}" ]; then - cd ${f} - ${DOCKER_COMPOSE} stop - ${DOCKER_COMPOSE} pull - ${DOCKER_COMPOSE} up -d - fi - fi - fi -done + ${DOCKER_COMPOSE} -f services/${1}/docker-compose.yml stop + ${DOCKER_COMPOSE} -f services/${1}/docker-compose.yml pull + ${DOCKER_COMPOSE} -f services/${1}/docker-compose.yml up -d + + } diff --git a/commands/system/up.sh b/commands/system/up.sh index 40ff19a..df905f9 100755 --- a/commands/system/up.sh +++ b/commands/system/up.sh @@ -37,8 +37,11 @@ function system:up() { cd services/conf.d + _logGreen "Test" + + for f in *; do - if [ -f ${ROOT_DIR}/services/${f}/docker-compose.yml ]; then + if [ -f "${ROOT_DIR}/services/${f}/docker-compose.yml" ]; then _logGreen "Starting service ${f}" cd ${ROOT_DIR}/services/${f} ${DOCKER_COMPOSE} up -d || true diff --git a/helper/configure-image.sh b/helper/configure-image.sh index 18377f5..279f30d 100755 --- a/helper/configure-image.sh +++ b/helper/configure-image.sh @@ -82,7 +82,9 @@ fi if [ -d /var/lib/nginx/tmp ]; then chown -R dde:dde /var/lib/nginx/tmp fi +ls -la /var/www if [ -d /var/www ]; then + echo 'chown -R dde:dde /var/www' chown -R dde:dde /var/www fi diff --git a/services/samba/README.md b/services/samba/README.md new file mode 100644 index 0000000..75ea558 --- /dev/null +++ b/services/samba/README.md @@ -0,0 +1,11 @@ +## DDE Samba Service + +### Installation + +``` + +> dde system:service:enable samba + +``` + +copy [config.yml](sample-data%2Fconfig.yml) to `dde/data/samba/data` diff --git a/services/samba/docker-compose.yml b/services/samba/docker-compose.yml index d7fd644..1339c7b 100644 --- a/services/samba/docker-compose.yml +++ b/services/samba/docker-compose.yml @@ -16,7 +16,7 @@ services: - ./../../data/samba/share:/samba environment: - "TZ=Europe/Paris" - - "SAMBA_LOG_LEVEL=0" + - "SAMBA_LOG_LEVEL=3" restart: always hostname: samba domainname: test