forked from Pawdia/sobani-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
66 lines (54 loc) · 1.4 KB
/
deploy.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
#!/bin/bash
# update apt
sudo apt-get update
install_node() {
sudo curl -sL https://deb.nodesource.com/setup_13.x | sudo bash -
sudo apt-get install -y nodejs
}
# install nodejs
NODE=`which node`
NPM=`which npm`
SHOULD_INSTALL_NODE=false
if ! [ -x "${NODE}" ]; then
NODE_VER=`node -v | awk -F'.' '{ print substr($1, 2, length($1) - 1)}'`
if ! [ -x "${NODE_VER}" -le 10 ]; then
SHOULD_INSTALL_NODE=true
fi
if ! [ ! -x "${NPM}" ]; then
SHOULD_INSTALL_NODE=true
fi
else
SHOULD_INSTALL_NODE=true
fi
if [ "${SHOULD_INSTALL_NODE}" ]; then
install_node
fi
# install git
GIT=`which git`
if ! [ -x "${GIT}" ]; then
sudo apt-get install -y git
fi
# clone sobani-tracker
git clone https://github.com/nekomeowww/sobani-tracker ~/sobani-tracker
cd ~/sobani-tracker
# install sobani-tracker dependenceis
npm install --save
# generate systemd service file
cat <<EOF | sudo tee /etc/systemd/system/sobani-tracker.service
[Unit]
Description=Sobani Tracker
After=network-online.target
[Service]
User=${USER}
WorkingDirectory=${HOME}/sobani-tracker
ExecStart=/usr/bin/node ${HOME}/sobani-tracker/app.js
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=5
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# enable and start sobani-tracker
sudo systemctl enable sobani-tracker.service
sudo systemctl start sobani-tracker
sudo systemctl status sobani-tracker