forked from marcomicera/followifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.sh
executable file
·92 lines (83 loc) · 2.51 KB
/
server.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
#!/bin/bash
# 'core' and 'frontend' module starting script.
# This shows the accepted flags.
_help_message() {
echo "Usage: $(basename "$0") [options]" >&2
echo
echo " -h, --help Shows this help message"
echo " --compile Compiles the core server before launching"
echo
exit 1
}
# Creates a screen daemon if it does not exist already and does not attach to it.
_screen_daemon_no_reattach() {
if screen -ls | awk '{print $1}' | grep -q "followifier-$1$"; then
echo "The $1 module is already running."
else
echo "Launching the $1 module..."
screen -dmS followifier-$1 bash -c "$2; exec bash"
echo "...$1 launched as a screen daemon."
fi
}
# Allowing inbound and outbound TCP connections on the specified port
_allow_tcp_port() {
PORT=$(python3 -c "import json; print(json.load(open('core/server/config.json'))['port'])")
echo Asking password to allow TCP inbound and outbound connections on port "$PORT" on this machine...
sudo iptables -A INPUT -p tcp --dport "$PORT" -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport "$PORT" -m conntrack --ctstate ESTABLISHED -j ACCEPT
}
# Starts the NTP server
_launch_ntp_server() {
/etc/init.d/ntp start
}
# Starts the local database
_start_db() {
sudo service mongod start
}
# Launches the UI
_launch_ui() {
_screen_daemon_no_reattach "reader" "cd frontend/reader && npm install && node index.js"
_screen_daemon_no_reattach "gui" "cd frontend/paper && npm install && npm start"
}
# Launches the core server without compiling first
_launch_core() {
_allow_tcp_port
_launch_ntp_server
_start_db
cd core/server && ./core
}
# Compiles and launches the core server
_compile_and_launch_core() {
_start_db
cd core/server && ./start.sh
}
# If there are no command line arguments
if [ $# -eq 0 ]; then
# Start UI & server without compiling the latter
_launch_ui
_launch_core
# If there is at least a command line argument
else
# For every flag
for i in "$@"
do
case $i in
# Help section
--help|-h)
_help_message
shift
;;
# Compile section
--compile)
_launch_ui
_compile_and_launch_core
shift
;;
# Anything else will just display the help message
*)
_help_message
shift
;;
esac
done
fi