Skip to content

Commit 88e49c5

Browse files
committed
[shell] format & optimized
1 parent bea5fb8 commit 88e49c5

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

start.sh

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
#!/bin/bash
2-
set +m
2+
#set +m
33
cvm_pid=cvm.pid
44
node_pid=node.pid
5-
tracker_pid=tracker_pid
5+
#tracker_pid=tracker_pid
66
remove=1
77
trap 'EXIT' INT
88
function EXIT(){
99
if [ $remove -eq 0 ];then
1010
exit 0
1111
fi
12-
pkill -P `cat cvm.pid`
13-
wait $!
12+
13+
if [ -f ${cvm_pid} ];then
14+
pkill -P `cat ${cvm_pid}`
15+
wait $!
16+
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex virtual machine exited with status $?."
17+
else
18+
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex virtual machine pid file not exist. Try to stop process manually."
19+
fi
1420
#echo "cvm stopped successfully"
15-
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex virtual machine exited with status $?."
21+
#echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex virtual machine exited with status $?."
1622
#wait `cat cvm.pid` 2>/dev/null
1723
#ps aux | grep 'cortex cvm' | grep -v grep | grep -v echo | cut -c 9-15 | xargs kill -9
1824
# pkill -P `cat tracker.pid`
19-
pkill -P `cat node.pid`
20-
wait $!
25+
if [ -f ${node_pid} ];then
26+
pkill -P `cat ${node_pid}`
27+
wait $!
28+
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex full node exited with status $?."
29+
else
30+
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex full node pid file not exist. Try to stop process manually."
31+
fi
2132
#echo "cortex node stopped successfully"
22-
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex full node exited with status $?."
23-
rm -rf cvm.pid node.pid
33+
#echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex full node exited with status $?."
34+
rm -rf ${cvm_pid} ${node_pid}
2435
wait $!
2536
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex workspace cleaned with status $?."
2637
#echo "clean [$cvm_pid, $node_pid]"
2738
# ps aux | grep 'bittorrent-tracker' | grep -v grep | grep -v echo | cut -c 9-15 | xargs kill -9
2839
exit 0
2940
}
3041

31-
if [ -f $cvm_pid ];then
32-
echo "cvm is running with pid [`cat cvm.pid`]. You should stop this process first."
42+
if [ -f ${cvm_pid} ];then
43+
echo "cvm is running with pid [`cat ${cvm_pid}`]. You should stop this process first."
3344
remove=0
3445
exit 0
3546
fi
@@ -40,8 +51,8 @@ fi
4051
# exit 0
4152
#fi
4253

43-
if [ -f $node_pid ];then
44-
echo "cortex node is running with pid [`cat node.pid`]. You should stop this process first."
54+
if [ -f ${node_pid} ];then
55+
echo "cortex node is running with pid [`cat ${node_pid}`]. You should stop this process first."
4556
remove=0
4657
exit 0
4758
fi
@@ -50,12 +61,14 @@ function start_cvm(){
5061
#./cvm.sh | grep -v 'Terminated ' & #>/dev/null 2>&1 &
5162
#echo $$ > cvm.pid
5263
./cvm.sh 2>/dev/null &
53-
echo $! > cvm.pid
64+
echo $! > ${cvm_pid}
65+
chmod 644 "${cvm_pid}"
5466
}
5567

5668
function start_node(){
5769
./node.sh &
58-
echo $! > node.pid
70+
echo $! > ${node_pid}
71+
chmod 644 "${node_pid}"
5972
}
6073

6174
#function start_tracker(){
@@ -71,7 +84,7 @@ start_cvm
7184
start_node
7285
while true; do
7386
server=`ps aux | grep 'cortex cvm' | grep -v grep | grep -v echo`
74-
if [ ! "$server" ]; then
87+
if [ ! "${server}" ]; then
7588
#./cvm.sh &
7689
#echo $! > cvm.pid
7790
start_cvm

stop_tracker.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22
tracker_pid=tracker.pid
3-
if [ ! -f $tracker_pid ];then
3+
if [ ! -f ${tracker_pid} ];then
44
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex tracker is not running."
55
exit 0
66
fi
7-
pkill -P `cat tracker.pid`
7+
pkill -P `cat ${tracker_pid}`
88
wait $!
99
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex tracker exited with status $?."
10-
rm -rf tracker.pid
10+
rm -rf ${tracker_pid}
1111
echo "INFO [$(date +"%d-%m|%H:%M:%S:000")] Cortex workspace cleaned with status $?."

tracker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22
tracker_pid=tracker.pid
3-
if [ -f $tracker_pid ];then
3+
if [ -f ${tracker_pid} ];then
44
echo "tracker is running."
55
exit 0
66
fi
77
./build/bin/tracker > /dev/null 2>&1 &
8-
echo $! > tracker.pid
8+
echo $! > ${tracker_pid}

0 commit comments

Comments
 (0)