VMware Cloud Community
AnonymousDefaul
Enthusiast
Enthusiast

<addUnixService> in systemd

 Since SystemV style of service has been replaced by systemd, but <addUnixSerive> still only support  SystemV style. It will lead to a series of incompatible issues.



 SystemV: add init script in /etc/init.d/xxx


 systemd: add configure file in /use/lib/systemd/system/xxx.service



Will you consider supporting systemd in the interface?

Labels (1)
2 Replies
flexit_analytic
Contributor
Contributor

Is there any update on this question? It seems like it should be a high priority fix.

0 Kudos
gongomgra
VMware Employee
VMware Employee

Hello,

Thanks for your message. Fully native support for systemd services is on our roadmap but still not implemented. However, as systemd is backwards compatible with SystemV, you can still use the addUnixService action and add the appropriate header in your initialization script. Please take a look at the next references about this

https://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/initscrcomconv.html

https://wiki.debian.org/LSBInitScripts

It would be something similar to the next snippet

----------

### BEGIN INIT INFO

# Provides: <your service name>

# Required-Start: <any services your service may depend on, e.g. networking>

# Required-Stop: <list of services that should be stopped only after your service is stopped>

# Default-Start: 2 3 5

# Default-Stop: 0 1 6

# Short-Description: <a short description of your service>

# Description: <your service description>

### END INIT INFO

----------

Another option would be to use the below snippet that creates a systemd .service file to run the init.d script if systemd is present, falling back to addUnixService action:

----------

<if>

  <actionList>

    <writeFile>

      <path>/etc/systemd/system/${serviceName}.service</path>

      <text>[Unit]

SourcePath=${installdir}/${serviceName}

Description=LSB: ${serviceName} init script

Before=shutdown.target

After=network-online.target

Wants=network-online.target

Conflicts=shutdown.target

[Service]

Type=forking

Restart=no

TimeoutSec=30min

IgnoreSIGPIPE=no

KillMode=process

GuessMainPID=no

RemainAfterExit=yes

SysVStartPriority=1

ExecStart=${installdir}/${serviceName} start

ExecStop=${installdir}/${serviceName} stop# Output needs to appear in instance console output

StandardOutput=journal+console

[Install]

WantedBy=multi-user.target</text>

    </writeFile>

  </actionList>

  <conditionRuleList>

    <fileTest>

      <condition>exists</condition>

      <path>/etc/systemd/system</path>

    </fileTest>

    <fileTest>

      <condition>is_directory</condition>

      <path>/etc/systemd/system</path>

    </fileTest>

  </conditionRuleList>

  <elseActionList>

    <addUnixService>

      <description>Product description</description>

      <name>${product_shortname}</name>

      <program>${installdir}/${serivceName}</program>

    </addUnixService>

  </elseActionList>

</if>

----------