Description
I just recently found your project and it seems to have a great set of API calls for managing and monitoring units and services. However, after searching around, I can't seem to find any functions that help in the creation of new units and services.
I am working on a program that dynamically creates services for systemd to manager and I am hoping to leverage your API for both monitoring, managing and also creating these units. Currently I create the units via a template:
[Unit]
Description=Transcoding StreamID %%i
[Service]
ExecStart=/bin/echo TEST %1$s/%%i :: Random num: %2$s
User=%1$s
Restart=always
RestartSec=3
StandardOutput=journal+console
StandardError=journal+console
SyslogIdentifier=transcoding_streamid_%%i
[Install]
Alias=transcoding-streamid-%%i
WantedBy=multi-user.target
I use String.format
to create a file called [email protected]
and the %%i
works with the @
aspect of the service unit.
Then I run this command to enable it and fire it up:
new ProcessBuilder()
.command("sudo", "systemctl", "enable", "--now", serviceFile.getPath())
.redirectErrorStream(true)
.start();
I have various other code to read the stdout/stderr and also check the exit value, ensuring it returns 0. All that said, is there functionality in your system to create and register services?
If not, I may be interested in extending this ability into your API (if time allows). Do you have a thought on where it would be best to implement this ability? Would you recommend sub classing and/or implementing any particular interfaces in your code to make this happen properly?