[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[GSoC Report] Week 8, 9 & 10 - Systemd Unit Translator



Hello, everyone!

I realize I'm unusually late for submission of this month's weekly reports. I
haven't been doing well mentally over the past month. So I apologize for my late
submission of this report. This report covers the work done in the entirety of
August.

STATS:

  Services:
    Total: 72
    Success: 72
    Failure: 0

    Ratio: 1.00

  Sockets:
    Total: 6
    Success: 5
    Failure: 1

    Ratio: 0.83

  Timers:
    Total: 6
    Success: 6
    Failure: 0

    Ratio: 1.00

WORK DONE:

  Last month's report laid out the following things to be done:

    - Make a repository in Debian's salsa
      [DONE][https://salsa.debian.org/kayg/systemd-unit-translator]

      This repository[https://salsa.debian.org/kayg/systemd-unit-translator] is
      also the primary tracking point of the project with a mirror on gitlab.com
      [https://gitlab.com/kayg-works/intern/gsoc-2020/systemd-unit-translator].
      My instance of Gitea [https://git.kayg.org/gsoc-2020] is being deprecated
      in favour of gitlab.com.

    - Fix remaining service files where translation fails [DONE]

      After this month's work which is explained below, all services work after
      translation. Of course, this excludes the services which have explicit
      systemd dependencies.

    - Finish up on documentation and the manual [DONE]

      The manual is available in the repository. Comments through the script
      (and the modules) explain what each function does. A better explanation is
      always possible. Any suggestions are welcome.

  SERVICES:

    According to Benda's instructions, services were the priority and hence they
    were paid the most attention.

    - Instead of having separate functions for exec_events such as
      `Exec{Stop,Start,StartPre,StopPre,StartPost,StopPost,Reload}`, a generic
      function `gen_openrc_script_exec_event` has been defined which takes
      `--$event` as the first argument and the actual command in the $event as
      the second argument. Thereafter, respective variables and / or functions
      are generated through a switch-case match.

    - Make all exec_events optional. The translator no longer throws an error
      when one of the event types is missing.

    - Fixed a bug where with some services, the executable path will end up in
      both $command and $command_args.

    - PIDFiles are no longer created unless the systemd service has a PIDFile
      directive.

    - If services prefer to run as a specific user in a specific group, now the
      translator is capable of handling that with $command_user.

    - More explanation has been added to parts where the code relies on regex.

    - A usage() function has been added which gets called when the script is
      executed with no arguments. Currently supports `-h` or `--help` as options
      which open the manpage.

    - Instead of having a separate file and a symbolic link, the repository now
      contains only one file.

    - Since one of the goals in making this project is making it have as few
      external dependencies as possible, an overhaul of the `parser.sh` file has
      been done to remove reliance on `sed`, `grep` and `awk`.

      Everything is now done through bash's native filtering and
      substitution. This also makes the code (related to filtering) much easier
      to read. The mechanism is simple:

        - The script reads the whole file, line by line, in a while block
          through input redirection.

        - Until $start is set to 1, the filtering does not start.

        - $start is set to 1 when the current line matches the required section
          (Unit, Service, Socket, Timer, Install)

        - Once $start is set to 1, all lines beginning with # are skipped. Lines
          which have the character '=' are filtered.

        - This process continues until either another '[$type]' is encountered,
          in which case it breaks, or until the file itself ends.

      The script only has one call to `grep` in `timer.sh` which will be removed
      in the future.

    - Support has also been added for instantiated services -- services which
      require an argument to start. Examples are: clean-mount-point@,
      wpa_supplicant@. All of these services work with an argument, which is
      similar to `agetty` in OpenRC which works on specified ports: tty{1,2,3}

      A start_pre() function is added for any *instantiated* service which does
      not have a ExecStartPre key to check if a symbolic link (an instance) has
      been made before the script start-up. This is done by defining an
      $instance variable which has the value "${RC_SVCNAME#*.}" which removes
      the shortest match before '.' is found.

      For instantiated services having an ExecStartPre, the check block gets
      inserted before the exec command.

      The '@' character is replaced to '.' in the resulting file to stay in line
      with OpenRC lingo.

A Google Summer of Code 2020 submission report / post is being drafted in the
repository's wiki which lists out the thought-process and ideas involved while
making this project. It will also contain a list of what could and could not be
done during this timeline.

That's all for the coding period!

Here are few ideas for the future:

FUTURE:

  As Benda pointed out, this project needs a real parser instead of the current
  reliance on regular expressions for timer units. Calendar event expressions
  are rather cumbersome and complicated to filter through regular expressions.

  A continous integration pipeline which spawns a docker container and performs
  required checks through all services, timers and sockets installed on the
  latest debian stable.

  A better name? `systemd-unit-translator` feels too long.


Warmest regards,
K Gopal Krishna
(https://kayg.org/)


Reply to: