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

Custom bash script to run before default start script #380

Closed
mhamrah opened this issue Oct 15, 2014 · 3 comments
Closed

Custom bash script to run before default start script #380

mhamrah opened this issue Oct 15, 2014 · 3 comments

Comments

@mhamrah
Copy link
Contributor

mhamrah commented Oct 15, 2014

I'd like a way to run a custom bash script (which sources a file for environment variables and sets up some other settings) without having to override the default templates. I like the idea of the /etc/default server setting and .conf files, but these seem to concatenate settings--one per line--to the command line options of the start script. I'd like a place to add a little more complexity without having to mimic the default script template.

Suggestions? I thought there was a way to add a setting to call an external script (or other command) before the start script. Maybe there's a template parameter key I'm missing?

Thanks,

Mike

@mhamrah
Copy link
Contributor Author

mhamrah commented Oct 15, 2014

As an example, I want to dynamically set the java memory setting based on the size of the box:

TOTAL_MEM=`free -m | sed  -n -e '/^Mem:/s/^[^0-9]*\([0-9]*\) .*/\1/p'` 
JAVA_MEM=`expr $TOTAL_MEM / 5 \* 4`
# JAVA_MEM can be set in JAVA_OPTS or passed to -mem

and I need the hostname in an environment variable:

export HOSTNAME=`hostname --fqdn`

@fiadliel
Copy link
Contributor

This seems to do something like what you want:

bashScriptExtraDefines ++= Seq(
  """export HOSTNAME=`hostname --fqdn`""",
  """TOTAL_MEM=`free -m | sed  -n -e '/^Mem:/s/^[^0-9]*\([0-9]*\) .*/\1/p'`""",
  """JAVA_MEM=`expr $TOTAL_MEM / 5 \* 4`""",
  """app_mem=${JAVA_MEM}"""
)

or perhaps

bashScriptExtraDefines ++= IO.readLines(baseDirectory.value / "scripts" / "extra.sh")

The lines are placed near the end of the script, and have access to a number of utility bash functions (e.g. addJava, addApp, addResidual, addDebugger). There is no function matching the result of calling -mem, but you can assign directly to app_mem (this does not change the reported default value from -h, however).

Here's an example where the feature is used to add a -javaagent parameter: https://github.com/gilt/sbt-newrelic/blob/master/src/main/scala/NewRelic.scala#L46

@mhamrah
Copy link
Contributor Author

mhamrah commented Oct 16, 2014

Perfect, bashScriptExtraDefines is what I was looking for. I'll beef up the documentation on this in my MR #379.

@mhamrah mhamrah closed this as completed Oct 16, 2014
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

2 participants