-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user-data script for installing service on a cloud provider VM
The script will: 1. Install necessary dependencies 2. Create the DB file 3. Run the migrations 4. Initialize the DB with the seed data 5. Move the systemd unit file to the correct location 6. Enable the systemd service The script will NOT: - Create the `.env` file - Start the server (the systemd service will start the server on reboot tho)
- Loading branch information
1 parent
456d28c
commit b7b594e
Showing
3 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[Unit] | ||
Description=Nutrition Tracker server | ||
ConditionFileNotEmpty=/root/nutriton-tracker/.env | ||
ConditionPathExists=/root/nutriton-tracker/sqlite/nutrition-tracker.db | ||
After=multi-user.target | ||
Wants=multi-user.target | ||
StartLimitIntervalSec=600 | ||
StartLimitBurst=5 | ||
|
||
[Service] | ||
Type=simple | ||
ExecStartPre=/bin/bash -c 'echo "$(date +"%%F-%%T") starting" >> /var/log/nutrition-tracker-starts.log' | ||
ExecStart=/bin/bash -c '/root/nutriton-tracker/out/nutrition-tracker /root/nutriton-tracker/.env 2>&1 | tee /var/log/nutrition-tracker.log && exit ${PIPESTATUS[0]}' | ||
ExecStartPost=/bin/bash -c 'echo "$(date +"%%F-%%T") started" >> /var/log/nutrition-tracker-starts.log' | ||
Restart=on-failure | ||
TimeoutSec=30 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
# logging | ||
exec >> /var/log/user-data.log | ||
exec 2>&1 | ||
|
||
set -ex -o pipefail | ||
|
||
export HOME=/root | ||
|
||
install_go() { | ||
curl -LO https://go.dev/dl/go1.23.1.linux-amd64.tar.gz | ||
rm -rf /usr/local/go | ||
tar -C /usr/local -xzf go1.23.1.linux-amd64.tar.gz | ||
echo "export PATH=$PATH:/usr/local/go/bin:/root/go/bin" >> /etc/profile | ||
echo "export GOPATH=/root/go" >> /etc/profile | ||
source /etc/profile | ||
go version | ||
} | ||
|
||
main() { | ||
apt-get update | ||
|
||
if ! which make || ! which gcc; then | ||
apt-get install -y build-essential | ||
which make | ||
which gcc | ||
fi | ||
|
||
if ! which go; then | ||
install_go | ||
fi | ||
|
||
if ! which sqlite3; then | ||
apt-get install -y sqlite3 | ||
which sqlite3 | ||
fi | ||
|
||
if [[ ! -d ~/nutrition-tracker ]]; then | ||
cd ~ | ||
git clone https://github.com/szabolcs-horvath/nutrition-tracker.git | ||
cd nutrition-tracker | ||
make install | ||
else | ||
echo "Nutrition Tracker already installed." | ||
fi | ||
} | ||
|
||
main "$@" |