3

I'm learning how to create a .deb file using jdeb in order to deliver a maven based java headless application inside debian based distributions.

It needs to be installed in such a way it auto start at boot time.

In the examples that I found in web jdeb is being set with a data directory containing a init.d file.

 <data>
     <src>${project.basedir}/src/deb/init.d/</src>
     <type>directory</type>
     <mapper>
         <type>perm</type>
         <prefix>/etc/init.d</prefix>
         <filemode>755</filemode>
         <user>root</user>
         <group>root</group>
     </mapper>
   </data>

But how can I deal with different init systems? should I set a data tag for systemd, sysvinit and upstart all together?

thank for any insight.

1 Answer 1

2

There is no magic in such a case. You can't use a Debian package's static copy to install both the systemd and sysV files because this will duplicate services.

So, the solution I found was to deliver the configuration files as normal files inside the deb file, and then to implement a routine inside the postinst / postrm scripts that identifies which init system the target machine is running and then copy the right file to the proper directory.

if [[ `systemctl` =~ -\.mount ]] 
then 
  cp $serviceDir/service-systemd /lib/systemd/system/$serviceName.service
elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]
then 
cp $serviceDir/service-sysvinit /etc/init.d/$serviceName
fi
2
  • Thanks Cristiano for your own feedback, is it possible to gist your files somewhere. I am interested in also because I am developing for Raspberry. ;-)
    – Thomas
    Dec 4, 2017 at 8:37
  • @Thomas, I left the company where I needed to do this, but I will search in my backups soon... Let you know if I found them...
    – Cristiano
    Dec 6, 2017 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.