This project implements a Job Worker Service that allows running and managing arbitrary Linux processes with fine-grained resource control and real-time output streaming.
- Go 1.22.5 or later
- Docker and Docker Compose
- OpenSSL (for certificate generation)
-
Clone the repository:
git clone https://github.com/zphoenixrises/JobWorkerService.git cd JobWorkerService
-
Install dependencies:
make deps
Before running the server or client, you need to generate certificates for mTLS:
make certs
This will create the necessary certificates in the certs
directory.
To run the tests in a Docker container:
make test
This command builds a test Docker image and runs the tests in a privileged container.
To build and run the server in a Docker container:
make run-server
This command builds the server binary, creates a Docker image, and starts the server in a privileged container using Docker Compose.
To stop the server:
make stop-server
First, build the CLI client:
make build-client
Before running the CLI, you need to export the following into your shell environment:
export SERVER_ADDRESS=localhost:50051 && export CLIENT_CERT_FILE=./certs/client1.crt && export CLIENT_KEY_FILE=./certs/client1.key && export CA_CERT_FILE=./certs/ca.crt
Now you can use the CLI to interact with the server. Here are some example commands:
-
Start a job that prints "start", "middle" and "end":
./build/jobworker-client start .5 1048576 1048576 sh -c "echo 'start'; sleep 20; echo 'middle'; sleep 20; echo 'end'"
This will return a job ID.
-
Stream the output of a job:
./build/jobworker-client stream <job-id>
-
Get the status of a job:
./build/jobworker-client status <job-id>
-
Stop a job:
./build/jobworker-client stop <job-id>
The command in 1. will pass. Here is an example of one that will fail:
./build/jobworker-client start .5 1024 1024 sh -c "echo 'start'; sleep 20; echo 'middle'; sleep 20; echo 'end'"
-
To see all available commands:
./build/jobworker-client
-
To see help for a specific command:
./build/jobworker-client <command>
-
To format the code:
make fmt
-
To run the linter:
make lint
-
To regenerate protobuf files (if you've made changes to the .proto files):
make proto
To clean up build artifacts and Docker resources:
make clean
- The server runs in a privileged Docker container to allow management of cgroups and other system resources.
- mTLS is used for secure communication between the client and server.
- Make sure the necessary environment variables are set when running the client (SERVER_ADDRESS, CLIENT_CERT_FILE, CLIENT_KEY_FILE, CA_CERT_FILE).
If you encounter any issues:
- Ensure all prerequisites are installed and up to date.
- Check that the server is running and accessible.
- Verify that the certificates have been generated correctly.
- Make sure the correct environment variables are set for the client.
If problems persist, please open an issue in the GitHub repository.