-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-server.sh
executable file
·58 lines (48 loc) · 1.23 KB
/
web-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
#!/usr/bin/env bash
WEB_SERVER_PID=/tmp/remote_service_web_server.pid
check_before_start(){
if [ -f $WEB_SERVER_PID ]; then
pid_that_running=`cat $WEB_SERVER_PID`
if kill -0 $pid_that_running > /dev/null 2>&1; then
echo "Server already running with pid $pid_that_running"
exit 1
fi
fi
}
check_that_database_created(){
bundle exec ruby ./scripts/CreateDB.rb ./config/settings.yml
}
usage="Usage: need 1 parameter - start/stop"
if [ $# -le 0 ]; then
echo $usage
exit 1
fi
startStop=$1
shift
case $startStop in
(start)
#todo logs to file
check_before_start
check_that_database_created
nohup bundle exec rackup -p 8147 &
pid=$!
echo $pid > ${WEB_SERVER_PID}
;;
(stop)
if [ -f $WEB_SERVER_PID ]; then
pid_to_kill=`cat $WEB_SERVER_PID`
if kill -0 $pid_to_kill > /dev/null 2>&1; then
kill $pid_to_kill > /dev/null 2>&1
echo "Server stoped (pid=$pid_to_kill)"
else
echo "Server cannot stop, becase server (pid=${pid_to_kill}) not running"
fi
else
echo "Server cannot stop, becase pid file ($WEB_SERVER_PID) does not exist"
fi
;;
(*)
echo $usage
exit 1
;;
esac