Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated shell script fails to run inside docker container because of empty line before shebang unix #119

Closed
jm2dev opened this issue Oct 11, 2017 · 4 comments

Comments

@jm2dev
Copy link
Contributor

jm2dev commented Oct 11, 2017

Generated shell script under target/pack/bin looks like:


#!/bin/bash
# bla bla

though it runs on my linux machine, it fails to run inside docker container.
The fix consists on removing the first empty line, but ideally it shouldn't appear on generation.

Desired output:

#!/bin/bash
# bla bla
@woky
Copy link

woky commented Nov 5, 2017

Create very simple systemd service file in /etc/systemd/system/foo.service to start the program by the launch script (start) created by pack:

[Service]
ExecStart=/opt/foo/bin/start

Start the service: systemctl start foo

The service won't start and the following will appear in journal (journalctl -n20):

Nov 05 20:50:26 myhost systemd[291]: foo.service: Failed to execute command: Exec format error
Nov 05 20:50:26 myhost systemd[291]: foo.service: Failed at step EXEC spawning /opt/foo/bin/start: Exec format error

The problem is that the first line of the launch script is empty line. I think systemd is being correct (and perhaps strict) here. The shebang line should be the first line in the file.

Perhaps the fix could be something like this?

diff --git a/src/main/twirl/xerial/sbt/pack/launch.scala.txt b/src/main/twirl/xerial/sbt/pack/launch.scala.txt
index 632d466..1a13ffd 100644
--- a/src/main/twirl/xerial/sbt/pack/launch.scala.txt
+++ b/src/main/twirl/xerial/sbt/pack/launch.scala.txt
@@ -1,5 +1,4 @@
-@(opts:xerial.sbt.pack.LaunchScript.Opts, expandedClasspath:Option[String])
-#!/bin/sh
+@(opts:xerial.sbt.pack.LaunchScript.Opts, expandedClasspath:Option[String])#!/bin/sh
 #/*--------------------------------------------------------------------------
 # *  Copyright 2012 Taro L. Saito
 # *

@gijsbert802
Copy link

I just ran into this issue. For now I worked around it by using CMD ["sh", "bin/pack-generated-script.sh"] instead of just CMD["bin/pack-generated-script.sh"] in my Dockerfile.

@xerial
Copy link
Owner

xerial commented Nov 14, 2017

Try sbt-0.9.2 with a fix in #120

@xerial xerial closed this as completed Nov 30, 2017
@Paulpeter
Copy link

Paulpeter commented Jun 13, 2018

Was struggling with this problem for some time where the script ran fine but failed to execute with service, putting the shebang in the first line solved it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants