webhook
webhook copied to clipboard
redeploy-webhook example - can't write output to a file
I have installed webhook on a droplet running Ubuntu 18.04 using the apt repository so it is set up as a service. I have set up redeploy-webhook as in the example you provide and when I run a get request via the browser to http://my_server:9000/hooks/redeploy-webhook I can get an echoed message to appear in the shell where I start the webhook service. However, if I add a command to output the message to a file, I can get the shell script to do just that from a shell, but when I send a get request to the webhook, I get an error message:
error occurred: exit status 1
Here's the kind of think I want try out in redeploy.sh:
#! /bin/bash
output=/var/www/webhooks/redeploy-test.txt
now=`date`
printf "Redeploy command was executed $now \n" >> $output
Now, if I start webhook from a shell with my usual login credentials (which can get root privileges if I want) like this:
webhook -hooks /var/www/webhooks/hooks.json -verbose
I get the error message, but if I start it taking the identity of www-data (the user that owns the Apache process), everything works beautifully:
sudo -Hu www-data webhook -hooks /var/www/webhooks/hooks.json -verbose
and redeploy-test.txt contains line like this:
Redeploy command was executed Wed Mar 17 08:00:52 UTC 2021
Redeploy command was executed Wed Mar 17 08:00:52 UTC 2021
Redeploy command was executed Wed Mar 17 08:01:10 UTC 2021
Redeploy command was executed Wed Mar 17 08:01:11 UTC 2021
Could you explain in more detail exactly how to set ownership and permissions for a script called from a webhook when running a get request. Should the owner be my_name and the group www-data, or what? I want to be able to start webhook as a service and use it to call from GitHub so that I can get the webserver to pull the latest version of a github repository. Which user runs webhook as a service? Any help would be appreciated.
I'm not familiar with the Ubuntu packaging. When run as a service, what user does it run as?