# Server Control App

The `server_control_app` is a FastAPI application designed to start and shut down the server using specified configuration paths and shutdown commands.


## Running the Application

To start the `server_control_app`, use the following command:

```bash
export PYTHONPATH=.
nohup python ./src/distributed_deployment_utils/server_control_app/main.py &
```

## API Endpoints

### Start Server

- **URL:** `/start_server/`
- **Method:** `POST`
- **Request Body:**
    ```json
    {
        "config_path": "<path_to_config_file>"
    }
    ```
- **Response:**
    ```json
    {
        "message": "Server started"
    }
    ```

### Shutdown Server

- **URL:** `/shutdown_server/`
- **Method:** `POST`
- **Request Body:**
    ```json
    {
        "process_name": "start_server.py"
    }
    ```
- **Response:**
    ```json
    {
        "message": "Server shut down"
    }
    ```

## Testing the Application

You can test the `server_control_app` using the following `curl` commands:

### Start Server

```bash
curl -X POST -H "Content-Type: application/json" -d '{"config_path":"./configs/assignments/debug.yaml"}' http://localhost:8003/start_server/
```

### Shutdown Server

```bash
curl -X POST -H "Content-Type: application/json" -d '{"process_name":"start_server.py"}' http://localhost:8003/shutdown_server/
```

## Logging

Logs are stored in `./outputs/server_control_app.log`. The logging level is set to `DEBUG` by default.

## Additional Notes

- Ensure that the configuration file path provided in the `config_path` argument is correct.
- Monitor the log file for any errors or logs generated by the application.
