Skip to content

Commit

Permalink
refactor: update functions for services
Browse files Browse the repository at this point in the history
  • Loading branch information
rugbymauri committed Jun 13, 2024
1 parent e77d90d commit 8b68351
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 91 deletions.
29 changes: 29 additions & 0 deletions commands/_internals/services.sh
Original file line number Diff line number Diff line change
@@ -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}
}
15 changes: 6 additions & 9 deletions commands/system/services/available.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
20 changes: 4 additions & 16 deletions commands/system/services/disable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
20 changes: 4 additions & 16 deletions commands/system/services/enable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 3 additions & 4 deletions commands/system/services/enabled.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 3 additions & 14 deletions commands/system/services/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 3 additions & 14 deletions commands/system/services/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
23 changes: 7 additions & 16 deletions commands/system/services/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


}
5 changes: 4 additions & 1 deletion commands/system/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions helper/configure-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions services/samba/README.md
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion services/samba/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b68351

Please sign in to comment.