Spring Boot init.d脚本start-stop-daemon:未识别选项--no-close

6
在将我的应用程序符号链接到/etc/init.d/myappname之后,/etc/init.d/myappname start会显示"Failed to start"/var/log/appname.log显示:

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

当我删除--no-close时,jar文件变得损坏,无法再运行。我陷入了困境。
顺便提一下,我的jar文件是完全可执行的。也就是说,当我单独运行jar文件时,它可以正常启动springboot。
这里出了什么问题?
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]"
}

你能分享一下包含 --no close 选项的 init 脚本部分吗? - Darshan Mehta
@DarshanMehta:已添加。 - Sasi Kathimanda
你可以尝试使用 --background --exec 吗? - Darshan Mehta
3
您可以通过将属性文件中的标志设置为false来禁用start-stop demon配置,具体操作请参考这里(http://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html)。您可以尝试一下,谢谢。 - Darshan Mehta
1
如链接所述,我们可以将其添加到 spring-boot-maven-plugin 配置中。 - Darshan Mehta
显示剩余2条评论
3个回答

4

我假设你已经创建了一个可执行的Spring Boot应用JAR文件

  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
    

1
是 .conf 文件中的 USE_START_STOP_DAEMON=false 将问题解决了。— 使用为不同操作系统版本构建的 start-stop-daemon 版本不是一个选项。 - Corwin Newall

0

0

我终于解决了这个问题。

--no-close 是一个参数,最近被添加到 start-stop-daemon 中。

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

我在运行我的app.jar文件,它在Ubuntu 12.04 LTS上运行,该系统使用的是Debian的start-stop-daemon 1.16.1.2版本。

你可以通过以下方式知道你正在运行的版本:

start-stop-daemon --version

在Linux控制台上。

我下载了一个更新版本的start-stop-daemon。

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

安装deb包,Spring Boot jar最终将运行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接