Score:0

How to keep webhook listening in Ubuntu 18.04?

mw flag

I am setting up a webhook in a VPS so it gets pulls the code from a git repository every time there is a new commit. I have managed to set it up but it only works while -hooks is running.

After creating the webhook I use the following command to start listening (Replacing 0.0.0.0 with the actual public IP address of the VPS):

/usr/bin/webhook -hooks /root/webhooks/hooks.json -ip "0.0.0.0" -verbose

Then I get the following output:

[webhook] 2022/12/28 07:47:03 version 2.5.0 starting
[webhook] 2022/12/28 07:47:03 setting up os signal watcher
[webhook] 2022/12/28 07:47:03 attempting to load hooks from /root/webhooks/hooks.json
[webhook] 2022/12/28 07:47:03 found 1 hook(s) in file
[webhook] 2022/12/28 07:47:03   loaded: my-site.com
[webhook] 2022/12/28 07:47:03 serving hooks on http://0.0.0.0:9000/hooks/{id}
[webhook] 2022/12/28 07:47:03 os signal watcher ready

And I have configured the webhook in GitHub:

http://0.0.0.0:9000/hooks/my-site.com

The webhook works properly as long as [webhook] 2022/12/28 07:47:03 os signal watcher ready is on the screen, but if I press Ctrl + C then it is interrupted and the webhook is no longer listening.

Is there a way to keep the webhook listening in the background, so that any time there is a new commit on GitHub the VPS gets the latest code?

muru avatar
us flag
Does this answer your question? [How to run a process/binary on System startup/reboot in Ubuntu 20.04 LTS?](https://askubuntu.com/questions/1365334/how-to-run-a-process-binary-on-system-startup-reboot-in-ubuntu-20-04-lts)
Score:0
mw flag

After trying and researching a lot I found a way by installing Supervisor to keep the Webhook Server running. The original article is here.

An extract of the steps mentioned in the article:

  1. Install supervisor:
sudo apt install supervisor
  1. Navigate to the conf.d folder
cd /etc/supervisor/conf.d
  1. Create a configuration file:
sudo nano webhooks.conf
  1. Add the following inside the configuration file, replacing the username, IP, paths, etc. with your values.

Note: The path to your webhook folder can be found with whereis webhook.

[program:webhooks]
command=bash -c "<path to your webhook folder> -hooks <path to your hooks JSON file>/hooks.json -ip '0.0.0.0' -port '0000' -verbose"
redirect_stderr=true
autostart=true
autorestart=true
user=<user>
numprocs=1
process_name=%(program_name)s_%(process_num)s
stdout_logfile=<path to your hooks JSON file>/supervisor.log
environment=<ENVIRONMENT>="<your/environment>",USER="<user>"
  1. Save and close the configuration file
  2. Execute the following commands
touch <path to your hooks JSON file>/supervisor.log
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start webhooks:*

After this, the supervisor will keep your webhook server running.

muru avatar
us flag
You don't need to install anything additional for this. Systemd is installed by default and is meant for managing services.
HeytalePazguato avatar
mw flag
Thanks, after 4-5 hours of struggling with it the only way I found was using `supervisor` based on the article I mentioned. To be honest I think I won't try to change it now that is working haha. Have a good day!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.