forked from rslashplace2/rslashplace2.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
daemonise.sh
61 lines (51 loc) · 1.36 KB
/
daemonise.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
#!/bin/bash
# This script will alow rplacetk to always run in the background, and auto load on reboot using a systemD unit (only works on linux)
if [ -z "$1" ]
then
echo -e "\x1b[31mPlease input the path to the rplace server directory as an arguument e.g home/pi/rslashplace2.github.io"
exit 0
fi
node_dir=$(which node)
dotnet_dir=$(which dotnet)
echo -e "
[Unit]
Description=main place websocket server, see http-place for the static http server.
After=network.target
[Service]
Type=simple
StandardInput=tty-force
TTYVHangup=yes
TTYPath=/dev/tty20
TTYReset=yes
WorkingDirectory=$1
ExecStart=
ExecStart=$node_dir server.js
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target
" | sudo tee -a /etc/systemd/system/place.service
sudo systemctl daemon-reload
echo -e "
[Unit]
Description=place-http for the static http server, see place for main websocket server.
After=network.target
[Service]
Type=simple
StandardInput=tty-force
TTYVHangup=yes
TTYPath=/dev/tty21
TTYReset=yes
Environment=DOTNET_CLI_HOME=/temp
WorkingDirectory=$1/PlaceHttpsServer/
ExecStart=
ExecStart=$dotnet_dir run
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target
" | sudo tee -a /etc/systemd/system/http-place.service
sudo systemctl daemon-reload
sudo systemctl enable place.service http-place.service
sudo systemctl start place.service http-place.service
echo "Task completed."