Webhook: Webhook appears to be working but local script is not executing

Created on 6 Feb 2020  ·  7Comments  ·  Source: adnanh/webhook

I am running the following command which appears to be working (status 200) Yet it never triggers my script!

root@ip-172-30-100-108:/var/scripts# curl -l -X POST -H 'Content-Type: application/json' http://localhost:9000/hooks/redeploy-webhook -v
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9000 (#0)
> POST /hooks/redeploy-webhook HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 200 OK
< Date: Thu, 06 Feb 2020 22:15:37 GMT
< Content-Length: 0
< Content-Type: text/plain; charset=utf-8

*Note same output shows in if I remove 'Content-Type: application/json'

WEBHOOK OUTPUT

root@ip-172-30-100-108:/var/scripts# /usr/bin/webhook  -verbose -hooks=/var/scripts/hooks.json -hotreload
[webhook] 2020/02/06 22:29:06 version 2.5.0 starting
[webhook] 2020/02/06 22:29:06 setting up os signal watcher
[webhook] 2020/02/06 22:29:06 attempting to load hooks from /var/scripts/hooks.json
[webhook] 2020/02/06 22:29:06 found 1 hook(s) in file
[webhook] 2020/02/06 22:29:06   loaded: redeploy-webhook
[webhook] 2020/02/06 22:29:06 setting up file watcher for /var/scripts/hooks.json
[webhook] 2020/02/06 22:29:06 serving hooks on http://0.0.0.0:9000/hooks/{id}
[webhook] 2020/02/06 22:29:06 listen tcp 0.0.0.0:9000: bind: address already in use

HOOKS.JSON

root@ip-172-30-100-108:/var/scripts# cat hooks.json
[
  {
    "id": "redeploy-webhook",
    "execute-command": "/var/scripts/redeploy.sh",
    "command-working-directory": "/var/scripts"
  }
]

*Note /var/scripts/redeploy.sh does run from this directory .It just calls a python script (directly call that pyton script in "execute-command" does not work either)

SCRIPT TO BE EXECUTED

root@ip-172-30-100-108:/var/scripts# cat /var/scripts/redeploy.sh
#! /bin/sh
/var/scripts/readyrunning.py

FILE OWNERSHIP

root@ip-172-30-100-108:/var/scripts# ls -la redeploy.sh
-rwxrwxrwx 1 root root 42 Feb  6 21:26 redeploy.sh

SYSTEMD CONFIG

root@ip-172-30-100-108:/var/scripts# systemctl status webhook.service
● webhook.service - Small server for creating HTTP endpoints (hooks)
   Loaded: loaded (/lib/systemd/system/webhook.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-02-06 21:53:26 UTC; 37min ago
     Docs: https://github.com/adnanh/webhook/
 Main PID: 20806 (webhook)
    Tasks: 4 (limit: 2361)
   CGroup: /system.slice/webhook.service
           └─20806 /usr/bin/webhook -nopanic -hooks /etc/webhook.conf

Feb 06 21:53:26 ip-172-30-100-108 systemd[1]: Started Small server for creating HTTP endpoints (hooks).
Feb 06 21:54:04 ip-172-30-100-108 webhook[20806]: [webhook] 2020/02/06 21:54:04 Started POST /hooks/redeploy-webhook
Feb 06 21:54:04 ip-172-30-100-108 webhook[20806]: [webhook] 2020/02/06 21:54:04 Completed 200 OK in 68.273µs
Feb 06 21:59:07 ip-172-30-100-108 webhook[20806]: [webhook] 2020/02/06 21:59:07 Started POST /hooks/redeploy-webhook
Feb 06 21:59:07 ip-172-30-100-108 webhook[20806]: [webhook] 2020/02/06 21:59:07 Completed 200 OK in 59.334µs

Note I am running as root (it is test box I will fix this in prod) I had to add root as a user to get past "no hook found" error.

root@ip-172-30-100-108:/var/scripts# cat /lib/systemd/system/webhook.service
[Unit]
Description=Small server for creating HTTP endpoints (hooks)
Documentation=https://github.com/adnanh/webhook/

[Service]
ExecStart=/usr/bin/webhook -nopanic -hooks /etc/webhook.conf
User=root
Group=root

[Install]
WantedBy=multi-user.target

This is the Ubuntu. Please help me figure out how to trigger the script. Thanks!

All 7 comments

Could you please upgrade to the latest release as 2.5.0 is a very old release :-)

Also check that nothing else is running on the port 9000, as the log indicates it couldn't bind to that port?

webhook] 2020/02/06 22:29:06 listen tcp 0.0.0.0:9000: bind: address already in use

But then again, rest of the logs indicate you've managed to hit the webhook...

Whats the output of ls -la /var/scripts/readyrunning.py

Thanks for your prompt response.

Version
FYI Looks like apt repository has an old version. When I run this

root@ip-172-30-100-108:/home/ubuntu# apt-get update && apt-get upgrade webhook

It upgrades but I still get 2.5 version even after restarting the service and reloading it

Either way I will do the zip install tomorrow

Firewall

  1. I am glad you mentioned the firewall. Nothing else is using that port. But..........it is showing as "tcp6" for some reason. Is this a setting in a conf file I can change?
root@ip-172-30-100-108:/home/ubuntu# netstat -ant |grep 9000
tcp6       0      0 :::9000                 :::*                    LISTEN

If you want to know what process is listening on port 9000, try one of these commands (I prefer ss nowadays):

sh# ss -tnlp
sh# netstat -tnlp

Port Info

root@ip-172-30-100-108:/home/ubuntu# netstat -tnlp |grep 9000
tcp6       0      0 :::9000                 :::*                    LISTEN      21476/webhook
root@ip-172-30-100-108:/home/ubuntu# ss -tnlp |grep 9000
LISTEN   0         128                       *:9000                   *:*        users:(("webhook",pid=21476,fd=3))



md5-a631e62df304e8f935099cfb17d72394



root@ip-172-30-100-108:/home/ubuntu# ls -la /var/scripts/readyrunning.py
-rwxr-xr-x 1 root root 1734 Feb  6 21:09 /var/scripts/readyrunning.py
  • Still have not had a chance to upgrade yet. Sorry

Does your readyrunning.py have a corresponding shebang on top i.e. #!/usr/bin/env python?
If not, could you add it and try again.

-- OR --

Modify your /var/scripts/redeploy.sh to invoke interpreter directly like so:

#!/bin/sh
/path/to/python /var/scripts/readyrunning.py

Just be sure to replace /path/to/python with the actual path to the python binary.

I was able to fix this by reinstalling everything on a different server that had access to the internet and using "go get" instead of the "apt get" install

Before I had installed it on a server that was behind a proxy and could not get "go get" to work. I had used apt-get instead (I had already known how to use apt behind a proxy)

My guess is it had something to do with the go apt repository install. It is working now. Thank you very much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eschizoid picture eschizoid  ·  4Comments

pascalandy picture pascalandy  ·  4Comments

MichelDiz picture MichelDiz  ·  5Comments

alexw22 picture alexw22  ·  3Comments

abitrolly picture abitrolly  ·  4Comments