Systemd.unit - Add option for instance translation script.
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 16.7k
- Forks
- 4.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 140
Description
Submission type
- Request for enhancement (RFE)
systemd version the issue has been seen with
237.31-1
Used distribution
ArchLinux
Situation / use case
I have a systemd service template homie@.service that is being isntantiated using a unique customer ID.
Thus I can view the respective customer's service's logs using journalctl -au homie@<customer_id>.service.
The service unit may be triggered periodically using a systemd.timer named homie@.timer, that is instantiated in the same fashion (customer ID).
However, the service needs also be capable to be triggered by file uploads. Hence I created a systemd.path named homie@.path.
Since the paths to be monitored vary for each customer (but are unique for each customer), I instantiate the respective path unit with the path to monitor:
[Unit]
Description=Inotify trigger for HOMIE service for path %I
[Path]
PathChanged=%I
[Install]
WantedBy=multi-user.target
Obviously the respective service will now be passed the path, instead of the customer ID.
While I could just accept this behaviour and translate the path to the respective ID within the binary called in homie@.service's ExecStart=…, I then will have to check two logs for each customer: homie@<customer_id>.service and homie@<upload_path>.service.
Hence, it would be nice to add a feature to translate instance IDs within units by e.g. allowing to invoke a script InstanceTranslator=….
The provided script / binary would be expected to receive the unescaped instance as an argument and return the translated instance on STDOUT.
A non-zero exit code could indicate the failure of ID translation and cause the unit to fail.
On success, all %T (Translated instance, new) placeholders should be replaced by the translated ID:
[Unit]
Description=Inotify trigger for HOMIE service for path %I
[Path]
PathChanged=%I
InstanceTranslator=/usr/local/bin/path_to_id.sh
Unit=homie@%T.service
[Install]
WantedBy=multi-user.target
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the systemd.unit and systemd.path instance-handling areas described in the request, including how %I and Unit= are currently processed. Determine the design and tests needed for InstanceTranslator, translated %T expansion, and non-zero translation failures; done means the proposed path-triggered unit resolves to the customer-specific service.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, linux
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100