-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwatchtower.sh
executable file
·40 lines (31 loc) · 1.36 KB
/
watchtower.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
#!/bin/bash
# Get current directory and service name
WORK_DIR=$(dirname "$(readlink -f "${BASH_SOURCE}")") # Note this should remain this, it just directory to save log file from watchtower
SERVICE_NAME="agave-watchtower"
USERNAME=sol
# Create log file and change permissions to everyone readwrite-execute
sudo touch watchtower.log && sudo chmod 666 watchtower.log
# Install log rotate
sudo apt update && sudo apt install -y apache2-utils
# Check if the service is already running
if systemctl is-active --quiet "$SERVICE_NAME"; then
echo "$SERVICE_NAME is already running."
else
# Create the service unit file
SERVICE_UNIT="[Unit]
Description=Agave Watchtower Service
[Service]
ExecStart=/bin/bash -c \"/home/sol/.local/share/solana/install/active_release/bin/agave-watchtower --config /home/sol/.config/solana/cli/config.yml --interval 15 2>&1 | tee >(rotatelogs -t $WORK_DIR/watchtower.log 30M)\"
Restart=always
User=$USERNAME
WorkingDirectory=$WORK_DIR
[Install]
WantedBy=multi-user.target"
# Save the service unit file to the systemd directory
echo -e "$SERVICE_UNIT" | sudo tee "/etc/systemd/system/$SERVICE_NAME.service" > /dev/null
# Reload systemd and start the service
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl start "$SERVICE_NAME"
echo "$SERVICE_NAME service has been set up and started."
fi