[RHEL7] systemd unit specifiers (e.g. %p) are not expanded for Exec* properties

Solution Verified - Updated -

Issue

  • When creating a custom instantiated unit and specifying a specifier in the program in the Exec* properties, systemd fails to start the unit, as shown in the example below

    • Custom unit file /etc/systemd/system/myunit@.service

      [Unit]
      Description=My unit instance %I
      [Service]
      Type=oneshot
      ExecStart=/usr/local/bin/myunit_%I
      
    • Custom program /usr/local/bin/myunit_instance

      #!/bin/bash
      echo "This is $(basename $0)"
      
    • Execution is failing

      # systemctl daemon-reload
      # systemctl start myunit@instance
      Job for myunit@instance.service failed because the control process exited with error code. [...]
      # systemctl status myunit@instance
      ● myunit@instance.service - My unit instance instance
         Loaded: loaded (/etc/systemd/system/myunit@.service; static; vendor preset: disabled)
         Active: failed (Result: exit-code) since Fri 2019-01-11 09:35:24 CET; 5s ago
        Process: 6484 ExecStart=/usr/local/bin/myunit_%I (code=exited, status=203/EXEC)
       Main PID: 6484 (code=exited, status=203/EXEC)
      
      XXX systemd[1]: Starting My unit instance instance...
      XXX systemd[1]: myunit@instance.service: main process exited, code=exited, st...EXEC
      XXX systemd[1]: Failed to start My unit instance instance.
      [...]
      

      As we can see in the example above, systemd tried to execute /usr/local/bin/myunit_%I which doesn't exist.

  • When creating a custom instantiated unit and specifying a specifier for other properties or other arguments of the Exec* properties, there is no issue, as shown in the example below

    • Custom unit file /etc/systemd/system/myunit_ok@.service

      [Unit]
      Description=My unit instance %I
      [Service]
      Type=oneshot
      ExecStart=/usr/local/bin/myunit %I
      

      In the example above, the %I specifier is not used as the executable name, but as an argument to the /usr/local/bin/myunit program.

    • Custom program /usr/local/bin/myunit

      #!/bin/bash
      echo "This is $(basename $0), called with argument '$1'"
      
    • Execution is a success

      # systemctl daemon-reload
      # systemctl start myunit_ok@instance
      # systemctl status myunit_ok@instance
      ● myunit_ok@instance.service - My unit instance instance
         Loaded: loaded (/etc/systemd/system/myunit_ok@.service; static; vendor preset: disabled)
         Active: inactive (dead)
      
      XXX systemd[1]: Starting My unit instance instance...
      XXX myunit[6871]: This is myunit, called with argument 'instance'
      XXX systemd[1]: Started My unit instance instance.
      

Environment

  • Red Hat Enterprise Linux (RHEL) 7
    • systemd

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content