github.com/iotexproject/iotex-core@v1.14.1-rc1/tools/devenv/control.sh (about)

     1  #!/bin/bash
     2  
     3  # Colour codes
     4  YELLOW='\033[0;33m'
     5  RED='\033[0;31m'
     6  NC='\033[0m' # No Color
     7  
     8  # Dirs and files
     9  USER_DIR="${HOME}/.iotex"
    10  PROJECT_ABS_DIR=$(cd "$(dirname "$0")";pwd)
    11  REPO_ABS_DIR=$(cd "$PROJECT_ABS_DIR/..";pwd)
    12  
    13  pushd () {
    14      command pushd "$@" > /dev/null
    15  }
    16  
    17  popd () {
    18      command popd "$@" > /dev/null
    19  }
    20  
    21  function checkDockerPermissions() {
    22      docker ps > /dev/null 2>&1
    23      if [ $? = 1 ];then
    24          echo -e "your $RED [$USER] $NC not privilege docker" 
    25          echo -e "please run $RED [sudo bash] $NC first"
    26          echo -e "Or docker not install "
    27          exit 1
    28      fi
    29  }
    30  
    31  function checkDockerCompose() {
    32      docker-compose --version > /dev/null 2>&1
    33      if [ $? -eq 127 ];then
    34          echo -e "$RED docker-compose command not found $NC"
    35          echo -e "Please install it first"
    36          exit 1
    37      fi
    38  }
    39  
    40  function startup() {
    41      echo -e "Start iotex-server..."
    42      pushd $DOCKER_COMPOSE_HOME
    43      docker-compose up -d
    44      docker ps | grep iotex|grep -v grep > /dev/null 2>&1
    45      popd
    46  }
    47  
    48  function stop() {
    49      echo -e "Stopping iotex-server..."
    50      pushd $DOCKER_COMPOSE_HOME
    51      docker-compose stop
    52      popd
    53  }
    54  
    55  function status() {
    56      pushd $DOCKER_COMPOSE_HOME
    57      docker-compose ps iotex
    58      popd
    59  }
    60  
    61  function main() {
    62      # Check and clean
    63      checkDockerPermissions     # Determine the current user can run docker
    64      checkDockerCompose         # Determin the docker-compose is installed
    65  
    66      DOCKER_COMPOSE_HOME="$(cat $USER_DIR/workdir)/docker-compose"
    67      
    68      # Start server
    69      if [ "$1" == "start" ];then
    70          startup || exit 2
    71          echo 'Listening on 127.0.0.1:14014'
    72      elif [ "$1" == "stop" ];then
    73          stop
    74      elif [ "$1" == "status" ];then
    75          status
    76      fi
    77  }
    78  
    79  main $@