0

I have an issue with my script. I use beanstalk to deploy my ASP.NET Core code. And in my post deploy I have this code:

#!/usr/bin/env bash
file1=sudo cat /opt/elasticbeanstalk/config/ebenvinfo/region
file2=/opt/elasticbeanstalk/bin/get-config container -k environment_name
file3=$file2.$file1.elasticbeanstalk.com
echo $file3
sudo certbot -n -d $file3 --nginx --agree-tos --email al@gmail.com

It works perfectly if I launch it on the instance but in the postdeploy script I have the error:

[ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPostDeployHooks]. Stop running the command. Error: Command .platform/hooks/postdeploy/00_get_certificate.sh failed with error fork/exec .platform/hooks/postdeploy/00_get_certificate.sh: exec format error

PS: My script has .ebextension which allows exec rights

container_commands:
  00_permission_hook:
    command: "chmod +x .platform/hooks/postdeploy/00_get_certificate.sh"

What's wrong?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
dalton5
  • 915
  • 2
  • 14
  • 28
  • 2
    Can you try with `#!/bin/bash`? – Marcin Nov 17 '21 at 00:39
  • I have the same error – dalton5 Nov 17 '21 at 08:11
  • Platform scripts are run as root, so there is not need to use sudo in them. Also if you are using git, add execution permission like this may change it - https://stackoverflow.com/questions/40978921/how-to-add-chmod-permissions-to-file-in-git/40979016#40979016 – gowthz Nov 27 '21 at 04:34
  • I have the same issue , An error occurred during execution of command [app-deploy] - [RunAppDeployPostDeployHooks]. Stop running the command. Error: Command .platform/hooks/postdeploy/77_nginx_restart.sh failed with error fork/exec .platform/hooks/postdeploy/77_nginx_restart.sh: exec format error – Sandeep Nandey Jul 28 '22 at 07:30

1 Answers1

1

I had the same issue and added

#!/bin/bash

to the top of the sh file and also ran "chmod +x" to the sh file and it was solved

mahmouds12
  • 31
  • 3