A caplet that runs a Java capsule as a Unix service through jsvc and as a Windows service through procrun.
NOTE: currently capsule-daemon doesn't support Application-Script capsules.
In addition to Capsule's, only if the platform is not Windows, Linux 64 bit nor Mac OS X then jsvc must be correctly installed locally.
The Gradle-style dependency you need to embed in your Capsule JAR, which you can generate with the tool you prefer (f.e. with plain Maven/Gradle as in Photon and capsule-gui-demo or higher-level Capsule build plugins), is co.paralleluniverse:capsule-daemon:0.2.0. Also include the caplet class in your Capsule manifest, for example:
Caplets: MavenCapsule DaemonCapsulecapsule-daemon can also be run as a wrapper capsule without embedding it:
$ java -Dcapsule.log=verbose -jar capsule-daemon-0.2.0.jar my-capsule.jar my-capsule-arg1 ...It can be both run against (or embedded in) plain (e.g. "fat") capsules and Maven-based ones.
The following additional manifest entries and system properties can be used to customize capsule-daemon's behaviour (see the jsvc docs and the procrun docs for further details):
- Both Unix and Windows:
- Manifest entries:
Daemon-Start-Class: class containing thestartmethod (default: app's main).Daemon-Start-Method: staticString[] -> voidservice start method short name run as the specified, if any (default: app's main).Daemon-Stop-Class: class containing thestopmethod (default: none).Daemon-Stop-Method: staticString[] -> voidservice stop method short name run as the specified, if any (default: none).Daemon-User: the username under which the service will run. Thecapsule.daemon.usersystem property can override it.Daemon-Cwd: working directory of start/stop (default:/on Unix). Thecapsule.daemon.cwdsystem property can override it.Daemon-Stdout-File: stdout (default:/dev/nullon Unix,<logpath>/service-stdout.YEAR-MONTH-DAY.logon Windows). Thecapsule.daemon.stdoutFilesystem property can override it.Daemon-Stderr-File: stdout (default:/dev/nullon Unix,<logpath>/service-stderr.YEAR-MONTH-DAY.logon Windows). . Thecapsule.daemon.stderrFilesystem property can override it.Daemon-PID-File: PID file (default:/var/run/<appid>.pidon Unix,<logpath>/<appid>.pidon Windows). Thecapsule.daemon.pidFilesystem property can override it.
- System properties:
capsule.daemon.stop: iftrueor barely present will stop a running service rather than starting one.
- Manifest entries:
- Only Unix:
- System properties:
capsule.daemon.checkOnly:jsvccheck run, won't start the service.capsule.daemon.debug: turn on debugjsvclogging.capsule.daemon.verbose: turn on verbosejsvclogging.capsule.daemon.jsvc: specifies the pathname of a system-installedjsvccommand to be used instead of the one provided bycapsule-daemon.
- Manifest entries:
Init-Class: class containing theinitmethod (default: none).Init-Method: staticString[] -> String[]service initialization method, it will be run asroot; the return value will be passed to theStartmethod (default: none).Destroy-Class: class containing thedestroymethod (default: none).Destroy-Method: staticvoid -> voidcleanup method, it will be run asroot(default: none).No-Detach: don't detach from the parent process. Thecapsule.daemon.noDetachsystem property can override it.Keep-Stdin: don't redirect the standard input to/dev/null. Thecapsule.daemon.keepStdinsystem property can override it.Wait-Secs: Wait seconds for service readiness, must be multiple of 10. Thecapsule.daemon.waitSecssystem property can override it.
- System properties:
- Only Windows
Daemon-Password: the password of the user under which the service will run (default: none). Thecapsule.daemon.passwordsystem property can override it.Daemon-Java-Exec-User: the password of the user that will execute the final Java process (default: none). Thecapsule.daemon.javaExecUsersystem property can override it.Daemon-Java-Exec-Password: the password of the user that will execute the final Java process (default: none). Thecapsule.daemon.javaExecPasswordsystem property can override it.Daemon-Service-Name: the service internal name (default: app ID). Thecapsule.daemon.serviceNamesystem property can override it.Daemon-Display-Name: the service display name (default: app ID). Thecapsule.daemon.displayNamesystem property can override it.Daemon-Description: the service description (default: app ID). Thecapsule.daemon.descriptionsystem property can override it.Daemon-Startup: the service startup mode, eitherautoormanual(default:manual). Thecapsule.daemon.startupsystem property can override it.Daemon-Type: the service type, it can beinteractive(default: none). Thecapsule.daemon.typesystem property can override it.Daemon-DependsOn: the list of service dependencies (default: none). Thecapsule.daemon.dependsOnsystem property can override it.Daemon-Stop-Params: the list of service stop parameters (default: none). Thecapsule.daemon.stopParamssystem property can override it.Daemon-Stop-Timeout: service stop timeout in seconds (default: none). Thecapsule.daemon.stopTimeoutsystem property can override it.Daemon-Log-Path: the log path (default:%SystemRoot%\System32\LogFiles\Apache). Thecapsule.daemon.logPathsystem property can override it.Daemon-Log-Prefix: the log prefix (default: app ID). Thecapsule.daemon.logPrefixsystem property can override it.Daemon-Log-Level: the log level betweenerror,info,warnanddebug(default:info). Thecapsule.daemon.logLevelsystem property can override it.
jsvcwith default settings (due to the default PID file location) andprocrunin any case (for service installation, uninstallation and upgrade) require resp.rootand administrative privileges.- Launch, Java and service execution users must all be able to access the same Capsule's cache directory. You can set it to a commonly accessible location (for example in
/tmp/capsule) through theCAPSULE_CACHE_DIRenvironment variable.
Copyright (c) 2015, Parallel Universe Software Co. and Contributors. All rights reserved.
This program and the accompanying materials are licensed under the terms
of the Eclipse Public License v1.0 as published by the Eclipse Foundation.
http://www.eclipse.org/legal/epl-v10.html