diff --git a/appspec.yml b/appspec.yml index bc0edf4..0b5554e 100644 --- a/appspec.yml +++ b/appspec.yml @@ -5,8 +5,14 @@ files: destination: /home/ubuntu/song-recognition hooks: BeforeInstall: - - location: scripts/BeforeInstall.sh - AfterInstall: - - location: scripts/AfterInstall.sh - - location: scripts/ApplicationStart.sh + - location: scripts/before_install.sh + runas: ubuntu + AfterInstall: + - location: scripts/after_install.sh + runas: ubuntu + ApplicationStart: + - location: scripts/start_server.sh + runas: ubuntu + ApplicationStop: + - location: scripts/stop_server.sh runas: ubuntu diff --git a/scripts/ApplicationStart.sh b/scripts/ApplicationStart.sh deleted file mode 100644 index 6584c4b..0000000 --- a/scripts/ApplicationStart.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -start_backend() { - cd /home/ubuntu/song-recognition - touch back.txt - go build -tags netgo -ldflags '-s -w' -o app - nohup ./app > backend.log 2>&1 & -} - -start_client() { - cd /home/ubuntu/song-recognition/client - touch client.txt - - export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - - nvm install 16 - nvm use 16 - npm install - npm run build - nohup serve -s build > client.log 2>&1 & -} - -start_backend && start_client diff --git a/scripts/AfterInstall.sh b/scripts/after_install.sh similarity index 100% rename from scripts/AfterInstall.sh rename to scripts/after_install.sh diff --git a/scripts/BeforeInstall.sh b/scripts/before_install.sh similarity index 100% rename from scripts/BeforeInstall.sh rename to scripts/before_install.sh diff --git a/scripts/start_server.sh b/scripts/start_server.sh new file mode 100644 index 0000000..fef510a --- /dev/null +++ b/scripts/start_server.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +start_server() { + cd /home/ubuntu/song-recognition + go build -tags netgo -ldflags '-s -w' -o app + nohup ./app > backend.log 2>&1 & +} + +start_client() { + cd /home/ubuntu/song-recognition/client + npm install + npm run build + nohup serve -s build > client.log 2>&1 & +} + +start_server diff --git a/scripts/stop_server.sh b/scripts/stop_server.sh new file mode 100644 index 0000000..8054b30 --- /dev/null +++ b/scripts/stop_server.sh @@ -0,0 +1 @@ +sudo kill -9 $(sudo lsof -t -i:5000)