-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_energy_agent.sh
54 lines (36 loc) · 1.73 KB
/
prepare_energy_agent.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Update and upgrade the system
sudo apt-get update -y
sudo apt-get upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
# Add current user to the Docker group
sudo usermod -aG docker "${USER}"
# Use newgrp docker to run the subsequent commands in a new shell with the updated group
newgrp docker << EOF
# Create a directory for the docker-compose file
mkdir -p ~/energy-agent
cd ~/energy-agent || exit
# Download the docker-compose file from GitHub
# Replace the URL with the actual URL of your docker-compose file
wget https://github.com/rddl-network/EnergyAgent/raw/main/docker-compose.yaml
# Start the Docker Compose
docker compose up -d
# Cleanup
rm ../get-docker.sh
echo "Docker and Docker Compose setup complete. The services are now running."
EOF
echo "Establishing cron jobs for automated ugprades and reconnectivity."
# Install cronjob to look for updates in randomly once between 0-25 min randomly selected
CRONJOB_UPGRADE="*/30 * * * * cd ~/energy-agent && sleep \$(shuf -i 0-1500 -n 1) && docker system prune -f --all && docker compose up -d"
(crontab -l 2>/dev/null; echo "$CRONJOB_UPGRADE") | crontab -
wget https://github.com/rddl-network/EnergyAgent/raw/main/internet_check_restart.sh
sudo mv internet_check_restart.sh /usr/local/bin/
sudo chmod +x /usr/local/bin/internet_check_restart.sh
CRONJOB_RECONNECT="*/15 * * * * /usr/bin/systemd-cat -t internet-check /usr/bin/sudo /usr/local/bin/internet_check_restart.sh"
(crontab -l 2>/dev/null; echo "$CRONJOB_RECONNECT") | crontab -
sudo journalctl --vacuum-size=300M
sudo journalctl --rotate
sudo /bin/bash -c "echo 'RuntimeMaxUse=300M' >> /etc/systemd/journald.conf"
sudo systemctl restart systemd-journald.service