-
Notifications
You must be signed in to change notification settings - Fork 2
/
killapp
executable file
·59 lines (52 loc) · 1.57 KB
/
killapp
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
#!/bin/bash
DO_RESTART=false;
while getopts ":r" opt; do
case ${opt} in
r ) DO_RESTART=true;
;;
\? ) echo "Usage: killapp [-r]"
;;
esac
done
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# check $ALLOWED_USERS
ALLOWED_USERS=`node utilities/getConfig.js allowedUsersCommaSeparated`
if [ -z "${ALLOWED_USERS}" ]
then
printf "${YELLOW}No 'allowedUsersCommaSeparated' value set in config/default.json.\nValue must be set to proceed\n\nExample:\n${GREEN}allowedUsersCommaSeparated='root,someotheruser'\n\n${NC}" && exit 1
fi
IFS=', ' read -r -a array <<< "$ALLOWED_USERS"
USER=`whoami`
ALLOWED="false"
for i in "${array[@]}"
do
if [ "$i" == "$USER" ]
then
ALLOWED="true"
fi
done
# stop script if user not permitted to restart
if [ "$ALLOWED" == "false" ]
then
printf "${RED}User ${YELLOW}$USER${RED} not allowed to start/restart app; try sudo?${NC}\n"
printf "${YELLOW}Allowed users listed in config/default.json, but actual permissions are \nset elsewhered according to your setup.${NC}\n" && exit 1
fi
procline=`ps ax | grep node | grep -i MyGuide`
proc=`ps ax | grep node | grep -i MyGuide | { read a _; echo "$a"; }`
kill $proc
reset
echo $procline
printf "${YELLOW}killing $proc ...${NC}\n"
printf "${GREEN}done${NC}\n"
if [ $DO_RESTART = true ]; then
# printf "${YELLOW}\nRUNNING PREFLIGHT CHECK...${NC}\n";
# npm run check
printf "${YELLOW}\nRESTARTING SERVER...${NC}\n";
npm run server > /dev/null 2>&1 &
else
printf "restart server with: ${CYAN}./killapp${NC}\n\n"
fi