Webhook: PM2 problem

Created on 24 May 2020  ·  11Comments  ·  Source: adnanh/webhook

I'm using PM2 to automatically start the webhook on my VPS server (UBUNTU 18) and everything works fine. The problem is when I restart the server. When I run the process again, i have an error and I must to execute command "pkill webhook" and "pm2 restart process_name" and then its work again.

0|start | [webhook] 2020/05/24 19:31:09 listen tcp my_ip:9000: bind: address already in use
0|start | [webhook] 2020/05/24 19:31:09 version 2.5.0 starting
0|start | [webhook] 2020/05/24 19:31:09 setting up os signal watcher
0|start | [webhook] 2020/05/24 19:31:09 attempting to load hooks from hooks.json
0|start | [webhook] 2020/05/24 19:31:09 found 1 hook(s) in file
0|start | [webhook] 2020/05/24 19:31:09 loaded: build-webhook
0|start | [webhook] 2020/05/24 19:31:09 serving hooks on http://my_ip:9000/hooks/{id}

Is there any way to kill the previous address after server reboot?
Sorry I'm a layman in the subject :(

Tom.

question

Most helpful comment

Yeah! Now its work exactly what i want :) Thank You so much for your help and time, Cameron, You are Great :)

All 11 comments

I'm not familiar with PM2. Are you saying that pm2 restart webhook doesn't work?

PM2 is only for maintenance hooks with command "webhook -hooks hooks.json -verbose", and it's working ok. Problem is when i try to restart or reboot my linux server. After reboot, when i try to run same process witch PM2 or only just witch command above i have error:

[webhook] 2020/05/25 08:42:44 serving hooks on http://0.0.0.0:9000/hooks/{id}
[webhook] 2020/05/25 08:42:44 listen tcp 0.0.0.0:9000: bind: address already in use

Every time, after reboot, i must kill "old" process before running webhook with PM2 or just with command webhook -hooks hooks.json -verbose. I don't know why.

It sounds like PM2 is starting the webhook service upon reboot and then you're trying to start it again manually. In my mind, it's all working as designed. What am I missing?

Thanks for your patience, Cameron :). Let's forget about PM2 for a while. The same problem occurs without using it. Maybe step by step.

  1. I start the webhook from the webhook -hooks hooks.json -verbose command. Everything works, the hook is available under the configured endpoint.

  2. I am restarting/reboot my ubuntu server.

  3. I start the webhook again as in the first point, and this appears in the terminal:

[webhook] 2020/05/25 08:42:44 serving hooks on http://0.0.0.0:9000/hooks/{id}
[webhook] 2020/05/25 08:42:44 listen tcp 0.0.0.0:9000: bind: address already in use
...

  1. When i check webhook endpoint link in browser i have "Hook not found."

This is exactly the same case as in https://github.com/adnanh/webhook/issues/246 issue, but for me it happens after server reset. I have to do it after reboot (kill this connection) every time to be able to run webhook again.

After rebooting the server (step 2 above), webhook is already running. What is starting webhook (before step 3)? Whatever it is, share with us how that's configured.

I have 3 files:

hooks.json with:

[
  {
    "id": "build-webhook",
    "execute-command": "/var/www/webhook/build.sh",
    "command-working-directory": "/var/www/mydomain.com/public_html/sandbox"
  }
]

build.sh with:

#!/bin/bash
gatsby build

start.sh with:

webhook -hooks hooks.json -ip "my server ip" -verbose

I used PM2 as process manager for the webhook to work without interruption. (PM2 start start.sh --name webhook)

and everything working fine. I have endpoint link with working webhook that realised gatsby build command everytime when i use this endpoint.

After reboot, webhook endpoint not working (Hook not found). As i wrote in above comments, even if I restart the PM2 process again, i must close/kill old network connection with 9000 port because i have the same error like in https://github.com/adnanh/webhook/issues/246

I want the webhook process to start automatically after a reset without this error and without manual killing old connection. I`m sorry, I don't know how to describe this problem more simply :( Thanks!

It sounds like webhook is being started by systemd before PM2 starts. See what systemctl status webhook shows.

After reboot:

● webhook.service - Small server for creating HTTP endpoints (hooks)
   Loaded: loaded (/lib/systemd/system/webhook.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-05-27 20:15:14 CEST; 2min 16s ago
     Docs: https://github.com/adnanh/webhook/
 Main PID: 784 (webhook)
    Tasks: 4 (limit: 2361)
   CGroup: /system.slice/webhook.service
           └─784 /usr/bin/webhook -nopanic -hooks /etc/webhook.conf

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

seems that webhook is being started but endpoint link not working, i have "Hook not found."

After this, i put in terminal sudo pkill webhook and i run PM2 process again. I have:

● webhook.service - Small server for creating HTTP endpoints (hooks)
   Loaded: loaded (/lib/systemd/system/webhook.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2020-05-27 20:29:02 CEST; 1min 8s ago
     Docs: https://github.com/adnanh/webhook/
  Process: 805 ExecStart=/usr/bin/webhook -nopanic -hooks /etc/webhook.conf (code=killed, signal=TERM)
 Main PID: 805 (code=killed, signal=TERM)

... inactive(dead), but now webhook working fine :) its crazy.

I think the Ubuntu webhook package uses /etc/webhook.conf as the default hooks configuration file. That's why you're hook isn't found. (We don't manage the Ubuntu packages, BTW)

Try disabling the systemd webhook service:

systemctl disable webhook

Yeah! Now its work exactly what i want :) Thank You so much for your help and time, Cameron, You are Great :)

Was this page helpful?
0 / 5 - 0 ratings