-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartStopDocker.sh
More file actions
87 lines (78 loc) · 1.27 KB
/
Copy pathstartStopDocker.sh
File metadata and controls
87 lines (78 loc) · 1.27 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
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
#!/bin/bash
if [[ $# -eq 0 ]] ; then
echo 'please specify service'
exit 0
fi
if [ $# -eq 1 ];
then
#srvname=$1
echo "Checking docker is running or not"
if [ "$(systemctl is-active $1)" == active ];
then
sleep 1
echo "$1 is running"
else
echo "$1 is not running"
echo "Attempting to start $1"
systemctl start $1
sleep 5
echo "starting $1"
sleep 5
if [ "$(systemctl is-active $1)" == active ];
then
sleep 5
echo "$1 Started"
else
echo "Could not start $1"
fi
fi
exit 1
fi
if [ $# -eq 2 ];
then
echo "Checking docker is running or not"
if [ "$(systemctl is-active $1)" == active ];
then
sleep 1
echo "$1 is running"
else
echo "$1 is not running"
echo "Attempting to start $1"
systemctl start $1
sleep 5
echo "starting $1"
sleep 5
if [ "$(systemctl is-active --quiet $1)" == active ];
then
sleep 5
echo "$1 Started"
else
echo "Could not start $1"
fi
fi
echo "Checking $2 is running or not"
sleep 1
if [ "$(docker ps -q -f name=$2)" ];
then
if [ "$(docker ps -aq -f status=running -f name=$2)" ];
then
echo "$2 is running"
sleep 1
fi
else
if [ "$(docker ps -aq -f status=exited -f name=$2)" ];
then
echo "$2 is not running"
sleep 1
echo "attempt starting $2"
sleep 1
docker start $2
sleep 2
echo "$2 started"
else
sleep 1
echo "no such container"
fi
fi
exit 2
fi