Skip to content

Commit

Permalink
restart option added to sysvinit script, bug with wrong name for sysv…
Browse files Browse the repository at this point in the history
…init script fixed
  • Loading branch information
kardapoltsev committed Nov 26, 2013
1 parent 8843f58 commit d41b058
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
# Short-Description: ${{descr}}
### END INIT INFO

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

. /etc/default/${{appName}}
. /lib/init/vars.sh
. /lib/lsb/init-functions

Expand All @@ -23,27 +21,51 @@ get_java_cmd() {
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=$JAVA_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 $RUN_CMD
}


stop_daemon() {
log_daemon_msg "Stopping ${{app_name}}"
start-stop-daemon --stop --pidfile $PIDFILE --chuid $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

0 comments on commit d41b058

Please sign in to comment.