Hi Everyone,<br><br>Please find my third report below.<br><br><br>Third Report<br>==========<br><br>Project - Sys-V init file creator from systemd service files<br>==========================================<br><br>Status of the project so far :<br>



============================<br>
<br>In the last fortnight, I mostly worked on the conversion logic to convert the options available under the [Unit] and [Service] section of a systemd service configuration file. I went through the man pages of the systemd 'Unit' section[0] and 'Service' section[1] and had look at all the available options. Then option by option, I went about converting them to SysV init format (or bash commands). Here is a list of important options (section-wise) with a short description and their corresponding conversion logic which were done in the past few days : <br>




<br>Note : Now, in order to generate generic and widely accepted scripts, I decided to follow the LSB convention[2] as much as possible. This idea was discussed with the mentors and it results in the generated Sys-V files being shorter and more compact and easy to manage. There was also certain doubts I had with regard to LSB compliance which I discussed with the mentors and managed to clear. <br>




<br>--------------------<br>[Unit] Section <br>--------------------<br><br>The options under this section are mostly used to generate the LSB header in the created Sys-V init file. The main goal is to translate all the requires and dependencies properly into the LSB header. Obtaining a correct LSB header is very important because the order in which the Sys-V init scripts are run by the init system is encoded in the LSB header. Options with their conversion logic : <br>




<br><br>REQUIRES : This option is to configure the requirement dependencies on other services. This is a hard dependency. Even if any one of the services listed under this option fails for some reason, the whole transaction is considered failed.<br>




Conversion : This option maps directly to the Required-Start keyword of the LSB header.<br><br><br>WANTS : This is a weaker version of Requires. Even if any one of the services listed under this option fails for some reason, the whole transaction is not considered failed.<br>




Conversion : This option maps directly to the Should-Start keyword of the LSB header.<br><br><br>REQUIRESOVERRIDABLE :  If executed during system start-up then this is similar to the Requires option. If it is run by a user (using systemctl) then its behaviour is like Wants option.<br>




Conversion : Follows the same as Requires/Wants.<br><br><br>REQUISITE : Similar as Requires, but the services listed under this option must be up else the transaction fails. Whereas in Requires, the services listed would be started if they are not up.<br>




Conversion : This option maps to Required-Start keyword and we have a script for checking whether the listed services are up or not. We abort in case the check fails.<br><br><br>CONFLICTS : The services listed here will be stopped if the this service is started.<br>




Conversion : Script for checking and stopping the services listed  and we use the standard killproc() and start-stop-daemon() defined in the /lib/lsb/init-functions to achieve that .<br><br><br>BEFORE, AFTER : These options configure the ordering dependencies between the services.<br>




Conversion : These map to the Required-Start keyword.<br><br>These are the main options under the [Unit] section. There are other options too like OnFailure, OnFailureIsolate etc. but these options are related to the service monitoring feature of systemd and are not useful for the generation of Sys-V init scripts.<br>




<br><br>-------------------------<br>[Service] Section<br>-------------------------<br><br>The service specific configuration options are configured in the [Service] section. This section carries information about the service and the process it supervises.<br>




List of options with short description and possible conversion logic :-<br><br>PIDFile : Takes an absolute filename pointing to the PID file of the service.<br>Conversion : Define an environment variable $pidfile (or any other name) in the sysV script.<br>




<br><br>GuessMainPID : Takes a boolean value that specifies whether systemd should try to guess the main PID of a service.Usually ignored if explicitly configured PID file is known.<br>Conversion : We use the pidofproc() method defined in the standard /lib/lsb/init-functions to get the PID if the PID file is not known explicitly.<br>




<br><br>ExecStart : Takes a command line that is executed when this service shall be started up. It is mandatory that each service file has this option.<br>Conversion : Using the start_daemon() method defined in the standard /lib/lsb/init-functions to execute the argument provided with ExecStart Option.<br>



<br>
<br>ExecStartPre/Post : Additional commands that are executed before/after the command in ExecStart option.<br>Conversion : Script to save all the commands in a list and then execute them using the start_daemon() method.<br>



<br>
<br>ExecStop : Takes commands to execute to stop the service started via ExecStart option. This option is not mandatory.<br>Conversion :  If the option is present, then simply execute the command listed there. The problem comes when this option is not present. In such a case, I identify the executable path from the ExecStart option and use killproc() method in the standard /lib/lsb/init-functions to kill the job.<br>




<br> <br>Future Plans :<br>===========<br><br>There are still some options left in the [Service] section for which I need to design the conversion logic. This week I intend to have a look at the options available in the [Install] section and designing a conversion logic for them. The code is present in my git repository[3]. The main aim is to finish the major options present in the [Service] and [Install] section and have a initial version of the conversion tool ready before the mid-term evaluations (before 9th july). The testing will go on parallely with major debian systemd service configuration files.<br>




<br><br><br>[0] : <a href="http://0pointer.de/public/systemd-man/systemd.unit.html" target="_blank">http://0pointer.de/public/systemd-man/systemd.unit.html</a><br>[1] : <a href="http://0pointer.de/public/systemd-man/systemd.service.html" target="_blank">http://0pointer.de/public/systemd-man/systemd.service.html</a><br>




[2] : <a href="http://refspecs.linux-foundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/tocsysinit.html" target="_blank">http://refspecs.linux-foundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/tocsysinit.html</a><br>



[3] : <a href="https://github.com/akhilvij/systemd-to-sysvinit-converter" target="_blank">https://github.com/akhilvij/systemd-to-sysvinit-converter</a><br> 
<br><br>Kind Regards,<br>Akhil Vij<br>