How to make an app run as a daemon on Ubuntu when installed?

smeeb

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:

  • I need to somehow package my app inside a deb; or
  • Ship my app executable with necessary init/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?

saiarcot895

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.
  • If your app doesn't have a Makefile and is just a collection of Java source files, fill out 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).
  • If your app has a Makefile, but doesn't have an install target, remove the override_dh_auto_build target and fill out override_dh_auto_install.
  • If your app has a Makefile and it has an install target (that can be used), remove both targets.
  • If your app is just a JAR file, remove override_dh_auto_build, and fill out override_dh_auto_install.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make an app run as a daemon on Ubuntu when installed?

From Dev

How to view the packages/tools that will be installed by Ubuntu Make?

From Dev

How to make the ScheduledTaskAgent start as soon as the app is installed?

From Dev

is this possible to make mobile app that run on web? and can be installed on mobile too?

From Dev

How to run jqAssistant as a daemon

From Dev

How can I run the emacs daemon only when needed?

From Dev

How to run a daemon only when a specific application is running?

From Dev

First time app run action depending on how app was installed (Android)

From Dev

First time app run action depending on how app was installed (iOS)

From Dev

How to make a timer app that could run even when the app is in the background mode

From Dev

How to make the unity app search find a manually installed app

From Dev

Are dependencies installed when I install an app from Ubuntu Software?

From Dev

How to run Scilab 5.5.2 on Ubuntu 16.04 LTS with all updates installed?

From Dev

How to config apache (installed in server) to run a web app (django) in docker?

From Dev

How do i run a mysql app without mysql connector installed?

From Dev

How to config apache (installed in server) to run a web app (django) in docker?

From Dev

Daemon service app unable to bind port when run through php exec

From Dev

How to run python program as a daemon?

From Dev

How to run python program as a daemon?

From Dev

How to run Dropbox daemon in background?

From Dev

How to run gunicorn as systemd daemon

From Dev

How to run Spark Application as daemon

From Dev

How to make everything run as root in ubuntu?

From Dev

How to make Ubuntu 14.04 run with less lag?

From Dev

How to make ubuntu service run as specific user

From Dev

How can I make my framework's code automatically run when the app launches?

From Dev

How to make the Web Bluetooth Pair button work when run as chrome app

From Dev

How to make an android app to always run in background?

From Dev

how to make a sinatra app run in rails 4?

Related Related

  1. 1

    How to make an app run as a daemon on Ubuntu when installed?

  2. 2

    How to view the packages/tools that will be installed by Ubuntu Make?

  3. 3

    How to make the ScheduledTaskAgent start as soon as the app is installed?

  4. 4

    is this possible to make mobile app that run on web? and can be installed on mobile too?

  5. 5

    How to run jqAssistant as a daemon

  6. 6

    How can I run the emacs daemon only when needed?

  7. 7

    How to run a daemon only when a specific application is running?

  8. 8

    First time app run action depending on how app was installed (Android)

  9. 9

    First time app run action depending on how app was installed (iOS)

  10. 10

    How to make a timer app that could run even when the app is in the background mode

  11. 11

    How to make the unity app search find a manually installed app

  12. 12

    Are dependencies installed when I install an app from Ubuntu Software?

  13. 13

    How to run Scilab 5.5.2 on Ubuntu 16.04 LTS with all updates installed?

  14. 14

    How to config apache (installed in server) to run a web app (django) in docker?

  15. 15

    How do i run a mysql app without mysql connector installed?

  16. 16

    How to config apache (installed in server) to run a web app (django) in docker?

  17. 17

    Daemon service app unable to bind port when run through php exec

  18. 18

    How to run python program as a daemon?

  19. 19

    How to run python program as a daemon?

  20. 20

    How to run Dropbox daemon in background?

  21. 21

    How to run gunicorn as systemd daemon

  22. 22

    How to run Spark Application as daemon

  23. 23

    How to make everything run as root in ubuntu?

  24. 24

    How to make Ubuntu 14.04 run with less lag?

  25. 25

    How to make ubuntu service run as specific user

  26. 26

    How can I make my framework's code automatically run when the app launches?

  27. 27

    How to make the Web Bluetooth Pair button work when run as chrome app

  28. 28

    How to make an android app to always run in background?

  29. 29

    how to make a sinatra app run in rails 4?

HotTag

Archive