ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | |
| 4 | MS=$1 |
| 5 | ACTION=$2 |
| 6 | |
| 7 | do_stop(){ |
| 8 | MS=$1 |
| 9 | if ! docker ps --filter "name=^/${MS}" | grep -q "${MS}"; then |
| 10 | echo "${MS} is already stopped, ignore the action." |
| 11 | else |
| 12 | echo "Executing 'docker stop ${MS}'" |
| 13 | docker stop ${MS} |
| 14 | fi |
| 15 | } |
| 16 | |
| 17 | do_start(){ |
| 18 | MS=$1 |
| 19 | if docker ps --filter "name=^/${MS}" | grep -q "${MS}"; then |
| 20 | echo "${MS} is running, performing restart." |
| 21 | echo "Executing \'\docker stop ${MS}'" |
| 22 | docker stop ${MS} && sleep 2 |
| 23 | echo "Executing 'docker start ${MS}'" |
| 24 | docker start ${MS} |
| 25 | else |
| 26 | echo "Executing 'docker start ${MS}'" |
| 27 | docker start ${MS} |
| 28 | fi |
| 29 | } |
| 30 | |
| 31 | |
| 32 | do_status(){ |
| 33 | MS=$1 |
| 34 | out=$(docker ps --filter "name=^/${MS}" | grep "${MS}") |
| 35 | res=$? |
| 36 | if [ "$res" == "0" ]; then |
| 37 | echo $out |
| 38 | echo "The ${MS} is currnetly up & running!" |
| 39 | else |
| 40 | echo "The ${MS} is currnetly not running!" |
| 41 | fi |
| 42 | } |
| 43 | |
| 44 | |
| 45 | case $ACTION in |
| 46 | start) |
| 47 | do_start ${MS} |
| 48 | ;; |
| 49 | stop) |
| 50 | do_stop ${MS} |
| 51 | ;; |
| 52 | status) |
| 53 | do_status ${MS} |
| 54 | ;; |
| 55 | restart) |
| 56 | do_stop ${MS} |
| 57 | do_start ${MS} |
| 58 | ;; |
| 59 | *) |
| 60 | do_status ${MS} |
| 61 | ;; |
| 62 | esac |