fix: various issues in scripts
This commit is contained in:
parent
56ede19cae
commit
ecca216c0b
9 changed files with 29 additions and 10 deletions
|
@ -7,7 +7,7 @@
|
|||
"commit": "git-cz",
|
||||
"act:test-install": "act --container-architecture linux/amd64 -j test-install",
|
||||
"act:docker": "act --container-architecture linux/amd64 --secret-file github.secrets -j build-images",
|
||||
"start:dev": "./scripts/start-dev.sh",
|
||||
"start:dev": "sudo ./scripts/start-dev.sh",
|
||||
"start:rc": "docker-compose -f docker-compose.rc.yml --env-file .env up --build",
|
||||
"start:prod": "docker-compose --env-file .env up --build",
|
||||
"start:pg": "docker run --name test-db -p 5433:5432 -d --rm -e POSTGRES_PASSWORD=postgres postgres",
|
||||
|
|
|
@ -69,7 +69,7 @@ class EventDispatcher {
|
|||
return;
|
||||
}
|
||||
|
||||
this.clearEvent(this.lock.id);
|
||||
this.clearEvent(this.lock, status);
|
||||
this.lock = null;
|
||||
}
|
||||
|
||||
|
@ -165,10 +165,16 @@ class EventDispatcher {
|
|||
* Clear event from queue
|
||||
* @param id - Event id
|
||||
*/
|
||||
private clearEvent(id: string) {
|
||||
this.queue = this.queue.filter((e) => e.id !== id);
|
||||
if (fs.existsSync(`/app/logs/${id}.log`)) {
|
||||
fs.unlinkSync(`/app/logs/${id}.log`);
|
||||
private clearEvent(event: SystemEvent, status: EventStatusTypes = 'success') {
|
||||
this.queue = this.queue.filter((e) => e.id !== event.id);
|
||||
if (fs.existsSync(`/app/logs/${event.id}.log`)) {
|
||||
const log = fs.readFileSync(`/app/logs/${event.id}.log`, 'utf8');
|
||||
if (log && status === 'error') {
|
||||
logger.error(`EventDispatcher: ${event.type} ${event.id} failed with error: ${log}`);
|
||||
} else if (log) {
|
||||
logger.info(`EventDispatcher: ${event.type} ${event.id} finished with message: ${log}`);
|
||||
}
|
||||
fs.unlinkSync(`/app/logs/${event.id}.log`);
|
||||
}
|
||||
fs.writeFileSync(WATCH_FILE, '');
|
||||
}
|
||||
|
|
|
@ -154,10 +154,11 @@ describe('EventDispatcher - getEventStatus', () => {
|
|||
|
||||
describe('EventDispatcher - clearEvent', () => {
|
||||
it('Should clear event', async () => {
|
||||
const event = { id: '123', type: EventTypes.APP, args: [], creationDate: new Date() };
|
||||
// @ts-ignore
|
||||
eventDispatcher.queue = [{ id: '123', type: EventTypes.APP, args: [], creationDate: new Date() }];
|
||||
eventDispatcher.queue = [event];
|
||||
// @ts-ignore
|
||||
eventDispatcher.clearEvent('123');
|
||||
eventDispatcher.clearEvent(event);
|
||||
|
||||
// @ts-ignore
|
||||
const queue = eventDispatcher.queue;
|
||||
|
|
|
@ -46,6 +46,7 @@ if [[ "$command" = "update" ]]; then
|
|||
repo="$2"
|
||||
repo_hash=$(get_hash "${repo}")
|
||||
repo_dir="${ROOT_FOLDER}/repos/${repo_hash}"
|
||||
git config --global --add safe.directory "${repo_dir}"
|
||||
if [ ! -d "${repo_dir}" ]; then
|
||||
write_log "Repo does not exist"
|
||||
exit 1
|
||||
|
@ -55,6 +56,7 @@ if [[ "$command" = "update" ]]; then
|
|||
cd "${repo_dir}" || exit
|
||||
|
||||
if ! git pull origin master; then
|
||||
cd "${ROOT_FOLDER}" || exit
|
||||
write_log "Failed to update repo"
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
@ -5,5 +5,7 @@ ROOT_FOLDER="${PWD}"
|
|||
|
||||
kill_watcher
|
||||
"${ROOT_FOLDER}/scripts/watcher.sh" &
|
||||
chmod -R a+rwx "${ROOT_FOLDER}/state/events"
|
||||
chmod -R a+rwx "${ROOT_FOLDER}/state/system-info.json"
|
||||
|
||||
docker compose -f docker-compose.dev.yml --env-file "${ROOT_FOLDER}/.env.dev" up --build
|
||||
|
|
|
@ -201,6 +201,9 @@ mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
|
|||
# Run system-info.sh
|
||||
echo "Running system-info.sh..."
|
||||
bash "${ROOT_FOLDER}/scripts/system-info.sh"
|
||||
echo "Fixing permissions for events file"
|
||||
chmod -R a+rwx "${ROOT_FOLDER}/state/events"
|
||||
chmod -R a+rwx "${ROOT_FOLDER}/state/system-info.json"
|
||||
|
||||
## Don't run if config-only
|
||||
if [[ ! $ci == "true" ]]; then
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e # Exit immediately if a command exits with a non-zero status.
|
||||
|
||||
ROOT_FOLDER="${PWD}"
|
||||
STATE_FOLDER="${ROOT_FOLDER}/state"
|
||||
|
||||
# if not on linux exit
|
||||
if [[ "$(uname)" != "Linux" ]]; then
|
||||
echo '{"cpu": { "load": 0 },"memory": { "available": 0, "total": 0, "used": 0 },"disk": { "available": 0, "total": 0, "used": 0 }}' >"${STATE_FOLDER}/system-info.json"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "${BASH_SOURCE%/*}/common.sh"
|
||||
|
||||
ensure_pwd
|
||||
|
||||
ROOT_FOLDER="${PWD}"
|
||||
|
||||
if [ -z ${1+x} ]; then
|
||||
command=""
|
||||
else
|
||||
|
@ -23,6 +24,7 @@ fi
|
|||
# Update Tipi
|
||||
if [[ "$command" = "update" ]]; then
|
||||
scripts/stop.sh
|
||||
git config --global --add safe.directory "${ROOT_FOLDER}"
|
||||
git pull origin master
|
||||
scripts/start.sh
|
||||
exit
|
||||
|
|
|
@ -97,7 +97,6 @@ function select_command() {
|
|||
return 0
|
||||
}
|
||||
|
||||
check_running
|
||||
write_log "Listening for events in ${WATCH_FILE}..."
|
||||
clean_events
|
||||
# Listen in for changes in the WATCH_FILE
|
||||
|
|
Loading…
Add table
Reference in a new issue