forked from cryptosharks131/lndg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystemd.sh
106 lines (94 loc) · 3.2 KB
/
systemd.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
INSTALL_USER=${SUDO_USER:-${USER}}
REFRESH=20
RED='\033[0;31m'
NC='\033[0m'
if [ "$INSTALL_USER" == 'root' ] >/dev/null 2>&1; then
HOME_DIR='/root'
else
HOME_DIR="/home/$INSTALL_USER"
fi
function configure_jobs() {
cat << EOF > $HOME_DIR/lndg/jobs.sh
#!/bin/bash
$HOME_DIR/lndg/.venv/bin/python $HOME_DIR/lndg/jobs.py
EOF
cat << EOF > /etc/systemd/system/jobs-lndg.service
[Unit]
Description=Run Jobs For Lndg
[Service]
User=$INSTALL_USER
Group=$INSTALL_USER
ExecStart=/usr/bin/bash $HOME_DIR/lndg/jobs.sh
StandardError=append:/var/log/lnd_jobs_error.log
EOF
cat << EOF > /etc/systemd/system/jobs-lndg.timer
[Unit]
Description=Run Lndg Jobs Every $REFRESH Seconds
[Timer]
OnBootSec=300
OnUnitActiveSec=$REFRESH
AccuracySec=1
[Install]
WantedBy=timers.target
EOF
}
function configure_rebalancer() {
cat << EOF > $HOME_DIR/lndg/rebalancer.sh
#!/bin/bash
$HOME_DIR/lndg/.venv/bin/python $HOME_DIR/lndg/jobs.py
EOF
cat << EOF > /etc/systemd/system/rebalancer-lndg.service
[Unit]
Description=Run Rebalancer For Lndg
[Service]
User=$INSTALL_USER
Group=$INSTALL_USER
ExecStart=/usr/bin/bash $HOME_DIR/lndg/rebalancer.sh
StandardError=append:/var/log/lnd_rebalancer_error.log
RuntimeMaxSec=3600
EOF
cat << EOF > /etc/systemd/system/rebalancer-lndg.timer
[Unit]
Description=Run Lndg Rebalancer Every $REFRESH Seconds
[Timer]
OnBootSec=315
OnUnitActiveSec=$REFRESH
AccuracySec=1
[Install]
WantedBy=timers.target
EOF
}
function enable_services() {
systemctl daemon-reload
sleep 3
systemctl start jobs-lndg.timer
systemctl enable jobs-lndg.timer >/dev/null 2>&1
systemctl start rebalancer-lndg.timer
systemctl enable rebalancer-lndg.timer >/dev/null 2>&1
}
function report_information() {
echo -e ""
echo -e "================================================================================================================================"
echo -e "Backend services and rebalancer setup for LNDg via systemd using user account $INSTALL_USER and a refresh interval of $REFRESH seconds."
echo -e ""
echo -e "Jobs Timer Status: ${RED}sudo systemctl status jobs-lndg.timer${NC}"
echo -e "Rebalancer Timer Status: ${RED}sudo systemctl status rebalancer-lndg.timer${NC}"
echo -e ""
echo -e "Last Jobs Status: ${RED}sudo systemctl status jobs-lndg.service${NC}"
echo -e "Last Rebalancer Status: ${RED}sudo systemctl status rebalancer-lndg.service${NC}"
echo -e ""
echo -e "To disable your backend services, use the following commands."
echo -e "Disable Jobs Timer: ${RED}sudo systemctl disable jobs-lndg.timer${NC}"
echo -e "Disable Rebalancer Timer: ${RED}sudo systemctl disable rebalancer-lndg.timer${NC}"
echo -e "Stop Jobs Timer: ${RED}sudo systemctl stop jobs-lndg.timer${NC}"
echo -e "Stop Rebalancer Timer: ${RED}sudo systemctl stop rebalancer-lndg.timer${NC}"
echo -e ""
echo -e "To re-enable these services, simply replace the disable/stop commands with enable/start."
echo -e "================================================================================================================================"
}
##### Main #####
echo -e "Setting up, this may take a few minutes..."
configure_jobs
configure_rebalancer
enable_services
report_information