Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

set -e # Stop the script if any command fails

# Every 4 minutes, keep alive sudo (in background)
sudo -v
( while true; do sleep 240; sudo -n -v; done ) &
SUDO_KEEP_ALIVE_PID=$!

# Go to the home directory
cd ~

# Clone and install DISCOS master for SRT
if [ ! -d master-srt ]; then
discos-get master -s SRT
source ~/.bashrc
cd master-srt/SystemMake/
make all install
fi

# Go back to home
cd ~

# Download Redis only if the archive doesn't already exist
if [ ! -f redis-7.0.15.tar.gz ]; then
wget https://download.redis.io/releases/redis-7.0.15.tar.gz
fi

# Extract and build Redis
tar xzf redis-7.0.15.tar.gz
cd redis-7.0.15/
make clean
make BUILD_WITH_LTO=no
sudo make install

# Create the redis system user if it doesn't exist
if ! id "redis" &>/dev/null; then
sudo adduser --system --no-create-home redis
else
echo "User 'redis' already exists, skipping creation."
fi

# Configure redis
cd ~/suricate
sudo cp templates/redis.conf /etc/redis.conf

# Create the systemd service file for Redis
cd ~/suricate
sudo cp startup/redis.service /etc/systemd/system/redis.service

# Reload systemd and enable Redis
sudo systemctl daemon-reload
sudo systemctl enable redis.service
sudo service redis start

# Install and configure Suricate
cd ~/suricate
pip install -r requirements.txt
pip install -r testing_requirements.txt
pip install .
suricate-config -t srt

cd ~/suricate/suricate
source .flaskenv
if [ ! -d migrations ]; then
flask db init
fi

# Reload systemd and enable Suricate
cd ~/suricate
sudo cp scripts/start_suricate.sh /usr/local/bin/start_suricate.sh
sudo cp scripts/stop_suricate.sh /usr/local/bin/stop_suricate.sh
sudo cp startup/suricate.service /etc/systemd/system/suricate.service
sudo systemctl daemon-reload
sudo systemctl enable suricate.service

# Install DISCOS simulators
cd ~
git clone https://github.com/discos/simulators.git
cd simulators
pip install .

# Optional: start the RQ worker manually (commented)
# rqworker -P suricate/ discos-api

# Start discos simulators
# discos-simulators start

# Start discos
# discosup

kill $SUDO_KEEP_ALIVE_PID
sudo reboot
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ setuptools
redis==6.1.0
tzlocal==4.3.1
pytz==2020.4
apscheduler==3.2.0
apscheduler==3.11.0
MarkupSafe==3.0.2
Jinja2==3.1.6
itsdangerous==2.2.0
Expand Down
10 changes: 10 additions & 0 deletions scripts/start_suricate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

export HOME=/discos-sw/discos/
export PATH="/alma/ACS-2021DEC/pyenv/shims:/alma/ACS-2021DEC/pyenv/bin:$PATH"
export PYENV_ROOT="/alma/ACS-2021DEC/pyenv"
export LD_LIBRARY_PATH="/usr/local/lib:/usr/local/lib64:/usr/lib64"
/usr/local/bin/redis-cli CONFIG SET stop-writes-on-bgsave-error no
source /discos-sw/discos/.bashrc

exec /alma/ACS-2021DEC/pyenv/shims/suricate-server start
10 changes: 10 additions & 0 deletions scripts/stop_suricate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

export HOME=/discos-sw/discos/
export PATH="/alma/ACS-2021DEC/pyenv/shims:/alma/ACS-2021DEC/pyenv/bin:$PATH"
export PYENV_ROOT="/alma/ACS-2021DEC/pyenv"
export LD_LIBRARY_PATH="/usr/local/lib:/usr/local/lib64:/usr/lib64"
/usr/local/bin/redis-cli CONFIG SET stop-writes-on-bgsave-error no
source /discos-sw/discos/.bashrc

exec /alma/ACS-2021DEC/pyenv/shims/suricate-server stop
14 changes: 14 additions & 0 deletions startup/redis.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Redis In-Memory Data Store
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
User=redis
Group=redis

[Install]
WantedBy=multi-user.target
9 changes: 7 additions & 2 deletions startup/suricate.service
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[Unit]
Description=DISCOS monitoring program
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/bin/bash -c 'source ~/.bashrc && suricate-server start'
ExecStop=/bin/bash -c 'source ~/.bashrc && suricate-server stop'
ExecStart=/usr/local/bin/start_suricate.sh
ExecStop=/usr/local/bin/start_suricate.sh
User=discos
PIDFile=/var/run/suricate-server

[Install]
WantedBy=multi-user.target
Loading