aregnier
aregnier

Reputation: 1624

multiple command in postStart hook of a container

in a kubernetes Deployment yaml file is there a simple way to run multiple commands in the postStart hook of a container?

I'm trying to do something like this:

lifecycle:
  postStart:
    exec:
      command: ["/bin/cp", "/webapps/myapp.war", "/apps/"]
      command: ["/bin/mkdir", "-p", "/conf/myapp"]
      command: ["touch", "/conf/myapp/ready.txt"]

But it doesn't work. (looks like only the last command is executed)

I know I could embed a script in the container image and simply call it there... But I would like to be able to customize those commands in the yaml file without touching the container image.

thanks

Upvotes: 50

Views: 42141

Answers (2)

Bruno Quaresma
Bruno Quaresma

Reputation: 10727

You also can create a bash or make script to group all those commands.

#!/bin/bash

command_one
command_two
command_three

Upvotes: 4

aborilov
aborilov

Reputation: 8764

Only one command allowed, but you can use sh -c like this

  lifecycle:
    postStart:
      exec:
        command:
          - "sh"
          - "-c"
          - >
            if [ -s /var/www/mybb/inc/config.php ]; then
            rm -rf /var/www/mybb/install;
            fi;
            if [ ! -f /var/www/mybb/index.php ]; then
            cp -rp /originroot/var/www/mybb/. /var/www/mybb/;
            fi

Upvotes: 85

Related Questions