-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalleleRegistry_init
executable file
·120 lines (109 loc) · 3.59 KB
/
alleleRegistry_init
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# #########################
# ENVIRONMENT
# #########################
DIR_SCRIPTS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${DIR_SCRIPTS}/conf_runtime.sh
AR_STOPPED_FILE=${DIR_DATA}/alleleRegistry/locks/stopped
# #########################
# MAIN
# #########################
RETVAL=0
start() {
# FILE CHECK, SETUP: Does the "server intentionally stopped" file exist?
if [[ -e $AR_STOPPED_FILE ]]; then
# Need to WAIT (block) until we can get a lock on it. This way we know nothing else is messing with it too.
printf "Will wait for lock on ${AR_STOPPED_FILE} ...\n"
exec 723< $AR_STOPPED_FILE
flock -x 723
haveLock=1
printf "...lock obtained, will continue\n"
else
haveLock=0
fi
echo -n $"Starting Allele Registry:" $'\n'
${DIR_TARGET}/alleleRegistry/alleleRegistry ${DIR_DATA}/conf/alleleRegistry.yaml
RETVAL=$?
# FILE CHECK, CLEANUP: Do we need to remove the lock we obtained?
if [[ $haveLock = 1 ]]; then
flock -u 723
printf "Lock released\n"
fi
# Regardless, remove the "server is intentionally stopped" file
rm -f $AR_STOPPED_FILE
}
start_readonly() {
# FILE CHECK, SETUP: Does the "server intentionally stopped" file exist?
if [[ -e $AR_STOPPED_FILE ]]; then
# Need to WAIT (block) until we can get a lock on it. This way we know nothing else is messing with it too.
printf "Will wait for lock on ${AR_STOPPED_FILE} ...\n"
exec 723< $AR_STOPPED_FILE
flock -x 723
haveLock=1
printf "...lock obtained, will continue\n"
else
haveLock=0
fi
echo -n $"Starting Allele Registry in READ-ONLY mode:" $'\n'
${DIR_TARGET}/alleleRegistry/alleleRegistry ${DIR_DATA}/conf/alleleRegistry.yaml --read_only
RETVAL=$?
# FILE CHECK, CLEANUP: Do we need to remove the lock we obtained?
if [[ $haveLock = 1 ]]; then
flock -u 723
printf "Lock released\n"
fi
# Regardless, remove the "server is intentionally stopped" file
rm -f $AR_STOPPED_FILE
}
stop() {
# FILE CHECK, SETUP: Does the "server intentionally stopped" file already exist?
if [[ -e $AR_STOPPED_FILE ]]; then
# Need to WAIT (block) until we can get a lock on it. This way we know nothing else is messing with it too.
printf "Will wait for lock on ${AR_STOPPED_FILE} ...\n"
exec 723< $AR_STOPPED_FILE
flock -x 723
haveLock=1
printf "...lock obtained, will continue\n"
else
haveLock=0
fi
echo -n $"Shutting down Allele Registry:" $'\n'
kill `ps -e | grep 'alleleRegistry$' | sed 's/^ *//g' | cut -d \ -f 1`
RETVAL=$?
# FILE CHECK, CLEANUP: Do we need to remove the lock we obtained?
if [[ $haveLock = 1 ]]; then
flock -u 723
printf "Lock released\n"
fi
# Regardless, ensure the "server is intentionally stopped" file is present
touch $AR_STOPPED_FILE
}
echo ""
case "$1" in
start)
start
;;
start_readonly)
start_readonly
;;
stop)
stop
;;
restart)
stop
start
;;
restart_readonly)
stop
start_readonly
;;
*)
echo $"Usage: $0 {start|stop|restart|start_readonly|restart_readonly}"
RETVAL=1
esac
if [ $RETVAL = 0 ] ; then
echo "**SUCCESS**"
else
echo "FAILURE: '$0 $1' command failed, check logs ( exit code $RETVAL )"
fi
exit $RETVAL