- Edited
Although I have already written quite some customized services in the past I feel there's a lack of guides on how to efficiently write the @ execute field in the frontend file of a custom service.
This is apparently due to the fact that this field needs to be written in the s6 format of execline script. This is easy for one liners but how about a service where I want to test for two or more things to be existent in the system and only afterwards fire several commands? What are my choices? What would be best practice?
Requirements
Approaches
VMware Workstation needs a few modules loaded and command lines to be executed to have USB hand-over, networking etc. working.
This is rather simple and quickly done from the shell but apparently services are meant to automate this for me. The requirements and steps are as follows:
This is apparently due to the fact that this field needs to be written in the s6 format of execline script. This is easy for one liners but how about a service where I want to test for two or more things to be existent in the system and only afterwards fire several commands? What are my choices? What would be best practice?
Requirements
- Check for requirements of the service, can include more than only one command
- If a requirement is not met then try to satisfy it
- Once that is done execute several commands for the service itself
- If anything goes wrong echo an error message to the boot log and prevent stalling of the boot process
Approaches
- Ignore the requirements and make one service file for each command. Highly ineffective and unnecessarily complex. Creates service clutter.
- Check the requirements in one service file and execute anything necessary, make separate services for the commands and make them depend on the first. The developer approach, overly complex and unnecessarily overthought. Creates flexibility and service clutter.
- Check the requirements and fire all commands in the same service file. The lazy user approach. Highly cringed upon by any developer. Complex but effective and useful in everyday use. Reduces flexibility and service clutter.
VMware Workstation needs a few modules loaded and command lines to be executed to have USB hand-over, networking etc. working.
This is rather simple and quickly done from the shell but apparently services are meant to automate this for me. The requirements and steps are as follows:
- Have the following kernel modules loaded: vmmon vmnet vmw_vmci
- For networking: ’vmware-networks --postinstall vmware-workstation,0,1’ and then ’vmware-networks --start’
- For USB hand-over: ’vmware-usbarbitrator’
[main]
@ type = oneshot
@ name = vmware
@ description = "starts vmware modules"
@ user = ( root )
[start]
@ build = auto
@ execute =
(
if { modprobe vmw_vmci }
if { modprobe vmmon }
if { modprobe vmnet }
if { vmware-networks --postinstall vmware-workstation,0,1 }
if { vmware-networks --start }
vmware-usbarbitrator
)
This misses any fail-safe approach though and logging is also not thought of. What's your approach in such a situation?