Coder Social home page Coder Social logo

java-daemon's Introduction

java daemon

How to run a Java Program as a daemon on Debian & Ubuntu

Borrowed from:

How to run a Java Program as a daemon (service) on Linux (SUSE/openSUSE) using a shell script http://www.source-code.biz/snippets/java/7.htm

I just adapted it to Debian 7

Changes I made (so far):

  • no external dependancy to other scripts : removed dependancy to rc.status (not existing in Debian)
  • 1 or 2 quickfix (chown was absent, shell variables, checkProcessIsOurService..)
  • replaced sudo by su (why sudo?)
  • I separated the derived variables from the main variables
  • you can uncheck to debug variable to check variables values

Why I did it?

I first used the Apache Jakarta Commons Daemon package (Jsvc) http://jakarta.apache.org/commons/daemon/. The problem is... on prod, after a while it ate 80% CPU. For no reason (because it happens when the program is waiting on inotify events). No time to try to fix this.

(side note: I did not consider the Java Service Wrapper http://wrapper.tanukisoftware.org/: not open source, it will not run on my servers)

Then I was about to write a quick script based on nohup, when I found that one. Perfect. It use 100% shell, and detaches correclty the java process: Great.

I know there exists a standard scripts with Debian, but honestly, I find this one easier to debug/understand than the /etc/init.d/skeleton. start-stop-deamon is far too opaque to me.

Features

The shell script (javaDaemonTest.sh) provides the following functionality:

  • Start/stop the Java daemon process, according to the Linux system init script convention.
  • Run the Java daemon as a different (non-root) Linux user.
  • Log error messages and redirect StdOut/StdErr output into a log file.
  • Install/uninstall the daemon as a Linux service. (The "install" procedure installs the script in /etc/init.d, enables the service in the configured default runlevels, creates the "rc" command (symlink) and creates the Linux user (as a system account) and group if necessary).

Thanks

Thanks to the original Author Christian d'Heureuse for sharing this.

java-daemon's People

Contributors

boussou avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.