1

I want to run my Spring boot based application as a service using init.d (Server is a Redhat 5.9).

When running service myapp start or /etc/init.d/myapp start, I get the following error:

/etc/init.d/myapp: line 168: syntax error near unexpected token `>'
/etc/init.d/myapp: line 168: `    $command &>> "$log_file" &

I ran sh -x /etc/init.d/myapp status to see what is happening, but it did not help me much. This is the last part of the output:

+ PID_FOLDER=/var/run/myapp
+ pid_file=/var/run/myapp/myapp.pid
+ log_file=/app/myapp//myapp.log
++ id -u
+ [[ 0 == \0 ]]
++ awk '{print $3}'
++ ls -ld /app/myapp/myapp-server-0.0.1-SNAPSHOT.jar
+ run_user=myapp
+ [[ -n /usr/java/default ]]
+ [[ -x /usr/java/default/bin/java ]]
+ javaexe=/usr/java/default/bin/java
+ command='/usr/java/default/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true  -jar /app/myapp/myapp-server-0.0.1-SNAPSHOT.jar  '
/etc/init.d/myapp: line 168: syntax error near unexpected token `>'
/etc/init.d/myapp: line 168: `    $command &>> "$log_file" &'

I do have a .conf file next to my jar as well:

[root@appdev02 myapp]# cat myapp-server-0.0.1-SNAPSHOT.conf
MODE=service
LOG_FOLDER=/app/myapp/
JAVA_HOME=/usr/java/default

I am using Spring Boot 1.3.1

UPDATE: I downgraded to Spring Boot 1.3.0 and things started working:

[root@appdev02 ~]# service myapp start
which: no start-stop-daemon in (/sbin:/usr/sbin:/bin:/usr/bin)
Started [19564]
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
  • Why don't you use Spring Boots integrated [init scripts](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#deployment-service)? – ksokol Dec 21 '15 at 09:20
  • This is what I am using. I have created a symlink from `/etc/init.d/myapp` to `/apps/myapp/myapp-server-0.0.1-SNAPSHOT.jar` – Wim Deblauwe Dec 21 '15 at 09:21

1 Answers1

2

I have run into this issue on OSX and it is because older versions of bash do not like the &>> "$log_file" redirect syntax. See https://www.gnu.org/software/bash/manual/bashref.html. To revert to the original bash syntax change:

$command &>> "$log_file" &

to:

$command >> "$log_file" 2>&1

I notice the original syntax is used in other places in the script and I will suggest the Spring Boot folks make the change in their root script.

Until then, I suggest copying the script, making the above edit, saving the new script and using it as the embeddedLanchScript - if using mvn this is done as so:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable
<embeddedLaunchScript>${basedir}/src/main/resources/embeddedLaunchScript.bash</embeddedLaunchScript>
    </configuration>
</plugin>
  • 2
    Looks like the change has been made to support old bash: https://github.com/spring-projects/spring-boot/commit/832ad2fe859bc726566e0eb07fdf8f596891a32a – Andrew Kaluzniacki Jan 05 '16 at 17:37
  • I'm using `iTerm2` on Mac, run into this problem too, and when I switch `1.3.1` to `1.4.0`, it is solved. – zhuguowei Sep 20 '16 at 09:15