https://github.com/peteretelej/execapi
Run commands or scripts on your servers via HTTP APIs
https://github.com/peteretelej/execapi
automation devops remote-execution
Last synced: 6 months ago
JSON representation
Run commands or scripts on your servers via HTTP APIs
- Host: GitHub
- URL: https://github.com/peteretelej/execapi
- Owner: peteretelej
- License: mit
- Created: 2023-08-21T09:31:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-21T15:22:22.000Z (almost 2 years ago)
- Last Synced: 2025-09-22T01:37:33.855Z (6 months ago)
- Topics: automation, devops, remote-execution
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Exec API
Execute commands and run scripts via HTTP APIs.
Exec API enables the execution of predefined commands and scripts remotely on your servers via HTTP APIs. Please use with caution; see [Best Practice](./#Best-Practice) section below for recommend usage.
Some use-cases I use this for:
- CI/CD automation & automated deployments, IoT commands, health checks, running scheduled tasks across nodes
## Running ExecAPI
- Copy `config.json.sample` to `config.json`
- Update the key value (used for authorizing API requests), and the `commands` as necessary
- Run execapi. Either by,
- Grabbing the latest release from the [Releases page](https://github.com/peteretelej/execapi/releases)
- Or, building and running `execapi`
Building and running
``` sh
go build -o execapi .
./execapi
```
Arguments:
```
./execapi --config /apps/execapi.config.json --listen 0.0.0.0:8081
```
- `config`: path to config.json (default "config.json")
- `listen`: address to listen on (default "localhost:8080")
Run Exec API on the server you'd like to execute commands or scripts.
## Usage
Assuming you have an application at `/home/user/apps/appx` that has a script `deploy.sh` in the directory, you can use the [./config.json.sample](./config.json.sample) as the config.json.
Update `commands` to add different options as desired.
### Requesting command execution
```sh
curl -X POST http://localhost:8080/run/appx -H "Authorization: Bearer EXECAPI_KEY"
```
This will attempt to run the script for the app named "appx".
Responds with http 200 (success) if command execution succeeds, or http 400 (with failure error) on failure.
Request full execution logs with `?verbose=1`, for example:
```sh
curl -X POST http://localhost:8080/run/appx?verbose=1 -H "Authorization: Bearer EXECAPI_KEY"
```
### Windows?
Yes, this also works on Windows, simply provide the directory path in the config.json eg `"dir": "C:\\myapps\\appx"`, and the executable as the script eg `"script": "commandx.exe"`.
## Best Practice
Please consider configuring Exec API to only be accessible by intended clients. While using pre-defined commands via `config.json` restricts what can be done, it still allows a client to initiate process execution (even though intended) on your servers.
- Access control: For example, using tailscale and ufw to only allow desired access:
- [Secure your Ubuntu server with Tailscale](https://tailscale.com/kb/1077/secure-server-ubuntu-18-04/)
- [Tailscale GitHub Action](https://github.com/tailscale/github-action)
- Logging and Monitoring: Set up logging and monitoring to keep track of access
- Use HTTPS: Secure communication between the client and server with HTTPS
# License
[MIT](./LICENSE)