Code Monkey home page Code Monkey logo

caddy-events-exec's Introduction

Run commands on Caddy events

This is the events.handlers.exec Caddy module. It executes commands to handle Caddy events.

It is EXPERIMENTAL and subject to change. After getting some production experience, if demand is high enough and if this is generally useful to most users, we may move this into the standard Caddy distribution. It would be the only Caddy module that executes commands on the system, so we want to make sure it does not allow for arbitrary commands to be executed.

Install

Like any other Caddy plugin, select it on the download page to get a custom build, or use xcaddy to build from source:

$ xcaddy build --with github.com/mholt/caddy-events-exec

Usage

Minimal JSON config example:

{
	"apps": {
		"events": {
			"subscriptions": [
				{
					"events": ["cert_obtained"],
					"handlers": [
						{
							"handler": "exec",
							"command": "systemctl",
							"args": ["reload", "mydaemon"]
						}
					]
				}
			]
		}
	}
}

This will run systemctl reload mydaemon every time Caddy obtains a certificate. Of course, you will need to make sure caddy has permission to run any command you configure it with.

Equivalent Caddyfile:

{
	events {
		on cert_obtained exec systemctl reload mydaemon
	}
}

Notes

This module runs commands in the background by default, to avoid performance problems caused by blocking.

If you want the ability to cancel an event (for example, cert_obtaining can be canceled to avoid getting a certificate) you must configure the command to run in the foreground as well as the exit code(s) to trigger an abort.

Please be mindful of any security implications of the commands you run and how you configure this module, at least until we get more production experience. Please test it out and report any issues!

caddy-events-exec's People

Contributors

mholt avatar pmaene avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.