spring boot init.d script start-stop-daemon:无法识别的选项--no-close

时间:2016-03-07 12:20:14

标签: java linux spring spring-boot

将我的应用程序符号链接到 /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会损坏,无法继续运行。我很震惊。

bdw我的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]"
}

3 个答案:

答案 0 :(得分:2)

  1. 将您的应用复制到/var/appname/appname.jar

  2. 确保它是可执行的:

    sudo chmod +x "/var/appname/appname.jar"
    
  3. 使用以下内容创建配置文件/var/appname/appname.conf

    USE_START_STOP_DAEMON=false
    
  4. 按照Spring Boot Reference Guide

    的说明操作
      

    要将Spring Boot应用程序安装为init.d服务,只需创建一个符号链接:

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

    安装完成后,您可以按常规方式启动和停止服务。例如,在基于Debian的系统上:

    $ service appname start
    

答案 1 :(得分:0)

我终于解决了这个问题。

--no-close是"最近"的参数。添加到start-stop-daemon

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

我在Ubuntu 12.04 LTS上运行我的app.jar 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。

答案 2 :(得分:0)

运行文档http://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

中提到的“service myappname start”

/etc/init.d/myappname start和server myappname start

之间存在差异