Webhook: Help Wanted - Any examples of how to daemonize the webhook app with systemd

Created on 27 Jul 2017  路  9Comments  路  Source: adnanh/webhook

If anyone has any examples of how they used systemd or something similar to have this run as a background service with logging that would be really helpful.

Thanks in advance

Hass
(Linux Amateur..)

Most helpful comment

@scottstensland for some reason I thought I was going to have an issue with the switches when setting the ExecStart but as you said no issue and really simple.

Quick question how have you handled multiple webhooks? I'm running multiple related webhooks within a single JSON but wanted to use seperate JSON's for for different groups (to help manage change).

Did you run each of these as a separate systemd services?

E.g.
webhook-dns.service
webhook-mail.service

Any thoughts would be good.

For anyone else searching the site that is completely new to Linux below is what I did (very very basic stuff and so might not be secure or good...), but it will help you get going as you read the documents to expand the settings.

1) Created a file: MyAppInstanceName.service (for this example webhook.service) within /etc/systemd/system

2) edit the new file with the following (NOTE: in ExecStart use the line you normally use to start the webhook)

[Unit]
Description=webhook

[Service]
ExecStart=/usr/local/webhook-linux-amd64/webhook -hooks /webhook/site/dns_management.json -verbo$
Restart=always

[Install]
WantedBy=multi-user.target

The once saved run the following:

To start the service
systemctl start webhook

To start at book
systemctl enable webhook

To check if it's working:
journalctl -u webhook

All 9 comments

just setup like every other systemd service ... many doc examples out there ... after you push your envelope and have done battle then come back with questions ... no need to re-do yet another doc ... all systemd service setups are intentionally identical ... I can confirm this webhook works nicely launched as a systemd service

Thanks @scottstensland I'll have a go and will let you know how I get on.

@scottstensland for some reason I thought I was going to have an issue with the switches when setting the ExecStart but as you said no issue and really simple.

Quick question how have you handled multiple webhooks? I'm running multiple related webhooks within a single JSON but wanted to use seperate JSON's for for different groups (to help manage change).

Did you run each of these as a separate systemd services?

E.g.
webhook-dns.service
webhook-mail.service

Any thoughts would be good.

For anyone else searching the site that is completely new to Linux below is what I did (very very basic stuff and so might not be secure or good...), but it will help you get going as you read the documents to expand the settings.

1) Created a file: MyAppInstanceName.service (for this example webhook.service) within /etc/systemd/system

2) edit the new file with the following (NOTE: in ExecStart use the line you normally use to start the webhook)

[Unit]
Description=webhook

[Service]
ExecStart=/usr/local/webhook-linux-amd64/webhook -hooks /webhook/site/dns_management.json -verbo$
Restart=always

[Install]
WantedBy=multi-user.target

The once saved run the following:

To start the service
systemctl start webhook

To start at book
systemctl enable webhook

To check if it's working:
journalctl -u webhook

You can specify multiple -hooks switches for multiple files.

Yes I guess that might be the best way to balance not having everything in one JSON and to limit the risk of change impacting all Webhook.

Thanks I'm guessing we can close this now but hopefully some of the comments on the chain will be useful for other newbies!

Thanks

I would like to mention the fact that: in systemd service some environment variables will not be exposed, a solution would be this one: https://coreos.com/os/docs/latest/using-environment-variables-in-systemd-units.html

hi @rodislav I'm using CentOS 7.X and not having any issues with using the systemd and and the pass-environment-to-command?

Well as far as I can tell.... These webhooks are running all the time and would fail if they didn't the their env variables

Hi @rodislav I just had a thought related to if what you mentioned is part of "Unable to run curl commands in the shell scripts when started as a service #129" then I think I should be ok as I'm only using Environment Variables that are being imported via the webhook app and so don;t need access to the base system ones.

But do let me know your thoughts

Thanks

Hass

Hello @hassanbabaie , in my particular case I was using webhooks to run docker-compose commands, which is starting containers and those are using environment variables, so for the containers, the variables exposed in /etc/profile were not working. In order to solve this _(for now)_ I've extracted the needed vars to a file and mentioned that in the systemd service

[Unit]
Description=webhook

[Service]
WorkingDirectory=/home/rodislav
ExecStart=webhook -hooks /home/rodislav/webhooks.json -verbose -hotreload
EnvironmentFile=-/etc/webhook.environment

[Install]
WantedBy=multi-user.target
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sfxworks picture sfxworks  路  5Comments

scalp42 picture scalp42  路  4Comments

macau23 picture macau23  路  6Comments

simplenotezy picture simplenotezy  路  4Comments

wranitzky picture wranitzky  路  6Comments