Webhook: no such file or directory

Created on 18 Apr 2019  路  4Comments  路  Source: adnanh/webhook

I have a simple script test.sh:

root@ip-10-22-202-0:~# cat /home/ubuntu/test.sh
#!/bin/bash

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
pwd;
whoami;

Runs fine as root:

root@ip-10-22-202-0:~# su ubuntu -c '/home/ubuntu/test.sh'
/root
ubuntu

Hooks in /etc/webhook.conf:

[
  {
    "id": "redeploy-webhook",
    "execute-command": "su ubuntu -c '/home/ubuntu/test.sh'",
    "command-working-directory": "/home/ubuntu",
    "response-message": "Executing redeploy script"
  }
]

Now if I try to run it through webhook, I'm getting an error:

Apr 18 19:14:46 ip-10-22-202-0 webhook[3357]: [webhook] 2019/04/18 19:14:46 Started GET /hooks/redeploy-webhook
Apr 18 19:14:46 ip-10-22-202-0 webhook[3357]: [webhook] 2019/04/18 19:14:46 redeploy-webhook got matched
Apr 18 19:14:46 ip-10-22-202-0 webhook[3357]: [webhook] 2019/04/18 19:14:46 redeploy-webhook hook triggered successfully
Apr 18 19:14:46 ip-10-22-202-0 webhook[3357]: [webhook] 2019/04/18 19:14:46 Completed 200 OK in 105.18碌s
Apr 18 19:14:46 ip-10-22-202-0 webhook[3357]: [webhook] 2019/04/18 19:14:46 executing su ubuntu -c '/home/ubuntu/test.sh' (su ubuntu -c '/home/ubuntu/test.sh') with arguments ["su ubuntu -c '/home/ubuntu/test.sh'"] and environment [] using /home/ubuntu as cwd
Apr 18 19:14:46 ip-10-22-202-0 webhook[3357]: [webhook] 2019/04/18 19:14:46 command output:
Apr 18 19:14:46 ip-10-22-202-0 webhook[3357]: [webhook] 2019/04/18 19:14:46 error occurred: fork/exec su ubuntu -c '/home/ubuntu/test.sh': no such file or directory
Apr 18 19:14:46 ip-10-22-202-0 webhook[3357]: [webhook] 2019/04/18 19:14:46 finished handling redeploy-webhook

No idea why it can't find the file as it obviously exists:

root@ip-10-22-202-0:~# ll /home/ubuntu/test.sh
-rwxrwxr-x 1 ubuntu ubuntu 110 Apr 18 19:08 /home/ubuntu/test.sh*

Any ideas?

Thanks in advance!

Most helpful comment

For anyone else needing to do this, this is the syntax that seemed to work for me:

"execute-command": "/bin/su",
"pass-arguments-to-command": [
  {
    "source": "string",
    "name": "ubuntu"
  },
  {
    "source": "string",
    "name": "-c"
  },
  {
    "source": "string",
    "name": "'/usr/bin/whoami'"
  },
],

All 4 comments

Another example:

Apr 18 19:17:23 ip-10-22-202-0 webhook[3485]: [webhook] 2019/04/18 19:17:23 Started GET /hooks/redeploy-webhook
Apr 18 19:17:23 ip-10-22-202-0 webhook[3485]: [webhook] 2019/04/18 19:17:23 redeploy-webhook got matched
Apr 18 19:17:23 ip-10-22-202-0 webhook[3485]: [webhook] 2019/04/18 19:17:23 redeploy-webhook hook triggered successfully
Apr 18 19:17:23 ip-10-22-202-0 webhook[3485]: [webhook] 2019/04/18 19:17:23 Completed 200 OK in 106.14碌s
Apr 18 19:17:23 ip-10-22-202-0 webhook[3485]: [webhook] 2019/04/18 19:17:23 executing su ubuntu -c '/usr/bin/whoami' (su ubuntu -c '/usr/bin/whoami') with arguments ["su ubuntu -c '/usr/bin/whoami'"] and environment [] using /home/ubuntu as cwd
Apr 18 19:17:23 ip-10-22-202-0 webhook[3485]: [webhook] 2019/04/18 19:17:23 command output:
Apr 18 19:17:23 ip-10-22-202-0 webhook[3485]: [webhook] 2019/04/18 19:17:23 error occurred: fork/exec su ubuntu -c '/usr/bin/whoami': no such file or directory
Apr 18 19:17:23 ip-10-22-202-0 webhook[3485]: [webhook] 2019/04/18 19:17:23 finished handling redeploy-webhook
^C
root@ip-10-22-202-0:~# su ubuntu -c '/usr/bin/whoami'
ubuntu

If anyone runs into this issue, the Ubuntu package version is broken I believe.

I replaced it with building from go directly and it works.

The fix for the old version would be to modify your hook to execute the /bin/su command ("execute-command": "/bin/su"), and then use the "pass-arguments-to-command" directive to pass the ubuntu -c '/usr/bin/whoami' string to the su command.

Cheers :-)

For anyone else needing to do this, this is the syntax that seemed to work for me:

"execute-command": "/bin/su",
"pass-arguments-to-command": [
  {
    "source": "string",
    "name": "ubuntu"
  },
  {
    "source": "string",
    "name": "-c"
  },
  {
    "source": "string",
    "name": "'/usr/bin/whoami'"
  },
],
Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndrewSav picture AndrewSav  路  6Comments

adamaze picture adamaze  路  5Comments

abitrolly picture abitrolly  路  4Comments

eschizoid picture eschizoid  路  4Comments

dcj picture dcj  路  5Comments