Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart option added to sysvinit script #89

Merged
merged 4 commits into from
Nov 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,49 +1,71 @@
#! /bin/sh
#! /bin/bash

### BEGIN INIT INFO
# Provides: ${{app_name}}
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: ${{descr}}
### END INIT INFO

PIDFILE=/var/run/${{app_name}}.pid
DAEMON_USER=${{daemon_user}}

. /lib/init/vars.sh
. /lib/lsb/init-functions
test -e /etc/default/${{app_name}} && source /etc/default/${{app_name}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So user configuration is under /etc/default/ for the runner of the script?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be overwritten in /etc/defaults

Regards, Alexey
On Nov 26, 2013 6:50 PM, "Josh Suereth" notifications@github.com wrote:

In
src/main/resources/com/typesafe/sbt/packager/archetypes/sysvinit-template:

Default-Stop:

Short-Description: ${{descr}}

END INIT INFO

-PIDFILE=/var/run/${{app_name}}.pid

-DAEMON_USER=${{daemon_user}}

-. /lib/init/vars.sh
-. /lib/lsb/init-functions
+test -e /etc/default/${{app_name}} && source /etc/default/${{app_name}}

So user configuration is under /etc/default/ for the runner of the
script?


Reply to this email directly or view it on GitHubhttps://github.com//pull/89/files#r7923081
.

source /lib/init/vars.sh
source /lib/lsb/init-functions

get_java_cmd() {
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
if [ -x "$JAVA_HOME/bin/java" ]; then
echo "$JAVA_HOME/bin/java"
else
echo "java"
echo `which java`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, I always prefer the $(which java) syntax here...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use $(which java) next time. Thanks!

Regards, Alexey
On Nov 26, 2013 6:50 PM, "Josh Suereth" notifications@github.com wrote:

In
src/main/resources/com/typesafe/sbt/packager/archetypes/sysvinit-template:

 echo "$JAVA_HOME/bin/java"

else

  • echo "java"
  • echo which java

For some reason, I always prefer the $(which java) syntax here...


Reply to this email directly or view it on GitHubhttps://github.com//pull/89/files#r7923096
.

fi
}

JAVA_CMD=$(get_java_cmd)
PIDFILE=/var/run/${{app_name}}.pid

RUN_CMD=$JAVA_CMD -cp ${{app_classpath}} ${{app_main_class}}
if [ -z "$DAEMON_USER" ]; then
DAEMON_USER=${{daemon_user}}
fi

case "$1" in
if [ -z "$JAVA_CMD" ]; then
JAVA_CMD=$(get_java_cmd)
fi

start) log_daemon_msg "Starting ${{app_name}}"
# smb could define some additional options in $RUN_OPTS
RUN_CMD="-cp ${{app_classpath}} ${{app_main_class}} $RUN_OPTS"

start-stop-daemon --background --start --chuid $DAEMON_USER --make-pidfile --pidfile $PIDFILE --exec $RUN_CMD

;;
stop) log_daemon_msg "Stopping ${{app_name}}"
start_daemon() {
log_daemon_msg "Starting ${{app_name}}"
start-stop-daemon --background --start --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$JAVA_CMD" --start -- $RUN_CMD
}


start-stop-daemon --stop --pidfile $PIDFILE --chuid $DAEMON_USER
stop_daemon() {
log_daemon_msg "Stopping ${{app_name}}"
start-stop-daemon --stop --pidfile "$PIDFILE" --user "$DAEMON_USER"

RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
exit 2
RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
exit 2
}


case "$1" in

start)
start_daemon
;;
stop)
stop_daemon
;;
*) log_daemon_msg "Usage: /etc/init.d/${{app_name}} {start|stop}"
exit 2
;;
restart)
stop_daemon
start_daemon
;;
*)
log_daemon_msg "Usage: /etc/init.d/${{app_name}} {start|stop}"
exit 2
;;
esac
exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ package archetypes

import Keys._
import sbt._
import sbt.Project.Initialize
import sbt.Keys.{ mappings, target, name, mainClass, normalizedName }
import linux.LinuxPackageMapping
import sbt.Keys.{ target, mainClass, normalizedName }
import SbtNativePackager._
import com.typesafe.sbt.packager.linux.LinuxPackageMapping

Expand All @@ -27,7 +25,8 @@ object JavaServerAppPackaging {
def debianSettings: Seq[Setting[_]] =
Seq(
debianStartScriptReplacements <<= (
maintainer in Debian, packageSummary in Debian, serverLoading in Debian, daemonUser in Debian, normalizedName, sbt.Keys.version, defaultLinuxInstallLocation, sbt.Keys.mainClass in Compile, scriptClasspath)
maintainer in Debian, packageSummary in Debian, serverLoading in Debian, daemonUser in Debian, normalizedName,
sbt.Keys.version, defaultLinuxInstallLocation, mainClass in Compile, scriptClasspath)
map { (author, descr, loader, daemonUser, name, version, installLocation, mainClass, cp) =>
// TODO name-version is copied from UniversalPlugin. This should be consolidated into a setting (install location...)
val appDir = installLocation + "/" + name
Expand All @@ -45,8 +44,10 @@ object JavaServerAppPackaging {
daemonUser = daemonUser
)
},
debianMakeStartScript <<= (debianStartScriptReplacements, normalizedName, target in Universal, serverLoading in Debian) map makeDebianStartScript,
linuxPackageMappings in Debian <++= (debianMakeStartScript, normalizedName, serverLoading in Debian) map { (script, name, loader) =>
debianMakeStartScript <<= (debianStartScriptReplacements, normalizedName, target in Universal, serverLoading in Debian)
map makeDebianStartScript,
linuxPackageMappings in Debian <++= (debianMakeStartScript, normalizedName, serverLoading in Debian)
map { (script, name, loader) =>
val (path, permissions) = loader match {
case Upstart => ("/etc/init/" + name + ".conf", "0644")
case SystemV => ("/etc/init.d/" + name, "0755")
Expand All @@ -66,7 +67,7 @@ object JavaServerAppPackaging {
if (replacements.isEmpty) None
else {
val scriptBits = JavaAppStartScript.generateScript(replacements, loader)
val script = tmpDir / "tmp" / "bin" / name
val script = tmpDir / "tmp" / "bin" / s"$name.$loader"
IO.write(script, scriptBits)
Some(script)
}
Expand Down