github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/caas/scripts.go (about)

     1  // Copyright 2019 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package caas
     5  
     6  var (
     7  	// JujudStartUpSh is the start script for K8s controller and operator style agents.
     8  	JujudStartUpSh = `
     9  export JUJU_DATA_DIR=%[1]s
    10  export JUJU_TOOLS_DIR=$JUJU_DATA_DIR/%[2]s
    11  
    12  mkdir -p $JUJU_TOOLS_DIR
    13  cp /opt/jujud $JUJU_TOOLS_DIR/jujud
    14  
    15  %[3]s
    16  `[1:]
    17  
    18  	// JujudStartUpAltSh is the start script for K8s operator style agents.
    19  	JujudStartUpAltSh = `
    20  export JUJU_DATA_DIR=%[1]s
    21  export JUJU_TOOLS_DIR=$JUJU_DATA_DIR/%[2]s
    22  
    23  mkdir -p $JUJU_TOOLS_DIR
    24  cp %[3]s/jujud $JUJU_TOOLS_DIR/jujud
    25  
    26  %[4]s
    27  `[1:]
    28  
    29  	// MongoStartupShTemplate is used to generate the start script for mongodb.
    30  	// Mongo is very specific about what permissions the shared secret must have,
    31  	// so we must copy it and lock it down for rootless k8s controllers.
    32  	// NOTE: 170 uid/gid must be updated here and in caas/kubernetes/provider/constants/constants.go
    33  	MongoStartupShTemplate = `
    34  args="%[1]s"
    35  ipv6Disabled=$(sysctl net.ipv6.conf.all.disable_ipv6 -n)
    36  if [ $ipv6Disabled -eq 0 ]; then
    37    args="${args} --ipv6"
    38  fi
    39  SHARED_SECRET_SRC="%[2]s"
    40  SHARED_SECRET_DST="%[3]s"
    41  rm "${SHARED_SECRET_DST}" || true
    42  cp "${SHARED_SECRET_SRC}" "${SHARED_SECRET_DST}"
    43  chown 170:170 "${SHARED_SECRET_DST}"
    44  chmod 600 "${SHARED_SECRET_DST}"
    45  ls -lah "${SHARED_SECRET_DST}"
    46  while [ ! -f "%[4]s" ]; do
    47    echo "Waiting for %[4]s to be created..."
    48    sleep 1
    49  done
    50  exec mongod ${args}
    51  `[1:]
    52  
    53  	// JujudCopySh is the start script for K8s operator style agents.
    54  	JujudCopySh = `
    55  cp /opt/jujud %[1]s/jujud
    56  
    57  %[2]s
    58  `[1:]
    59  
    60  	// APIServerStartUpSh is the start script for the "api-server" container
    61  	// in the controller pod (Pebble running jujud).
    62  	APIServerStartUpSh = `
    63  export JUJU_DATA_DIR=%[1]s
    64  export JUJU_TOOLS_DIR=$JUJU_DATA_DIR/tools
    65  
    66  mkdir -p $JUJU_TOOLS_DIR
    67  cp /opt/jujud $JUJU_TOOLS_DIR/jujud
    68  
    69  %[2]s
    70  
    71  mkdir -p /var/lib/pebble/default/layers
    72  cat > /var/lib/pebble/default/layers/001-jujud.yaml <<EOF
    73  %[3]s
    74  EOF
    75  
    76  exec /opt/pebble run --http :%[4]s --verbose
    77  `[1:]
    78  )