- Notifications
You must be signed in to change notification settings - Fork0
Self-hosted Azure Functions implemented in pure bash
License
sbrl/shunction
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
⛽ Self-hostedAzure Functions ftw! (Parody)
Shunction (SHell Function) is a parody ofAzure Functions. When I first heard of Azure Functions, I knew I had to write this.
In short,shunction given a folder of function scripts, provides various mechanisms by which they can be triggered.
Simply clone this repository like this:
git clone git@github.com:sbrl/shunction.gitcd shunction;
Then you can call shunction like this to display some quick help on how to use it:
./shunction
Functions are, by default, looked for in./functions
. A function file can be any executable with a filename in the formfunction_name.func
- the shebang (the#!...
bit) is respected.
Extra CLI arguments are supported:
Argument | Short form | Meaning |
---|---|---|
--config | -c | Specify the location of a configuration file to load |
--strip-ansi | none | Strip all ANSI escape codes from the output. Useful for sending the output to a log file etc. |
Although not required, shunctioncan take a configuration file. Specify it's location with the--config
CLI argument.
Such a configuration file should look something like this:
#!/usr/bin/env bashfunctions_folder="path/to/directory";
Directive | Default Value | Meaning |
---|---|---|
functions_folder | ./functions | The location of the directory in which to find functions to execute |
strip_ansi | false | Whether to strip all ANSI escape codes from the output. Useful for sending the output to a log file. |
Shunction supports 4 modes of operation: ad-hoc, cron, inotify, and http.
For one-off runs, usead-hoc mode.
./shunction trigger adhoc function_name
Regularly-repeating jobs can be invoked by editing your crontab withcrontab -e
. Paste in something like this:
5 4***/absolute/path/to/shunction trigger cron function_name
This website is really useful for generating crontab definitions:https://crontab.guru/.
The inotify mode allows you to run jobs when something changes on disk. Theinotifywait
command is required. Shunction will automatically watch subdirectories for you.
Use it like this:
./shunction inotify"path/to/file/or/directory""function_name"
It will stick around until it is killed. Note that it will run the function once forevery event detected in the background and start listening for additional jobs immediately, so if you need to ensure only 1 instance of your program is running, try looking atthis StackOverflow answer.
Finally, shunction supports listening over HTTP, though it's not advised to listen on anything more than localhost. Unlike inotify, http mode supports execution of multiple different functions, though only 1 at a time.
./shunction http bind_address port_number./shunction http 127.0.0.1 7777
Note that regular Linux rules still apply - if you want to listen on port numbers below 1024, shunction either needs to run as root (bad idea!), or you need to tell Linux that it's allowed to like this:setcap 'cap_net_bind_service=+ep' path/to/shunction
.