-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_lib.sh
More file actions
52 lines (45 loc) · 1.32 KB
/
script_lib.sh
File metadata and controls
52 lines (45 loc) · 1.32 KB
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
#!/bin/bash
# -----------------------------------------------------------------------------
# Variables...
# -----------------------------------------------------------------------------
DATE=$(date "+%Y-%m-%d %H:%M:%S")
PROMP="[$DATE] - $PROCESS_NAME -"
RUBY_PROCESS_NAME="ruby"
#
# -----------------------------------------------------------------------------
# Functions...
# -----------------------------------------------------------------------------
function stopProcess {
NAME=$1
if [ -n "$(ps -ef | grep $NAME | grep -v grep | awk '{print $2}')" ]
then
ps -ef | grep $NAME | grep -v grep | awk '{print $2}' | xargs kill -9
if [ ${?} = 0 ]
then
showMessage "$NAME processes shutdown..."
else
showMessage "Problem shutting down $NAME processes..."
fi
else
showMessage "$NAME processes was not running..."
fi
}
function showProcess {
showMessage "Show runing process..."
showMessage "PID's: $(ps -fea | grep $1 | awk '{print $2}' | sed ':a;N;$!ba;s/\n/, /g')."
}
function stopRubyProcess {
stopProcess $RUBY_PROCESS_NAME
}
function showRubyProcess {
showProcess $RUBY_PROCESS_NAME
}
function showMessage {
echo "$PROMP $1"
}
function runRubyProcess {
PROCESS_NAME=$1
showMessage "Start \"$PROCESS_NAME\"..."
rm -f $PROCESS_NAME.log
ruby $PROCESS_NAME.rb > $PROCESS_NAME.log &
}