harbor run -t LiteCoder/systemd-service-builderharbor download LiteCoder/systemd-service-builderBuild a shell-based build tool that takes a C source file and a JSON configuration, compiles the binary, generates a systemd service unit file, and produces an installation script. All components are orchestrated by a single entry point script.
/app/service_config.json (service configuration), plus a C source file specified in the config/app/build/ directory containing the compiled binary/app/build/<service_name>.service — the generated systemd unit file/app/build/install.sh — the generated installation script/app/build.sh — the main build script that reads config, compiles, and generates all outputs/app/service_config.json has the following structure:
{
"service_name": "myapp",
"description": "My custom daemon application",
"source_file": "src/myapp.c",
"user": "www-data",
"restart_policy": "on-failure",
"after": "network.target",
"compile_flags": "-Wall -O2"
}
Field definitions:
service_name (string, required): Name used for the binary, service file, and install paths.description (string, required): Description line in the systemd unit file.source_file (string, required): Relative path (from /app/) to the C source file to compile.user (string, optional, default root): The User= directive in the service file.restart_policy (string, optional, default always): The Restart= directive. Valid values: no, always, on-success, on-failure, on-abnormal, on-watchdog, on-abort.after (string, optional, default network.target): The After= directive.compile_flags (string, optional, default -Wall): Flags passed to gcc.Create a minimal sample daemon at /app/src/myapp.c that:
When executed (bash /app/build.sh):
/app/service_config.json./app/build/ directory if it does not exist.source_file using gcc with the flags from compile_flags. Output the binary to /app/build/<service_name>./app/build/<service_name>.service./app/build/install.sh.0 on success, non-zero on any failure (e.g., missing config, compilation error).The generated /app/build/<service_name>.service must follow this exact structure:
[Unit]
Description=<description>
After=<after>
[Service]
Type=simple
ExecStart=/usr/local/bin/<service_name>
Restart=<restart_policy>
User=<user>
[Install]
WantedBy=multi-user.target
The generated /app/build/install.sh must:
#!/bin/bash./usr/local/bin/<service_name>./etc/systemd/system/<service_name>.service.systemctl daemon-reload.systemctl enable <service_name>.systemctl start <service_name>.chmod +x)./app/service_config.json does not exist, build.sh must print an error message to stderr and exit with a non-zero code.source_file does not exist, build.sh must print an error message to stderr and exit with a non-zero code.gcc compilation fails, build.sh must exit with a non-zero code.