SystemGo is a comprehensive and extensible system management tool inspired by the capabilities of systemd
. It is designed to manage and monitor system tasks and services with a focus on flexibility, reliability, and ease of use. SystemGo provides features for starting, stopping, restarting, and monitoring services, as well as an optional web interface for real-time management.
- Process Management: Start, stop, restart, and monitor system tasks and services.
- Service Management: Manage services with support for different types of services.
- Logging: Comprehensive logging for monitoring and debugging.
- Configuration Management: Support for configuration files to define services and processes.
- Web Interface: Optional web interface for monitoring and managing services.
- Health Checks: Built-in health check mechanisms to ensure service health.
- Service Dependencies: Define dependencies between services to manage their startup and shutdown order.
- Security: Secure communication and authentication mechanisms.
- Go 1.22.3 or later
- Git
-
Clone the repository:
git clone https://github.com/your-username/systemgo.git cd systemgo
Build the project: ``go mod tidy ; go build -o systemgo main.go`
SystemGo uses a YAML configuration file to define services. The configuration file should be named config.yaml and placed in the root directory of the project.
Example config.yaml yaml
services:
- name: example-service
- command: /path/to/your/executable
SystemGo can be managed via command-line interface. The basic usage pattern is:
systemgo <start|stop|restart|status> <service-name>
Start a service: ./systemgo start example-service
Stop a service: ./systemgo stop example-service
Restart a service: ./systemgo restart example-service
Get the status of a service: ./systemgo status example-service
SystemGo includes an optional web interface for monitoring and managing services. The web server runs on port 8080 by default.
The web server starts automatically when you run the main application. To access the web interface, navigate to http://localhost:8080 in your web browser.
Start a Service: GET /start?name=<service-name>
Stop a Service: GET /stop?name=<service-name>
Restart a Service: GET /restart?name=<service-name>
Get Service Status: GET /status?name=<service-name>
Health Check: GET /health?name=<service-name>
SystemGo includes built-in health checks to ensure the health of services. Health checks can be configured and executed using the web interface or programmatically.
In daemons/handlers.go
, the health check handler is implemented as follows:
func HealthCheckHandler(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
svc, exists := services[name]
if !exists {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(map[string]string{"status": "not found"})
return
}
status, err := internal.CheckHealth(name, svc.Command)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"status": status, "error": err.Error()})
return
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": status})
}
SystemGo provides comprehensive logging for monitoring and debugging. Logs are written to a file named systemgo.log in the root directory.
INFO: General information about the operations.
ERROR: Error messages when operations fail.
In internal/logging.go
, logging is initialized as follows:
package internal
import (
"log"
"os"
)
var (
InfoLogger *log.Logger
ErrorLogger*log.Logger
)
func Init() {
file, err := os.OpenFile("systemgo.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("Failed to open log file: %v", err)
}
InfoLogger = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
ErrorLogger = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
}
SystemGo allows defining dependencies between services to ensure they start and stop in the correct order.
To add dependencies, extend the ServiceConfig struct in internal/settings.go
:
service "example-service" {
name = "Example Service"
command = "executable-name" # Executables should be built in systemgo/bin directory
enabled = true
retry_count = 3
dependencies = "another-service, yet-another-service" # Leave blank if not required
Update the ServiceConfig struct and initialization logic to handle dependencies.
SystemGo provides secure communication and authentication mechanisms for the web interface.
To enable TLS, modify the StartWebServer function in daemons/server.go
:
func StartWebServer() {
http.HandleFunc("/start", StartServiceHandler)
http.HandleFunc("/stop", StopServiceHandler)
http.HandleFunc("/restart", RestartServiceHandler)
http.HandleFunc("/status", StatusServiceHandler)
http.HandleFunc("/health", HealthCheckHandler)
log.Fatal(http.ListenAndServeTLS(":8080", "server.crt", "server.key", nil))
}
Ensure you have the necessary certificate (server.crt) and key (server.key) files.
We welcome contributions to improve SystemGo! To contribute:
Create a new branch for your feature or bugfix. Make your changes and commit them with a clear message. Push your changes to your fork. Create a pull request describing your changes.
SystemGo is licensed under the MIT License. Feel free to use, modify, and distribute it according to the terms of the license.