Skip to content

Commit

Permalink
add unitfile for ncm-cdispd
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird committed Mar 18, 2024
1 parent 7b7aa95 commit 2eeea23
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 11 deletions.
102 changes: 91 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@
<filemode>755</filemode>
<directoryIncluded>false</directoryIncluded>
</mapping>
<mapping>
<sources>
<source>
<location>${project.build.directory}/systemd/${project.artifactId}.service</location>
</source>
</sources>
<directory>/usr/lib/systemd/system</directory>
<filemode>644</filemode>
<directoryIncluded>false</directoryIncluded>
</mapping>
<mapping>
<sources>
<source>
<location>${project.build.directory}/systemd/80-${project.artifactId}.preset</location>
</source>
</sources>
<directory>/usr/lib/systemd/system-preset</directory>
<filemode>644</filemode>
<directoryIncluded>false</directoryIncluded>
</mapping>
<mapping>
<directory>/usr/sbin</directory>
<filemode>755</filemode>
Expand Down Expand Up @@ -168,23 +188,63 @@
</sources>
</mapping>
</mappings>
<preinstallScriptlet>
<script><![CDATA[
if [ "$1" -eq 2 ]; then # upgrade
if [ -x /bin/systemctl -a -h /etc/rc3.d/S30${project.artifactId} ]; then
# Upgrade from the initscript version. The daemon needs to be
# stopped, otherwise, systemd gets confused
/sbin/service ${project.artifactId} stop > /dev/null 2>&1 || :
/sbin/chkconfig --del ${project.artifactId}
fi
fi
]]></script>
</preinstallScriptlet>
<postinstallScriptlet>
<script>
/sbin/chkconfig --add ${project.artifactId}
<script><![CDATA[
if [ "$1" -eq 1 ]; then # first install
if [ -x /bin/systemctl ]; then
/bin/systemctl preset ${project.artifactId}.service > /dev/null 2>&1 || :
else
/sbin/chkconfig --add ${project.artifactId}
fi
elif [ "$1" -eq 2 ]; then # upgrade
# Ensure that profile has been updated to the last format, if any change, to prevent potential ncm-cdispd crash at restart
ccm-fetch --force
/sbin/service ${project.artifactId} restart
</script>
if [ -x /bin/systemctl ]; then
/bin/systemctl daemon-reload > /dev/null 2>&1 || :
# Calling 'preset' here is arguably wrong, but not doing it could leave
# the daemon disabled when upgrading from the init script version
/bin/systemctl preset ${project.artifactId}.service > /dev/null 2>&1 || :
/bin/systemctl restart ${project.artifactId} > /dev/null 2>&1 || :
else
/sbin/chkconfig --add ${project.artifactId}
/sbin/service ${project.artifactId} restart > /dev/null 2>&1 || :
fi
fi
]]></script>
</postinstallScriptlet>
<preremoveScriptlet>
<script>
if [ "$1" -eq 0 ] # Uninstall rather than upgrade
then
# Do not stop the service as the uninstall may happen from within the service...
/sbin/chkconfig --del ${project.artifactId}
fi
</script>
<script><![CDATA[
if [ "$1" -eq 0 ]; then # Uninstall rather than upgrade
# Do not stop the service as the uninstall may happen from within the service...
if [ -x /bin/systemctl ]; then
/bin/systemctl --no-reload disable ${project.artifactId}.service > /dev/null 2>&1 || :
else
/sbin/chkconfig --del ${project.artifactId}
fi
fi
]]></script>
</preremoveScriptlet>
<postremoveScriptlet>
<script><![CDATA[
if [ -x /bin/systemctl ]; then
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
fi
]]></script>
</postremoveScriptlet>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -350,6 +410,26 @@
</resources>
</configuration>
</execution>
<execution>
<id>copy-systemd-files</id>
<phase>process-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/systemd</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/systemd</directory>
<includes>
<include>${project.artifactId}.service</include>
<include>80-${project.artifactId}.preset</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/systemd/80-ncm-cdispd.preset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable ncm-cdispd.service
14 changes: 14 additions & 0 deletions src/main/resources/systemd/ncm-cdispd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Configuration Dispatch Daemon waits for new incoming configuration profiles
After=network.target
After=network-online.target
Before=shutdown.target

[Service]
Type=simple
ExecStart=/usr/sbin/ncm-cdispd
KillMode=process
PIDFile=/var/run/ncm-cdispd.pid

[Install]
WantedBy=multi-user.target

0 comments on commit 2eeea23

Please sign in to comment.