This repository has been archived by the owner on Mar 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch-server
executable file
·69 lines (57 loc) · 1.7 KB
/
launch-server
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
#!/bin/bash
#
# launch-server -- Launch server as daemon.
#
set -e
server_dir=$(pwd)/$(dirname "$0")
server_main="${server_dir}/src/server.js"
server_log="${server_dir}/server.log"
server_conf="/etc/advse/server.conf"
function is_windows {
case $(uname -s) in
CYGWIN*|MINGW*) return 0 ;;
*) return 1 ;;
esac
}
function is_root {
[[ $EUID -eq 0 ]] && return 0
return 1
}
if is_windows; then
server_dir=$(cygpath -w "${server_dir}")
server_main=$(cygpath -w "${server_main}")
server_log=$(cygpath -w "${server_log}")
fi
function die {
echo "*** Fatal error: $@" >&2
exit 1
}
function setup_env {
if [[ -f "${server_conf}" ]]; then
while read LINE; do
# Print line unless it is blank or starts with #
local string=$(echo "${LINE}" | sed 's/^[[:space:]]*//')
if [[ ${#string} -gt 0 ]] && [[ ! "${string}" =~ \#.* ]]; then
echo "${string}" >&2
export "${string}"
fi
done <"${server_conf}"
fi
}
function start_daemon {
[[ -x $(which setsid) ]] || die "setsid command required"
echo "*** Starting server daemon" >&2
# Set umask to 0 and cd to /.
umask 0
cd /
# Run server detatched from shell, appending its output to $server_log.
setsid "$(which node)" "${server_main}" </dev/null 2>&1 >>"${server_log}" &
# Echo the PID on stdout so user/script can send signals to the server.
echo $!
}
# Don't run server if not root user, unless running on Windows.
is_windows || is_root || die "Server should be run as root"
# Make sure Node.js is installed.
[[ -x $(which node) ]] || die "Node.js (node) is not in PATH"
setup_env
start_daemon