From df4e812dc7f73eb37a86ea5525b3f15f53346b79 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sun, 8 Oct 2023 10:43:38 -0600 Subject: add service files --- appspec.yml | 2 ++ autoaid.service | 12 ++++++++++++ scripts/install_dependencies.sh | 9 +++++++-- scripts/start_application.sh | 3 +++ scripts/stop_application.sh | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 autoaid.service create mode 100644 scripts/start_application.sh create mode 100644 scripts/stop_application.sh diff --git a/appspec.yml b/appspec.yml index c8dbced..8db5566 100644 --- a/appspec.yml +++ b/appspec.yml @@ -3,6 +3,8 @@ os: linux files: - source: / destination: /home/ec2-user/dep-dir + - source: /autoaid.service + destination: /etc/systemd/system/ hooks: AfterInstall: - location: scripts/install_dependencies.sh diff --git a/autoaid.service b/autoaid.service new file mode 100644 index 0000000..0783144 --- /dev/null +++ b/autoaid.service @@ -0,0 +1,12 @@ +[Unit] +Description=AutoAid Python App +After=network.target + +[Service] +User=ec2-user +WorkingDirectory=/home/ec2-user/dep-dir +ExecStart=/usr/bin/python3 /home/ec2-user/dep-dir/app.py +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index ea78008..cfc98a5 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -4,5 +4,10 @@ then curl -sSL https://install.python-poetry.org | python3 - fi export PATH="/root/.local/bin:$PATH" -cd /home/ec2-user/dep-dir -/root/.local/bin/poetry install +cd /home/ec2-user +sudo chown -R ec2-user:ec2-user /home/ec2-user/deps-dir +cd /home/ec2-user/deps-dir +sudo -u ec2-user bash -c 'cd /home/ec2-user/deps-dir && /home/ec2-user/.local/bin/poetry install' + +systemctl daemon-reload + diff --git a/scripts/start_application.sh b/scripts/start_application.sh new file mode 100644 index 0000000..48c4274 --- /dev/null +++ b/scripts/start_application.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +sudo systemd start autoaid \ No newline at end of file diff --git a/scripts/stop_application.sh b/scripts/stop_application.sh new file mode 100644 index 0000000..d385487 --- /dev/null +++ b/scripts/stop_application.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sudo systemctl stop autoaid \ No newline at end of file -- cgit v1.2.3