6

after symlink my app to the /etc/init.d/myappname.

/etc/init.d/myappname start gives "Failed to start"

/var/log/appname.log tells

"start-stop-daemon: unrecognized option '--no-close'"

when i remove the --no-close, the jar becomes corrupted and cannot run anymore. i am struck.

bdw my jar is fullyexecutable jar. i.e., when i run the jar alone it starts up the springboot normally.

whats going wrong here?

EDIT:

do_start() {
  working_dir=$(dirname "$jarfile")
  pushd "$working_dir" > /dev/null
  if [[ -n "$run_user" ]]; then
    mkdir "$PID_FOLDER" &> /dev/null
    checkPermissions || return $?
    chown "$run_user" "$PID_FOLDER"
    chown "$run_user" "$pid_file"
    chown "$run_user" "$log_file"
    if [ $USE_START_STOP_DAEMON = true ] && type start-stop-daemon > /dev/null 2>&1; then
      arguments=(-Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS -jar $jarfile $RUN_ARGS "$@")
      start-stop-daemon --start --quiet \
        --chuid "$run_user" \
        --name "$identity" \
        --make-pidfile --pidfile "$pid_file" \
        --background --no-close \
        --startas "$javaexe" \
        --chdir "$working_dir" \
        -- "${arguments[@]}" \
        >> "$log_file" 2>&1
      await_file "$pid_file"
    else
      su -s /bin/sh -c "$command >> \"$log_file\" 2>&1 & echo \$!" "$run_user" > "$pid_file"
    fi
    pid=$(cat "$pid_file")
  else
    checkPermissions || return $?
    $command >> "$log_file" 2>&1 &
    pid=$!
    disown $pid
    echo "$pid" > "$pid_file"
  fi
  [[ -z $pid ]] && { echoRed "Failed to start"; return 1; }
  echoGreen "Started [$pid]"
}
Sasi Kathimanda
  • 1,788
  • 3
  • 25
  • 47
  • Can you share the part of init script that has `--no close` option? – Darshan Mehta Mar 07 '16 at 12:28
  • @DarshanMehta : added – Sasi Kathimanda Mar 07 '16 at 12:31
  • Can you try with `--background --exec` instead? – Darshan Mehta Mar 07 '16 at 12:41
  • the moment i edit the /etc/init.d/appname , the jar becomes corrupted. the startup script is created automatically by spring boot , so probably it wont like manual edits. any other alternatives where i can auto deploy spring boot ? – Sasi Kathimanda Mar 07 '16 at 12:51
  • 3
    You can disable `start-stop demon` config by setting the flag in the property file to false as described here (http://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html). Can you try with that? thanks. – Darshan Mehta Mar 07 '16 at 12:59
  • @DarshanMehta : your suggestion worked ! Thanks lot. I set the USE_START_STOP_DAEMON=false as environment variable for testing .But how add it spring config on fly, as i am not running the java -jar appname.jar byhand. – Sasi Kathimanda Mar 07 '16 at 13:33
  • 1
    As explained in the link, we can add it into configuration of `spring-boot-maven-plugin` config. – Darshan Mehta Mar 07 '16 at 13:37

3 Answers3

4

I assume you already created an executable JAR of your Spring Boot app.

  1. Copy your app to /var/appname/appname.jar

  2. Make sure it's given execute permission:

    sudo chmod +x "/var/appname/appname.jar"
    
  3. Create a config file /var/appname/appname.conf with the following content

    USE_START_STOP_DAEMON=false
    
  4. Follow instructions from Spring Boot Reference Guide

    To install a Spring Boot application as an init.d service simply create a symlink:

    $ sudo ln -s /var/appname/appname.jar /etc/init.d/appname
    

    Once installed, you can start and stop the service in the usual way. For example, on a Debian based system:

    $ service appname start
    
naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
  • 1
    It was the .conf file `USE_START_STOP_DAEMON=false` which fixed it for me. — Using a version of `start-stop-daemon` built for a different OS version was not an option – Corwin Newall Mar 11 '18 at 21:38
0

i finally solve this problem.

--no-close is a parameter that was "recently" added to start-stop-daemon

http://manpages.ubuntu.com/manpages/wily/man8/start-stop-daemon.8.html

I run my app.jar on Ubuntu 12.04 LTS that has start-stop-daemon 1.16.1.2 for Debian

You could know what version you are running using:

start-stop-daemon --version

on linux console.

I downloaded a newer version of start-stop-daemon on

https://pkgs.org/ubuntu-14.04/ubuntu-main-amd64/dpkg_1.17.5ubuntu5_amd64.deb.html

Install the deb package and spring boot jar will finally run.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Andres
  • 383
  • 1
  • 4
  • 8
0

Run "service myappname start" as mentioned in the document http://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

There is a difference between /etc/init.d/myappname start and server myappname start

sramu
  • 1,001
  • 9
  • 9