A caplet that runs a capsule as a Unix service through jsvc and as a Windows service through procrun.
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.1.0
. Also include the caplet class in your Capsule manifest, for example:
Caplets: MavenCapsule DaemonCapsule
capsule-daemon
can also be run as a wrapper capsule without embedding it:
$ java -Dcapsule.log=verbose -jar capsule-daemon-0.1.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 thestart
method (default: app's main).Daemon-Start-Method
: staticString[] -> void
service start method short name run as the specified, if any (default: app's main).Daemon-Stop-Class
: class containing thestop
method (default: none).Daemon-Stop-Method
: staticString[] -> void
service stop method short name run as the specified, if any (default: none).Daemon-User
: the username under which the service will run.Daemon-Cwd
: working directory of start/stop (default:/ on Unix). The
capsule.daemon.usersystem property can override it. The
capsule.daemon.cwd` system property can override it.Daemon-Stdout-File
: stdout (default:/dev/null
on Unix,<logpath>/service-stdout.YEAR-MONTH-DAY.log
on Windows). Thecapsule.daemon.stdoutFile
system property can override it.Daemon-Stderr-File
: stdout (default:/dev/null
on Unix,<logpath>/service-stderr.YEAR-MONTH-DAY.log
on Windows). . Thecapsule.daemon.stderrFile
system property can override it.Daemon-PID-File
: PID file (default:/var/run/<appid>.pid
on Unix,<logpath>/<appid>.pid
on Windows). Thecapsule.daemon.pidFile
system property can override it.
- Manifest entries:
- Only Unix:
- System properties:
capsule.daemon.checkOnly
:jsvc
check run, won't start the service.capsule.daemon.debug
: turn on debugjsvc
logging.capsule.daemon.verbose
: turn on verbosejsvc
logging.
- Manifest entries:
Init-Class
: class containing theinit
method (default: none).Init-Method
: staticString[] -> String[]
service initialization method, it will be run asroot
; the return value will be passed to theStart
method (default: none).Destroy-Class
: class containing thedestroy
method (default: none).Destroy-Method
: staticvoid -> void
cleanup method, it will be run asroot
(default: none).No-Detach
: don't detach from the parent process. Thecapsule.daemon.noDetach
system property can override it.Keep-Stdin
: don't redirect the standard input to/dev/null
. Thecapsule.daemon.keepStdin
system property can override it.Wait-Secs
: Wait seconds for service readiness, must be multiple of 10. Thecapsule.daemon.waitSecs
system 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.password
system property can override it.Daemon-Java-Exec-User
: the password of the user that will execute the final Java process (default: none). Thecapsule.daemon.javaExecUser
system property can override it.Daemon-Java-Exec-Password
: the password of the user that will execute the final Java process (default: none). Thecapsule.daemon.javaExecPassword
system property can override it.Daemon-Service-Name
: the service internal name (default: app ID). Thecapsule.daemon.serviceName
system property can override it.Daemon-Service-Display-Name
: the service display name (default: app ID). Thecapsule.daemon.displayName
system property can override it.Daemon-Service-Description
: the service description (default: app ID). Thecapsule.daemon.description
system property can override it.Daemon-Startup
: the service startup mode, eitherauto
ormanual
(default:manual
). Thecapsule.daemon.startup
system property can override it.Daemon-Type
: the service type, it can beinteractive (default: none). The
capsule.daemon.type` system property can override it.Daemon-DependsOn
: the list of service dependencies (default: none). Thecapsule.daemon.dependsOn
system property can override it.Daemon-Stop-Params
: the list of service stop parameters (default: none). Thecapsule.daemon.stopParams
system property can override it.Daemon-Stop-Timeout
: service stop timeout in seconds (default: none). Thecapsule.daemon.stopTimeout
system property can override it.Daemon-Log-Path
: the log path (default:%SystemRoot%\System32\LogFiles\Apache
). Thecapsule.daemon.logPath
system property can override it.Daemon-Log-Prefix
: the log prefix (default: app ID). Thecapsule.daemon.logPrefix
system property can override it.Daemon-Log-Level
: the log level betweenerror
,info
,warn
anddebug
(default:info
). Thecapsule.daemon.logLevel
system property can override it.
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 the CAPSULE_CACHE_DIR
environment 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