I have a Java app - although the answer here should be the same regardless of whether it is Java, Ruby, Python, etc. - that I would like to distribute in such a way that when devops folk go to install it, it automagically runs as a daemon, with zero config on their side. My inspiration for this comes from the Docker daemon, which is written in Go but that automagically configures itself as a daemon on Ubuntu machines. I want to do the same, but have no clue where to even begin.
I would imagine that either:
deb
; orinit
/systemd
/upstart
/etc. scripts that somehow get installed locally without the end user having to run them. However, in this case, I’m not sure how to select which scripts to install as the user may have any one of several init
-like tools setup.Any ideas?
On Ubuntu (and Debian), creating a deb
package would be the best way to go, as everything can be automated, so that no end-user intervention is needed. The only cases where package installation or upgrades are not automated are if the package has some configuration options that need input from the user (mainly during installation only) or if a configuration file was modified by the user and is also modified by a newer version of the package (during upgrading). In addition, after installing/upgrading a package, any startup scripts it installs are automatically started.
You can have multiple init
scripts be installed, and have everything still work. In the case of systemd
being installed and used on the user's computer, if there is both an init
script and a systemd
script for the same service, then the init
script is ignored and the systemd
script is used.
In terms of the packaging itself, Debian provides helper scripts that (among other things) automatically install any startup scripts you provide (I don't think upstart
is supported by their helper scripts, since this is only used on Ubuntu) and start the service. For an example of the packaging, see this debian
folder for the dump1090-mutability
package. (Disclaimer: this is my Github account) Note that the dump1090-mutability.init
file contains the init
script while the dump1090-mutability.service
file contains the systemd
script. Note that the names of these files should be package-name.init
and package-name.service
, where package-name
is the name of the binary package being created. (See man dh_systemd_enable
and man dh_systemd_start
for the systemd case.)
On packaging, both of these files are placed in the appropriate directories on the user's system, and the service is then started. For the rules
file, I recommend that you have something like the following, so that you benefit from the automation (see this for the --with systemd
part):
#!/usr/bin/make -f
%:
dh $@ --with systemd
override_dh_auto_build:
# Specify how to build the Java files here, if there is no Makefile provided
override_dh_auto_install:
# Specify how to install the Java files here, if there is no `install` target in the Makefile. Don't worry about anything in the `debian` directory unless you need to install some icons.
override_dh_auto_build
(where the source files are compiled and packaged into a JAR) and override_dh_auto_install
(where the JAR is installed).install
target, remove the override_dh_auto_build
target and fill out override_dh_auto_install
.install
target (that can be used), remove both targets.override_dh_auto_build
, and fill out override_dh_auto_install
.Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments