diff --git a/ansible/setup.yml b/ansible/setup.yml index 601ef825..c3cb07ab 100644 --- a/ansible/setup.yml +++ b/ansible/setup.yml @@ -7,10 +7,5 @@ - import_tasks: ./tasks/common/zsh.yml - import_tasks: ./tasks/common/docker.yml - import_tasks: ./tasks/network/avahi.yml - # - import_tasks: tasks/zsh.yml - # - import_tasks: tasks/nginx.yml - # - import_tasks: tasks/pi-hole.yml - # - import_tasks: tasks/pi-vpn.yml - # - import_tasks: tasks/nextcloud.yml # - name: Reboot machine # reboot: diff --git a/ansible/stop.yml b/ansible/stop.yml new file mode 100644 index 00000000..0227d34e --- /dev/null +++ b/ansible/stop.yml @@ -0,0 +1,6 @@ +--- +- hosts: tipi + become: yes + + tasks: + - import_tasks: ./tasks/common/teardown.yml diff --git a/ansible/tasks/common/teardown.yml b/ansible/tasks/common/teardown.yml new file mode 100644 index 00000000..e374dc43 --- /dev/null +++ b/ansible/tasks/common/teardown.yml @@ -0,0 +1,9 @@ +- name: Check if app is already running + become_user: "{{ username }}" + shell: pm2 list + register: pm2_result + +- name: Stop app + become_user: "{{ username }}" + shell: pm2 stop "system-api" + when: pm2_result.stdout.find("system-api") != -1 diff --git a/scripts/stop.sh b/scripts/stop.sh index 785e36bb..e7f9a375 100755 --- a/scripts/stop.sh +++ b/scripts/stop.sh @@ -21,6 +21,8 @@ STATE_FOLDER="${ROOT_FOLDER}/state" cd "$ROOT_FOLDER" +ansible-playbook ansible/stop.yml -i ansible/hosts + export DOCKER_CLIENT_TIMEOUT=240 export COMPOSE_HTTP_TIMEOUT=240 diff --git a/system-api/src/modules/apps/apps.controller.ts b/system-api/src/modules/apps/apps.controller.ts index ca612bde..115f36fd 100644 --- a/system-api/src/modules/apps/apps.controller.ts +++ b/system-api/src/modules/apps/apps.controller.ts @@ -1,6 +1,4 @@ import { Request, Response } from 'express'; -import process from 'child_process'; -import config from '../../config'; import { AppConfig } from '../../config/types'; import { createFolder, fileExists, readJsonFile, writeFile, copyFile, runScript, deleteFolder } from '../fs/fs.helpers'; @@ -153,7 +151,11 @@ const installedApps = (req: Request, res: Response) => { const apps = readJsonFile('/state/apps.json'); const appNames = apps.installed.split(' '); - res.status(200).json(appNames); + if (appNames.length === 0) { + res.status(204).json([]); + } else { + res.status(200).json(appNames); + } } catch (e) { res.status(500).end(e); }