-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_serverinfo_restapi_remote.sh
127 lines (117 loc) · 4.29 KB
/
install_serverinfo_restapi_remote.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# To be ran as root
# Distro check Helper
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
...
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
...
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
# Disable service first if running
if [ -f "/etc/systemd/system/serverinfo_restapi.service" ]; then
# Stopping potentially running service
echo "Disabling ServerInfo RESTAPI Service"
systemctl stop serverinfo_restapi
systemctl disable serverinfo_restapi
systemctl daemon-reload
rm -rf "/etc/systemd/system/serverinfo_restapi.service"
fi
# Installing NodeJS 11.x and Dependencies
echo "${OS}"" was detected on ""${HOSTNAME}"
if [ ! -f "/usr/bin/node" ]; then
echo "Installing NodeJS and dependencies"
if [ "${OS}" == "Ubuntu" ] ; then
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs
echo "NodeJS Installed"
fi
if [ "${OS}" == "CentOS Linux" ] ; then
# Install from Binaries
# NODEJS_VERSION="v11.11.0"
# NODEJS_DISTRO="linux-x64"
# NODEJS_INSTALLDIR="/usr/local/lib/nodejs"
# if [ ! -d "${NODEJS_INSTALLDIR}" ]; then
# mkdir -p "${NODEJS_INSTALLDIR}"
# fi
# NODEJS_URL="https://nodejs.org/dist/${NODEJS_VERSION}/node-${NODEJS_VERSION}-${NODEJS_DISTRO}.tar.xz"
# wget "${NODEJS_URL}"
# tar -xJvf "node-$NODEJS_VERSION-$NODEJS_DISTRO.tar.xz" -C /usr
# rm -rf "node-$NODEJS_VERSION-$NODEJS_DISTRO.tar.xz"
#
# ln -s "/usr/local/lib/nodejs/node-$NODEJS_VERSION-$NODEJS_DISTRO/bin/node" "/usr/bin/node"
# ln -s "/usr/local/lib/nodejs/node-$NODEJS_VERSION-$NODEJS_DISTRO/bin/npm" "/usr/bin/npm"
# ln -s "usr/local/lib/nodejs/node-$NODEJS_VERSION-$NODEJS_DISTRO/bin/npx" "/usr/bin/npx"
# Straight forward ver but not working in script
yum install gcc-c++ make &> /dev/null
curl --silent --location https://rpm.nodesource.com/setup_11.x | bash -
yum install -y nodejs &> /dev/null
# Install from source
# yum install gcc-c++ make -y
# wget "https://nodejs.org/dist/v11.11.0/node-v11.11.0.tar.gz"
# tar xvf "node-v11.11.0.tar.gz"
# cd "node-v11.11.0"
# ./configure
# make -j $(nproc)
# make install
# cd ..
# rm -rf "node-v11.11.0"
fi
fi
echo "Cloning serverinfo_restapi to /opt/serverinfo_restapi"
if [ -d "/opt/serverinfo_restapi" ]; then
rm -rf "/opt/serverinfo_restapi"
fi
git clone "https://github.com/dosssman/nvidia_gpu_serverstatus_web_nodejs.git" "/opt/serverstatus_nodejs"
mv "/opt/serverstatus_nodejs/serverinfo_restapi" "/opt/."
rm -rf "/opt/serverstatus_nodejs"
# Install server App
echo "Installing NodeJS Module"
npm install --prefix /opt/serverinfo_restapi /opt/serverinfo_restapi &> /dev/null
# Create Service and forward necessary command
if [ -f "/etc/systemd/system/serverinfo_restapi.service" ]; then
rm -rf "/etc/systemd/system/serverinfo_restapi.service"
fi
if [ "${OS}" == "Ubuntu" ] ; then
ln -s "/opt/serverinfo_restapi/serverinfo_restapi_ubuntu.service" "/etc/systemd/system/serverinfo_restapi.service"
fi
if [ "${OS}" == "CentOS Linux" ] ; then
ln -s "/opt/serverinfo_restapi/serverinfo_restapi_centos.service" "/etc/systemd/system/serverinfo_restapi.service"
fi
#Opening necessary port
if [ -f "/usr/bin/firewall-cmd" ]; then
# TODO: Check explicilty if port is open !
echo "Opening port 9701"
firewall-cmd --zone=public --add-port=9701/tcp --permanent &> /dev/null
# firewall-cmd --zone=public --remove-port=10050/tcp
# firewall-cmd --runtime-to-permanent
firewall-cmd --reload &> /dev/null
fi
# Enable and start service
echo "Initializing and starting service"
systemctl daemon-reload
# Fix error too many symlink error somewhen
systemctl enable serverinfo_restapi &> /dev/null
systemctl start serverinfo_restapi