Startup script generated by SBT packager doesn't work

135 views Asked by At

I have an SBT project that uses a pure-Java plugin to create a Debian package. The plugin is defined in plugins.sbt as such:

libraryDependencies += "org.vafer" % "jdeb" % "1.5" artifacts (Artifact("jdeb", "jar", "jar"))

In the SBT console, I execute this command:

debian:packageBin

This generates a .deb file which I am attempting to install on an Ubuntu machine using dpkg -i <filename>

The package installs. The libraries and configuration etc. are placed in /usr/share/, which is what I expected. That folder also includes a bin folder with a script that directly starts the program. So far so good.

However, I want to start the program using service start <projectname>, which doesn't work. Same goes for /etc/init.d/<projectname> start. The output for the latter command is:

[ ok ] Starting undagrid-api-server (via systemctl): undagrid-api-server.service.

But the process isn't running when I check it with ps. Here's the contents of /etc/init.d/<projectname>

#! /bin/bash

### BEGIN INIT INFO
# Provides:     <projectname>
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: <projectname>
### END INIT INFO

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

# adding bashScriptEnvConfigLocation
[[ -f /etc/default/<projectname> ]] && . /etc/default/<projectname>

# $JAVA_OPTS used in $RUN_CMD wrapper
export JAVA_OPTS

PIDFILE=/var/run/<projectname>/running.pid

if [ -z "$DAEMON_USER" ]; then
    DAEMON_USER=<projectname>
fi

if [ -z "$DAEMON_GROUP" ]; then
    DAEMON_GROUP=<projectname>
fi


RUN_CMD="/usr/share/<projectname>/bin/<projectname>"


start_daemon() {
    log_daemon_msg "Starting" "<projectname>"
    [ -d "/var/run/<projectname>" ] || install -d -o "$DAEMON_USER" -g "$DAEMON_GROUP" -m755 "/var/run/<projectname>"
    start-stop-daemon --background --chdir /usr/share/<projectname> --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --startas "$RUN_CMD" --start -- $RUN_OPTS
    log_end_msg $?
}


stop_daemon() {
    log_daemon_msg "Stopping" "<projectname>"
    start-stop-daemon --stop --quiet --oknodo --pidfile "$PIDFILE" --retry=TERM/60/KILL/30
    log_end_msg $?
    rm -f "$PIDFILE"
}

case "$1" in

  start)
    start_daemon
    exit $?
          ;;
  stop)
    stop_daemon
    exit $?
          ;;
  restart|force-reload)
    stop_daemon
    start_daemon
    exit $?
    ;;
  status)
    status_of_proc -p "$PIDFILE" "$RUN_CMD" <projectname> && exit 0 || exit $?
    ;;
  *)
    log_daemon_msg "Usage: /etc/init.d/<projectname> {start|stop|restart|status}"
    ;;
esac
exit 0

With some simple debugging I have found out that if the command line argument is "start", the script never makes it past the second source statement: source /lib/lsb/init-functions

Systemctl gives me the following output:

<projectname>.service loaded active exited LSB: <projectname>

I have also run the script using bash -x but that produces quite a pile of output that I don't really know how to read.

Anybody know what's going on here? The entire point of using a packager and installing it as a package is to avoid headaches like these...

0

There are 0 answers