Coder Social home page Coder Social logo

lein-init-script's Introduction

lein-init-script

A leiningen plugin that generates *NIX init scripts. Alpha quality, verified working on OSX 10.6 and FC12.

In a nutshell, LSI generates the following artifacts which can be found in your /init-script dir:

  • Project Uberjar

  • d script

    Paired down from the Fedora Core init script template, injected with values from your lein project.clj.


  • install- script

    Creates (but does not overwrite) the :pid-dir, :install-dir, and :init-script-dir directories. To override the defaults see the Configuration section below.


  • clean- script

    Removes the init script, and uberjar from their respective install paths. Does not remove any created directories.


If you have an feature suggestions / bug reports, please open up an issue

Why?

Because it was too damn time-consuming to turn a java program into a *nix daemon service that can be started / stopped asyncronously, chkconfig'd, etc.

Lein

Add [leiningen-init-script "1.2.0-SNAPSHOT"] to the :dev-dependencies section in your project.clj.

Configuration

leiningen-init-script takes several options in the form of:

{:name "override-project-name"
 :pid-dir "/var/run"
 :install-dir "/usr/local/my-project-name"
 :init-script-dir "/etc/init.d"
 :redirect-output-to "/log/file or /dev/null"
 :properties {:clj-config.env "dev"
			  :java.library.path "/some/dir"
			  :init.script.test.prop "prop with spaces"}
 :jvm-opts ["-server"
			 "-Xms256M"
			 "-Xmx512M"
			 "-XX:MaxPermSize=128M"]}

which are passed to the the init-script task by adding a :lis-opts entry to the project map. For example:

(defproject init-script-test "0.1.0"
  :description "Test project for leiningen-init-script"
  :dependencies [[org.clojure/clojure "1.1.0"]
                 [org.clojure/clojure-contrib "1.1.0"]]
  :dev-dependencies [[leiningen-init-script "1.2.0-SNAPSHOT"]]
  :lis-opts {:redirect-output-to "/var/log/init-script-test.log"
             :properties {:clj-config.env "dev"
			  			  :java.library.path "/some/dir"
			  			  :init.script.test.prop "prop with spaces"}
	         :jvm-opts ["-server"
						 "-Xms256M"
			 			 "-Xmx512M"
			 			 "-XX:MaxPermSize=128M"]}
  :main main)

Usage

Short Version

Create a main class for your project, run lein init-script, and check the ./init-script directory.

Long Version

Taken from the init-script-test project.

Clone the init-script-test repo

git clone git://github.com/zkim/init-script-test.git

cd into the cloned repo directory

cd init-script-test</code>

Download dependencies

lein deps

Run the init-script task

lein init-script

Your output should look something like:

Created /Users/zkim/tmp/init-script-test/init-script-test.jar
Including init-script-test.jar
Including clojure-1.1.0.jar
Including clojure-contrib-1.1.0.jar
Including leiningen-init-script-0.1.0.jar
*** Done generating init scripts, see the /Users/zkim/tmp/init-script-test/init-script/ directory
napple:init-script-test zkim$

cd into the init-script directory cd ./init-script

Make install-init-script-test, clean-init-script-test runnable chmod u+x ./install-init-script-test chmod u+x ./clean-init-script-test

Install init script and jar sudo ./install-init-script-test

leiningen-init-script installs the jar to /usr/local/ and the init script to /etc/init.d. These defaults can be changed, see the Configuration section of the leiningen-init-script README

Start the daemon service sudo /etc/init.d/init-script-testd start

Verify the jar is running ps -e

Output:

44678 ttys003    0:00.01 login -pf zkim
44679 ttys003    0:00.11 -bash
45216 ttys003    0:01.28 /usr/bin/java -jar /usr/local/init-script-test/init-script-test-standalone.jar
45225 ttys003    0:00.00 ps -e

Stop the daemon service and verify the process has stopped sudo /etc/init.d/init-script-testd stop

ps -e

44198 ttys002    0:00.09 -bash
44678 ttys003    0:00.01 login -pf zkim
44679 ttys003    0:00.11 -bash
45248 ttys003    0:00.00 ps -e

Limitations

No Windows support at this time, if you'd like to see support for windows services, please open up an issue.

License

Eclipse Public License v1.0

lein-init-script's People

Contributors

strongh avatar zk avatar

Watchers

 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.