├── .gitignore ├── README ├── files ├── elasticsearch └── limits.conf ├── manifests └── init.pp └── templates ├── elasticsearch.conf.erb ├── elasticsearch.limits.conf.erb ├── elasticsearch.yml.erb └── upstart.elasticsearch.conf.erb /.gitignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | *.tgz 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | To use this module: 2 | 1.) You will need to download the version of elasticsearch you are running and add it to the modules /files folder. 3 | http://www.elasticsearch.org/download/ 4 | 2.) You will also need to download the elasticsearch service wrapper 5 | https://github.com/elasticsearch/elasticsearch-servicewrapper 6 | 7 | Usage: 8 | 9 | In your templates.pp or nodes.pp or wherever you define your server roles and applications you can call the elasticsearch module like so: 10 | 11 | class role_prod_dbserver { 12 | class { elasticsearch: version => "0.15.2" } 13 | } 14 | 15 | This version number should correspond to the version of ES you downloaded from the above link. 16 | The filenames should look like: 17 | /etc/puppet/modules/elasticsearch/files/elasticsearch-${version}.tar.gz 18 | - and - 19 | /etc/puppet/modules/elasticsearch/files/elasticsearch-servicewrapper.tar.gz 20 | 21 | For additional information see my blog post here: 22 | http://www.visibiz.com/blog/hunter/elasticsearch/elasticsearch-puppet-module 23 | -------------------------------------------------------------------------------- /files/elasticsearch: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # RESOLVE and SET $ES_HOME 4 | 5 | SCRIPT="$0" 6 | 7 | # SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. 8 | while [ -h "$SCRIPT" ] ; do 9 | ls=`ls -ld "$SCRIPT"` 10 | # Drop everything prior to -> 11 | link=`expr "$ls" : '.*-> \(.*\)$'` 12 | if expr "$link" : '/.*' > /dev/null; then 13 | SCRIPT="$link" 14 | else 15 | SCRIPT=`dirname "$SCRIPT"`/"$link" 16 | fi 17 | done 18 | 19 | # determine elasticsearch home 20 | ES_HOME=`dirname "$SCRIPT"`/../.. 21 | 22 | # make ELASTICSEARCH_HOME absolute 23 | export ES_HOME=`cd $ES_HOME; pwd` 24 | 25 | 26 | # Application 27 | APP_NAME="elasticsearch" 28 | APP_LONG_NAME="ElasticSearch" 29 | 30 | # Wrapper 31 | WRAPPER_CMD="$ES_HOME/bin/service/exec/elasticsearch" 32 | WRAPPER_CONF="$ES_HOME/bin/service/elasticsearch.conf" 33 | 34 | # Priority at which to run the wrapper. See "man nice" for valid priorities. 35 | # nice is only used if a priority is specified. 36 | PRIORITY= 37 | 38 | # Location of the pid file. 39 | PIDDIR="." 40 | 41 | # FIXED_COMMAND tells the script to use a hard coded action rather than 42 | # expecting the first parameter of the command line to be the command. 43 | # By default the command will will be expected to be the first parameter. 44 | #FIXED_COMMAND=console 45 | 46 | # PASS_THROUGH tells the script to pass all arguments through to the JVM 47 | # as is. If FIXED_COMMAND is specified then all arguments will be passed. 48 | # If not set then all arguments starting with the second will be passed. 49 | #PASS_THROUGH=true 50 | 51 | # If uncommented, causes the Wrapper to be shutdown using an anchor file. 52 | # When launched with the 'start' command, it will also ignore all INT and 53 | # TERM signals. 54 | #IGNORE_SIGNALS=true 55 | 56 | # Wrapper will start the JVM asynchronously. Your application may have some 57 | # initialization tasks and it may be desirable to wait a few seconds 58 | # before returning. For example, to delay the invocation of following 59 | # startup scripts. Setting WAIT_AFTER_STARTUP to a positive number will 60 | # cause the start command to delay for the indicated period of time 61 | # (in seconds). 62 | # 63 | WAIT_AFTER_STARTUP=0 64 | 65 | # If set, wait for the wrapper to report that the daemon has started 66 | WAIT_FOR_STARTED_STATUS=true 67 | WAIT_FOR_STARTED_TIMEOUT=120 68 | 69 | # If set, the status, start_msg and stop_msg commands will print out detailed 70 | # state information on the Wrapper and Java processes. 71 | #DETAIL_STATUS=true 72 | 73 | # If set, the 'pause' and 'resume' commands will be enabled. These make it 74 | # possible to pause the JVM or Java application without completely stopping 75 | # the Wrapper. See the wrapper.pausable and wrapper.pausable.stop_jvm 76 | # properties for more information. 77 | #PAUSABLE=true 78 | 79 | # If specified, the Wrapper will be run as the specified user. 80 | # IMPORTANT - Make sure that the user has the required privileges to write 81 | # the PID file and wrapper.log files. Failure to be able to write the log 82 | # file will cause the Wrapper to exit without any way to write out an error 83 | # message. 84 | # NOTE - This will set the user which is used to run the Wrapper as well as 85 | # the JVM and is not useful in situations where a privileged resource or 86 | # port needs to be allocated prior to the user being changed. 87 | RUN_AS_USER=elasticsearch 88 | 89 | # Specify the number of open files ulimit for the above user 90 | # recommended value: 32000 91 | #ULIMIT_N= 92 | 93 | # By default we show a detailed usage block. Uncomment to show brief usage. 94 | #BRIEF_USAGE=true 95 | 96 | # When installing on On Mac OSX platforms, the following domain will be used to 97 | # prefix the plist file name. 98 | PLIST_DOMAIN=org.tanukisoftware.wrapper 99 | 100 | # The following two lines are used by the chkconfig command. Change as is 101 | # appropriate for your application. They should remain commented. 102 | # chkconfig: 2345 20 80 103 | # description: @app.long.name@ 104 | 105 | # Initialization block for the install_initd and remove_initd scripts used by 106 | # SUSE linux distributions. 107 | ### BEGIN INIT INFO 108 | # Provides: @app.name@ 109 | # Required-Start: $local_fs $network $syslog 110 | # Should-Start: 111 | # Required-Stop: 112 | # Default-Start: 2 3 4 5 113 | # Default-Stop: 0 1 6 114 | # Short-Description: @app.long.name@ 115 | # Description: @app.description@ 116 | ### END INIT INFO 117 | 118 | # Do not modify anything beyond this point 119 | #----------------------------------------------------------------------------- 120 | 121 | if [ -n "$FIXED_COMMAND" ] 122 | then 123 | COMMAND="$FIXED_COMMAND" 124 | else 125 | COMMAND="$1" 126 | fi 127 | 128 | 129 | # Required for HP-UX Startup 130 | if [ `uname -s` = "HP-UX" -o `uname -s` = "HP-UX64" ] ; then 131 | PATH=$PATH:/usr/bin 132 | fi 133 | 134 | # Get the fully qualified path to the script 135 | case $0 in 136 | /*) 137 | SCRIPT="$0" 138 | ;; 139 | *) 140 | PWD=`pwd` 141 | SCRIPT="$PWD/$0" 142 | ;; 143 | esac 144 | 145 | # Resolve the true real path without any sym links. 146 | CHANGED=true 147 | while [ "X$CHANGED" != "X" ] 148 | do 149 | # Change spaces to ":" so the tokens can be parsed. 150 | SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'` 151 | # Get the real path to this script, resolving any symbolic links 152 | TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'` 153 | REALPATH= 154 | for C in $TOKENS; do 155 | # Change any ":" in the token back to a space. 156 | C=`echo $C | sed -e 's;:; ;g'` 157 | REALPATH="$REALPATH/$C" 158 | # If REALPATH is a sym link, resolve it. Loop for nested links. 159 | while [ -h "$REALPATH" ] ; do 160 | LS="`ls -ld "$REALPATH"`" 161 | LINK="`expr "$LS" : '.*-> \(.*\)$'`" 162 | if expr "$LINK" : '/.*' > /dev/null; then 163 | # LINK is absolute. 164 | REALPATH="$LINK" 165 | else 166 | # LINK is relative. 167 | REALPATH="`dirname "$REALPATH"`""/$LINK" 168 | fi 169 | done 170 | done 171 | 172 | if [ "$REALPATH" = "$SCRIPT" ] 173 | then 174 | CHANGED="" 175 | else 176 | SCRIPT="$REALPATH" 177 | fi 178 | done 179 | 180 | # Get the location of the script. 181 | REALDIR=`dirname "$REALPATH"` 182 | 183 | # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if 184 | # the working directory is later changed. 185 | FIRST_CHAR=`echo $PIDDIR | cut -c1,1` 186 | if [ "$FIRST_CHAR" != "/" ] 187 | then 188 | PIDDIR=$REALDIR/$PIDDIR 189 | fi 190 | # Same test for WRAPPER_CMD 191 | FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1` 192 | if [ "$FIRST_CHAR" != "/" ] 193 | then 194 | WRAPPER_CMD=$REALDIR/$WRAPPER_CMD 195 | fi 196 | # Same test for WRAPPER_CONF 197 | FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1` 198 | if [ "$FIRST_CHAR" != "/" ] 199 | then 200 | WRAPPER_CONF=$REALDIR/$WRAPPER_CONF 201 | fi 202 | 203 | # Process ID 204 | ANCHORFILE="$PIDDIR/$APP_NAME.anchor" 205 | COMMANDFILE="$PIDDIR/$APP_NAME.command" 206 | STATUSFILE="$PIDDIR/$APP_NAME.status" 207 | JAVASTATUSFILE="$PIDDIR/$APP_NAME.java.status" 208 | PIDFILE="$PIDDIR/$APP_NAME.pid" 209 | LOCKDIR="/var/lock/subsys" 210 | LOCKFILE="$LOCKDIR/$APP_NAME" 211 | pid="" 212 | 213 | # Resolve the location of the 'ps' command 214 | PSEXE="/usr/ucb/ps" 215 | if [ ! -x "$PSEXE" ] 216 | then 217 | PSEXE="/usr/bin/ps" 218 | if [ ! -x "$PSEXE" ] 219 | then 220 | PSEXE="/bin/ps" 221 | if [ ! -x "$PSEXE" ] 222 | then 223 | eval echo 'Unable to locate "ps".' 224 | eval echo 'Please report this message along with the location of the command on your system.' 225 | exit 1 226 | fi 227 | fi 228 | fi 229 | 230 | # Resolve the os 231 | DIST_OS=`uname -s | tr '[A-Z]' '[a-z]' | tr -d ' '` 232 | case "$DIST_OS" in 233 | 'sunos') 234 | DIST_OS="solaris" 235 | ;; 236 | 'hp-ux' | 'hp-ux64') 237 | # HP-UX needs the XPG4 version of ps (for -o args) 238 | DIST_OS="hpux" 239 | UNIX95="" 240 | export UNIX95 241 | ;; 242 | 'darwin') 243 | DIST_OS="macosx" 244 | ;; 245 | 'unix_sv') 246 | DIST_OS="unixware" 247 | ;; 248 | 'os/390') 249 | DIST_OS="zos" 250 | ;; 251 | esac 252 | 253 | # Resolve the architecture 254 | if [ "$DIST_OS" = "macosx" ] 255 | then 256 | OS_VER=`sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*'` 257 | DIST_ARCH="universal" 258 | if [[ "$OS_VER" < "10.5.0" ]] 259 | then 260 | DIST_BITS="32" 261 | else 262 | DIST_BITS="64" 263 | fi 264 | APP_PLIST_BASE=${PLIST_DOMAIN}.${APP_NAME} 265 | APP_PLIST=${APP_PLIST_BASE}.plist 266 | else 267 | DIST_ARCH= 268 | DIST_ARCH=`uname -p 2>/dev/null | tr '[A-Z]' '[a-z]' | tr -d ' '` 269 | if [ "X$DIST_ARCH" = "X" ] 270 | then 271 | DIST_ARCH="unknown" 272 | fi 273 | if [ "$DIST_ARCH" = "unknown" ] 274 | then 275 | DIST_ARCH=`uname -m 2>/dev/null | tr '[A-Z]' '[a-z]' | tr -d ' '` 276 | fi 277 | case "$DIST_ARCH" in 278 | 'athlon' | 'i386' | 'i486' | 'i586' | 'i686') 279 | DIST_ARCH="x86" 280 | if [ "${DIST_OS}" = "solaris" ] ; then 281 | DIST_BITS=`isainfo -b` 282 | else 283 | DIST_BITS="32" 284 | fi 285 | ;; 286 | 'amd64' | 'x86_64') 287 | DIST_ARCH="x86" 288 | DIST_BITS="64" 289 | ;; 290 | 'ia32') 291 | DIST_ARCH="ia" 292 | DIST_BITS="32" 293 | ;; 294 | 'ia64' | 'ia64n' | 'ia64w') 295 | DIST_ARCH="ia" 296 | DIST_BITS="64" 297 | ;; 298 | 'ip27') 299 | DIST_ARCH="mips" 300 | DIST_BITS="32" 301 | ;; 302 | 'power' | 'powerpc' | 'power_pc' | 'ppc64') 303 | if [ "${DIST_ARCH}" = "ppc64" ] ; then 304 | DIST_BITS="64" 305 | else 306 | DIST_BITS="32" 307 | fi 308 | DIST_ARCH="ppc" 309 | if [ "${DIST_OS}" = "aix" ] ; then 310 | if [ `getconf KERNEL_BITMODE` -eq 64 ]; then 311 | DIST_BITS="64" 312 | else 313 | DIST_BITS="32" 314 | fi 315 | fi 316 | ;; 317 | 'pa_risc' | 'pa-risc') 318 | DIST_ARCH="parisc" 319 | if [ `getconf KERNEL_BITS` -eq 64 ]; then 320 | DIST_BITS="64" 321 | else 322 | DIST_BITS="32" 323 | fi 324 | ;; 325 | 'sun4u' | 'sparcv9' | 'sparc') 326 | DIST_ARCH="sparc" 327 | DIST_BITS=`isainfo -b` 328 | ;; 329 | '9000/800' | '9000/785') 330 | DIST_ARCH="parisc" 331 | if [ `getconf KERNEL_BITS` -eq 64 ]; then 332 | DIST_BITS="64" 333 | else 334 | DIST_BITS="32" 335 | fi 336 | ;; 337 | '2097') 338 | DIST_ARCH="390" 339 | DIST_BITS="32" 340 | ;; 341 | esac 342 | fi 343 | 344 | # OSX always places Java in the same location so we can reliably set JAVA_HOME 345 | if [ "$DIST_OS" = "macosx" ] 346 | then 347 | if [ -z "$JAVA_HOME" ]; then 348 | JAVA_HOME="/Library/Java/Home"; export JAVA_HOME 349 | fi 350 | fi 351 | 352 | # Test Echo 353 | ECHOTEST=`echo -n "x"` 354 | if [ "$ECHOTEST" = "x" ] 355 | then 356 | ECHOOPT="-n " 357 | else 358 | ECHOOPT="" 359 | fi 360 | 361 | 362 | gettext() { 363 | echo "$1" 364 | } 365 | 366 | outputFile() { 367 | if [ -f "$1" ] 368 | then 369 | eval echo ' $1 Found but not executable.'; 370 | else 371 | echo " $1" 372 | fi 373 | } 374 | 375 | # Decide on the wrapper binary to use. 376 | # If the bits of the OS could be detected, we will try to look for the 377 | # binary with the correct bits value. If it doesn't exist, fall back 378 | # and look for the 32-bit binary. If that doesn't exist either then 379 | # look for the default. 380 | WRAPPER_TEST_CMD="" 381 | if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS" ] 382 | then 383 | WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS" 384 | if [ ! -x "$WRAPPER_TEST_CMD" ] 385 | then 386 | chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null 387 | fi 388 | if [ -x "$WRAPPER_TEST_CMD" ] 389 | then 390 | WRAPPER_CMD="$WRAPPER_TEST_CMD" 391 | else 392 | outputFile "$WRAPPER_TEST_CMD" 393 | WRAPPER_TEST_CMD="" 394 | fi 395 | fi 396 | if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" -a -z "$WRAPPER_TEST_CMD" ] 397 | then 398 | WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" 399 | if [ ! -x "$WRAPPER_TEST_CMD" ] 400 | then 401 | chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null 402 | fi 403 | if [ -x "$WRAPPER_TEST_CMD" ] 404 | then 405 | WRAPPER_CMD="$WRAPPER_TEST_CMD" 406 | else 407 | outputFile "$WRAPPER_TEST_CMD" 408 | WRAPPER_TEST_CMD="" 409 | fi 410 | fi 411 | if [ -f "$WRAPPER_CMD" -a -z "$WRAPPER_TEST_CMD" ] 412 | then 413 | WRAPPER_TEST_CMD="$WRAPPER_CMD" 414 | if [ ! -x "$WRAPPER_TEST_CMD" ] 415 | then 416 | chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null 417 | fi 418 | if [ -x "$WRAPPER_TEST_CMD" ] 419 | then 420 | WRAPPER_CMD="$WRAPPER_TEST_CMD" 421 | else 422 | outputFile "$WRAPPER_TEST_CMD" 423 | WRAPPER_TEST_CMD="" 424 | fi 425 | fi 426 | if [ -z "$WRAPPER_TEST_CMD" ] 427 | then 428 | eval echo 'Unable to locate any of the following binaries:' 429 | outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS" 430 | if [ ! "$DIST_BITS" = "32" ] 431 | then 432 | outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" 433 | fi 434 | outputFile "$WRAPPER_CMD" 435 | 436 | exit 1 437 | fi 438 | 439 | 440 | # Build the nice clause 441 | if [ "X$PRIORITY" = "X" ] 442 | then 443 | CMDNICE="" 444 | else 445 | CMDNICE="nice -$PRIORITY" 446 | fi 447 | 448 | # Build the anchor file clause. 449 | if [ "X$IGNORE_SIGNALS" = "X" ] 450 | then 451 | ANCHORPROP= 452 | IGNOREPROP= 453 | else 454 | ANCHORPROP=wrapper.anchorfile=\"$ANCHORFILE\" 455 | IGNOREPROP=wrapper.ignore_signals=TRUE 456 | fi 457 | 458 | # Build the status file clause. 459 | if [ "X$DETAIL_STATUS$WAIT_FOR_STARTED_STATUS" = "X" ] 460 | then 461 | STATUSPROP= 462 | else 463 | STATUSPROP="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\"" 464 | fi 465 | 466 | # Build the command file clause. 467 | if [ -n "$PAUSABLE" ] 468 | then 469 | COMMANDPROP="wrapper.commandfile=\"$COMMANDFILE\" wrapper.pausable=TRUE" 470 | else 471 | COMMANDPROP= 472 | fi 473 | 474 | if [ ! -n "$WAIT_FOR_STARTED_STATUS" ] 475 | then 476 | WAIT_FOR_STARTED_STATUS=true 477 | fi 478 | 479 | if [ $WAIT_FOR_STARTED_STATUS = true ] ; then 480 | DETAIL_STATUS=true 481 | fi 482 | 483 | 484 | # Build the lock file clause. Only create a lock file if the lock directory exists on this platform. 485 | LOCKPROP= 486 | if [ -d $LOCKDIR ] 487 | then 488 | if [ -w $LOCKDIR ] 489 | then 490 | LOCKPROP=wrapper.lockfile=\"$LOCKFILE\" 491 | fi 492 | fi 493 | 494 | prepAdditionalParams() { 495 | ADDITIONAL_PARA="" 496 | if [ -n "$PASS_THROUGH" ] ; then 497 | ADDITIONAL_PARA="--" 498 | while [ -n "$1" ] ; do 499 | ADDITIONAL_PARA="$ADDITIONAL_PARA \"$1\"" 500 | shift 501 | done 502 | fi 503 | } 504 | 505 | checkUser() { 506 | # $1 touchLock flag 507 | # $2.. [command] args 508 | 509 | # Check the configured user. If necessary rerun this script as the desired user. 510 | if [ "X$RUN_AS_USER" != "X" ] 511 | then 512 | # Resolve the location of the 'id' command 513 | IDEXE="/usr/xpg4/bin/id" 514 | if [ ! -x "$IDEXE" ] 515 | then 516 | IDEXE="/usr/bin/id" 517 | if [ ! -x "$IDEXE" ] 518 | then 519 | eval echo 'Unable to locate "id".' 520 | eval echo 'Please report this message along with the location of the command on your system.' 521 | exit 1 522 | fi 523 | fi 524 | 525 | if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ] 526 | then 527 | # Already running as the configured user. Avoid password prompts by not calling su. 528 | RUN_AS_USER="" 529 | fi 530 | fi 531 | if [ "X$RUN_AS_USER" != "X" ] 532 | then 533 | # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be 534 | # able to create the lock file. The Wrapper will be able to update this file once it 535 | # is created but will not be able to delete it on shutdown. If $1 is set then 536 | # the lock file should be created for the current command 537 | if [ "X$LOCKPROP" != "X" ] 538 | then 539 | if [ "X$1" != "X" ] 540 | then 541 | # Resolve the primary group 542 | RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1` 543 | if [ "X$RUN_AS_GROUP" = "X" ] 544 | then 545 | RUN_AS_GROUP=$RUN_AS_USER 546 | fi 547 | touch $LOCKFILE 548 | chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE 549 | fi 550 | fi 551 | 552 | # Still want to change users, recurse. This means that the user will only be 553 | # prompted for a password once. Variables shifted by 1 554 | shift 555 | 556 | # Wrap the parameters so they can be passed. 557 | ADDITIONAL_PARA="" 558 | while [ -n "$1" ] ; do 559 | ADDITIONAL_PARA="$ADDITIONAL_PARA \"$1\"" 560 | shift 561 | done 562 | 563 | # Set ulimit if specified. 564 | if [ "X$ULIMIT_N" != "X" ] 565 | then 566 | ulimit -n $ULIMIT_N 567 | fi 568 | 569 | # Use "runuser" if this exists. runuser should be used on RedHat in preference to su. 570 | # 571 | if test -f "/sbin/runuser" 572 | then 573 | /sbin/runuser - $RUN_AS_USER -c "\"$REALPATH\" $ADDITIONAL_PARA" 574 | else 575 | # CHANGE: Changed from wrapper script: Added -s "/bin/sh" to force the script type 576 | su - $RUN_AS_USER -s "/bin/sh" -c "\"$REALPATH\" $ADDITIONAL_PARA" 577 | fi 578 | 579 | # Now that we are the original user again, we may need to clean up the lock file. 580 | if [ "X$LOCKPROP" != "X" ] 581 | then 582 | getpid 583 | if [ "X$pid" = "X" ] 584 | then 585 | # Wrapper is not running so make sure the lock file is deleted. 586 | if [ -f "$LOCKFILE" ] 587 | then 588 | rm "$LOCKFILE" 589 | fi 590 | fi 591 | fi 592 | 593 | exit 0 594 | fi 595 | } 596 | 597 | getpid() { 598 | pid="" 599 | if [ -f "$PIDFILE" ] 600 | then 601 | if [ -r "$PIDFILE" ] 602 | then 603 | pid=`cat "$PIDFILE"` 604 | if [ "X$pid" != "X" ] 605 | then 606 | # It is possible that 'a' process with the pid exists but that it is not the 607 | # correct process. This can happen in a number of cases, but the most 608 | # common is during system startup after an unclean shutdown. 609 | # The ps statement below looks for the specific wrapper command running as 610 | # the pid. If it is not found then the pid file is considered to be stale. 611 | case "$DIST_OS" in 612 | 'freebsd') 613 | pidtest=`$PSEXE -p $pid -o args | tail -1` 614 | if [ "X$pidtest" = "XCOMMAND" ] 615 | then 616 | pidtest="" 617 | fi 618 | ;; 619 | 'macosx') 620 | pidtest=`$PSEXE -ww -p $pid -o command | grep "$WRAPPER_CMD" | tail -1` 621 | ;; 622 | 'solaris') 623 | if [ -f "/usr/bin/pargs" ] 624 | then 625 | pidtest=`pargs $pid | grep "$WRAPPER_CMD" | tail -1` 626 | else 627 | case "$PSEXE" in 628 | '/usr/ucb/ps') 629 | pidtest=`$PSEXE -auxww $pid | grep "$WRAPPER_CMD" | tail -1` 630 | ;; 631 | '/usr/bin/ps') 632 | TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1` 633 | COUNT=`echo $TRUNCATED_CMD | wc -m` 634 | COUNT=`echo ${COUNT}` 635 | COUNT=`expr $COUNT - 1` 636 | TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT` 637 | pidtest=`$PSEXE -o comm -p $pid | grep "$TRUNCATED_CMD" | tail -1` 638 | ;; 639 | '/bin/ps') 640 | TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1` 641 | COUNT=`echo $TRUNCATED_CMD | wc -m` 642 | COUNT=`echo ${COUNT}` 643 | COUNT=`expr $COUNT - 1` 644 | TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT` 645 | pidtest=`$PSEXE -o comm -p $pid | grep "$TRUNCATED_CMD" | tail -1` 646 | ;; 647 | *) 648 | echo "Unsupported ps command $PSEXE" 649 | exit 1 650 | ;; 651 | esac 652 | fi 653 | ;; 654 | 'hpux') 655 | pidtest=`$PSEXE -p $pid -x -o args | grep "$WRAPPER_CMD" | tail -1` 656 | ;; 657 | *) 658 | pidtest=`$PSEXE -p $pid -o args | grep "$WRAPPER_CMD" | tail -1` 659 | ;; 660 | esac 661 | 662 | if [ "X$pidtest" = "X" ] 663 | then 664 | # This is a stale pid file. 665 | rm -f "$PIDFILE" 666 | eval echo 'Removed stale pid file: $PIDFILE' 667 | pid="" 668 | fi 669 | fi 670 | else 671 | eval echo 'Cannot read $PIDFILE.' 672 | exit 1 673 | fi 674 | fi 675 | } 676 | 677 | getstatus() { 678 | STATUS= 679 | if [ -f "$STATUSFILE" ] 680 | then 681 | if [ -r "$STATUSFILE" ] 682 | then 683 | STATUS=`cat "$STATUSFILE"` 684 | fi 685 | fi 686 | if [ "X$STATUS" = "X" ] 687 | then 688 | STATUS="Unknown" 689 | fi 690 | 691 | JAVASTATUS= 692 | if [ -f "$JAVASTATUSFILE" ] 693 | then 694 | if [ -r "$JAVASTATUSFILE" ] 695 | then 696 | JAVASTATUS=`cat "$JAVASTATUSFILE"` 697 | fi 698 | fi 699 | if [ "X$JAVASTATUS" = "X" ] 700 | then 701 | JAVASTATUS="Unknown" 702 | fi 703 | } 704 | 705 | testpid() { 706 | case "$DIST_OS" in 707 | 'solaris') 708 | case "$PSEXE" in 709 | '/usr/ucb/ps') 710 | pid=`$PSEXE $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 711 | ;; 712 | '/usr/bin/ps') 713 | pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 714 | ;; 715 | '/bin/ps') 716 | pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 717 | ;; 718 | *) 719 | echo "Unsupported ps command $PSEXE" 720 | exit 1 721 | ;; 722 | esac 723 | ;; 724 | *) 725 | pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 2>/dev/null 726 | ;; 727 | esac 728 | if [ "X$pid" = "X" ] 729 | then 730 | # Process is gone so remove the pid file. 731 | rm -f "$PIDFILE" 732 | pid="" 733 | fi 734 | } 735 | 736 | launchdtrap() { 737 | stopit 738 | exit 739 | } 740 | 741 | waitforwrapperstop() { 742 | getpid 743 | while [ "X$pid" != "X" ] ; do 744 | sleep 1 745 | getpid 746 | done 747 | } 748 | 749 | launchdinternal() { 750 | getpid 751 | trap launchdtrap TERM 752 | if [ "X$pid" = "X" ] 753 | then 754 | prepAdditionalParams "$@" 755 | 756 | # The string passed to eval must handles spaces in paths correctly. 757 | COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $COMMANDPROP $LOCKPROP $ADDITIONAL_PARA" 758 | eval $COMMAND_LINE 759 | else 760 | eval echo '$APP_LONG_NAME is already running.' 761 | exit 1 762 | fi 763 | # launchd expects that this script stay up and running so we need to do our own monitoring of the Wrapper process. 764 | if [ $WAIT_FOR_STARTED_STATUS = true ] 765 | then 766 | waitforwrapperstop 767 | fi 768 | } 769 | 770 | console() { 771 | eval echo 'Running $APP_LONG_NAME...' 772 | getpid 773 | if [ "X$pid" = "X" ] 774 | then 775 | trap '' 3 776 | 777 | prepAdditionalParams "$@" 778 | 779 | # The string passed to eval must handles spaces in paths correctly. 780 | COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" $ANCHORPROP $STATUSPROP $COMMANDPROP $LOCKPROP $ADDITIONAL_PARA" 781 | eval $COMMAND_LINE 782 | else 783 | eval echo '$APP_LONG_NAME is already running.' 784 | exit 1 785 | fi 786 | } 787 | 788 | waitforjavastartup() { 789 | getstatus 790 | eval echo $ECHOOPT `gettext 'Waiting for $APP_LONG_NAME...'` 791 | 792 | # Wait until the timeout or we have something besides Unknown. 793 | counter=15 794 | while [ "$JAVASTATUS" = "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do 795 | echo $ECHOOPT"." 796 | sleep 1 797 | getstatus 798 | counter=`expr $counter - 1` 799 | done 800 | 801 | if [ -n "$WAIT_FOR_STARTED_TIMEOUT" ] ; then 802 | counter=$WAIT_FOR_STARTED_TIMEOUT 803 | else 804 | counter=120 805 | fi 806 | while [ "$JAVASTATUS" != "STARTED" -a "$JAVASTATUS" != "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do 807 | echo $ECHOOPT"." 808 | sleep 1 809 | getstatus 810 | counter=`expr $counter - 1` 811 | done 812 | if [ "X$ECHOOPT" != "X" ] ; then 813 | echo "" 814 | fi 815 | } 816 | 817 | startwait() { 818 | if [ $WAIT_FOR_STARTED_STATUS = true ] 819 | then 820 | waitforjavastartup 821 | fi 822 | # Sleep for a few seconds to allow for intialization if required 823 | # then test to make sure we're still running. 824 | # 825 | i=0 826 | while [ $i -lt $WAIT_AFTER_STARTUP ] 827 | do 828 | sleep 1 829 | echo $ECHOOPT"." 830 | i=`expr $i + 1` 831 | done 832 | if [ $WAIT_AFTER_STARTUP -gt 0 -o $WAIT_FOR_STARTED_STATUS = true ] 833 | then 834 | getpid 835 | if [ "X$pid" = "X" ] 836 | then 837 | eval echo ' WARNING: $APP_LONG_NAME may have failed to start.' 838 | exit 1 839 | else 840 | eval echo ' running: PID:$pid' 841 | fi 842 | else 843 | echo "" 844 | fi 845 | } 846 | 847 | macosxstart() { 848 | # The daemon has been installed. 849 | eval echo 'Starting $APP_LONG_NAME. Detected Mac OSX and installed launchd daemon.' 850 | if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then 851 | eval echo 'Must be root to perform this action.' 852 | exit 1 853 | fi 854 | 855 | getpid 856 | if [ "X$pid" != "X" ] ; then 857 | eval echo '$APP_LONG_NAME is already running.' 858 | exit 1 859 | fi 860 | 861 | # If the daemon was just installed, it may not be loaded. 862 | LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}` 863 | if [ "X${LOADED_PLIST}" = "X" ] ; then 864 | launchctl load /Library/LaunchDaemons/${APP_PLIST} 865 | fi 866 | # If launchd is set to run the daemon already at Load, we don't need to call start 867 | getpid 868 | if [ "X$pid" == "X" ] ; then 869 | launchctl start ${APP_PLIST_BASE} 870 | fi 871 | 872 | startwait 873 | } 874 | 875 | start() { 876 | eval echo 'Starting $APP_LONG_NAME...' 877 | getpid 878 | if [ "X$pid" = "X" ] 879 | then 880 | prepAdditionalParams "$@" 881 | 882 | # The string passed to eval must handles spaces in paths correctly. 883 | COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $COMMANDPROP $LOCKPROP $ADDITIONAL_PARA" 884 | eval $COMMAND_LINE 885 | else 886 | eval echo '$APP_LONG_NAME is already running.' 887 | exit 1 888 | fi 889 | 890 | startwait 891 | } 892 | 893 | stopit() { 894 | # $1 exit if down flag 895 | 896 | eval echo 'Stopping $APP_LONG_NAME...' 897 | getpid 898 | if [ "X$pid" = "X" ] 899 | then 900 | eval echo '$APP_LONG_NAME was not running.' 901 | if [ "X$1" = "X1" ] 902 | then 903 | exit 1 904 | fi 905 | else 906 | if [ "X$IGNORE_SIGNALS" = "X" ] 907 | then 908 | # Running so try to stop it. 909 | kill $pid 910 | if [ $? -ne 0 ] 911 | then 912 | # An explanation for the failure should have been given 913 | eval echo 'Unable to stop $APP_LONG_NAME.' 914 | exit 1 915 | fi 916 | else 917 | rm -f "$ANCHORFILE" 918 | if [ -f "$ANCHORFILE" ] 919 | then 920 | # An explanation for the failure should have been given 921 | eval echo 'Unable to stop $APP_LONG_NAME.' 922 | exit 1 923 | fi 924 | fi 925 | 926 | # We can not predict how long it will take for the wrapper to 927 | # actually stop as it depends on settings in wrapper.conf. 928 | # Loop until it does. 929 | savepid=$pid 930 | CNT=0 931 | TOTCNT=0 932 | while [ "X$pid" != "X" ] 933 | do 934 | # Show a waiting message every 5 seconds. 935 | if [ "$CNT" -lt "5" ] 936 | then 937 | CNT=`expr $CNT + 1` 938 | else 939 | eval echo 'Waiting for $APP_LONG_NAME to exit...' 940 | CNT=0 941 | fi 942 | TOTCNT=`expr $TOTCNT + 1` 943 | 944 | sleep 1 945 | 946 | testpid 947 | done 948 | 949 | pid=$savepid 950 | testpid 951 | if [ "X$pid" != "X" ] 952 | then 953 | eval echo 'Failed to stop $APP_LONG_NAME.' 954 | exit 1 955 | else 956 | eval echo 'Stopped $APP_LONG_NAME.' 957 | fi 958 | fi 959 | } 960 | 961 | pause() { 962 | eval echo 'Pausing $APP_LONG_NAME.' 963 | } 964 | 965 | resume() { 966 | eval echo 'Resuming $APP_LONG_NAME.' 967 | } 968 | 969 | status() { 970 | getpid 971 | if [ "X$pid" = "X" ] 972 | then 973 | eval echo '$APP_LONG_NAME is not running.' 974 | exit 1 975 | else 976 | if [ "X$DETAIL_STATUS" = "X" ] 977 | then 978 | eval echo '$APP_LONG_NAME is running: PID:$pid' 979 | else 980 | getstatus 981 | eval echo '$APP_LONG_NAME is running: PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS' 982 | fi 983 | exit 0 984 | fi 985 | } 986 | 987 | installdaemon() { 988 | if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then 989 | eval echo 'Must be root to perform this action.' 990 | exit 1 991 | else 992 | APP_NAME_LOWER=`echo "$APP_NAME" | tr '[A-Z]' '[a-z]'` 993 | if [ "$DIST_OS" = "solaris" ] ; then 994 | eval echo 'Detected Solaris:' 995 | if [ -f /etc/init.d/$APP_NAME ] ; then 996 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 997 | exit 1 998 | else 999 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1000 | ln -s "$REALPATH" "/etc/init.d/$APP_NAME" 1001 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER" 1002 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER" 1003 | fi 1004 | elif [ "$DIST_OS" = "linux" ] ; then 1005 | if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then 1006 | eval echo 'Detected RHEL or Fedora:' 1007 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1008 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1009 | exit 1 1010 | else 1011 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1012 | ln -s "$REALPATH" "/etc/init.d/$APP_NAME" 1013 | /sbin/chkconfig --add "$APP_NAME" 1014 | /sbin/chkconfig "$APP_NAME" on 1015 | fi 1016 | elif [ -f /etc/SuSE-release ] ; then 1017 | eval echo 'Detected SuSE or SLES:' 1018 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1019 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1020 | exit 1 1021 | else 1022 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1023 | ln -s "$REALPATH" "/etc/init.d/$APP_NAME" 1024 | insserv "/etc/init.d/$APP_NAME" 1025 | fi 1026 | elif [ -f /etc/lsb-release ] ; then 1027 | eval echo 'Detected Ubuntu:' 1028 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1029 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1030 | exit 1 1031 | else 1032 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1033 | ln -s "$REALPATH" "/etc/init.d/$APP_NAME" 1034 | update-rc.d "$APP_NAME" defaults 1035 | fi 1036 | else 1037 | eval echo 'Detected Linux:' 1038 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1039 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1040 | exit 1 1041 | else 1042 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1043 | ln -s "$REALPATH" /etc/init.d/$APP_NAME 1044 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER" 1045 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER" 1046 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER" 1047 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/K20$APP_NAME_LOWER" 1048 | fi 1049 | fi 1050 | elif [ "$DIST_OS" = "hpux" ] ; then 1051 | eval echo 'Detected HP-UX:' 1052 | if [ -f "/sbin/init.d/$APP_NAME" ] ; then 1053 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1054 | exit 1 1055 | else 1056 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1057 | ln -s "$REALPATH" "/sbin/init.d/$APP_NAME" 1058 | ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/K20$APP_NAME_LOWER" 1059 | ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/S20$APP_NAME_LOWER" 1060 | fi 1061 | elif [ "$DIST_OS" = "aix" ] ; then 1062 | eval echo 'Detected AIX:' 1063 | if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then 1064 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1065 | exit 1 1066 | else 1067 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1068 | ln -s "$REALPATH" /etc/rc.d/init.d/$APP_NAME 1069 | ln -s "/etc/rc.d/init.d/$APP_NAME" "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER" 1070 | ln -s "/etc/rc.d/init.d/$APP_NAME" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER" 1071 | fi 1072 | elif [ "$DIST_OS" = "freebsd" ] ; then 1073 | eval echo 'Detected FreeBSD:' 1074 | if [ -f "/etc/rc.d/$APP_NAME" ] ; then 1075 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1076 | exit 1 1077 | else 1078 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1079 | sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf 1080 | if [ -f "${REALDIR}/${APP_NAME}.install" ] ; then 1081 | ln -s "${REALDIR}/${APP_NAME}.install" "/etc/rc.d/$APP_NAME" 1082 | else 1083 | echo '#!/bin/sh' > "/etc/rc.d/$APP_NAME" 1084 | echo "#" >> "/etc/rc.d/$APP_NAME" 1085 | echo "# PROVIDE: $APP_NAME" >> "/etc/rc.d/$APP_NAME" 1086 | echo "# REQUIRE: NETWORKING" >> "/etc/rc.d/$APP_NAME" 1087 | echo "# KEYWORD: shutdown" >> "/etc/rc.d/$APP_NAME" 1088 | echo ". /etc/rc.subr" >> "/etc/rc.d/$APP_NAME" 1089 | echo "name=\"$APP_NAME\"" >> "/etc/rc.d/$APP_NAME" 1090 | echo "rcvar=\`set_rcvar\`" >> "/etc/rc.d/$APP_NAME" 1091 | echo "command=\"${REALDIR}/${APP_NAME}\"" >> "/etc/rc.d/$APP_NAME" 1092 | echo 'start_cmd="${name}_start"' >> "/etc/rc.d/$APP_NAME" 1093 | echo 'load_rc_config $name' >> "/etc/rc.d/$APP_NAME" 1094 | echo 'status_cmd="${name}_status"' >> "/etc/rc.d/$APP_NAME" 1095 | echo 'stop_cmd="${name}_stop"' >> "/etc/rc.d/$APP_NAME" 1096 | echo "${APP_NAME}_status() {" >> "/etc/rc.d/$APP_NAME" 1097 | echo '${command} status' >> "/etc/rc.d/$APP_NAME" 1098 | echo '}' >> "/etc/rc.d/$APP_NAME" 1099 | echo "${APP_NAME}_stop() {" >> "/etc/rc.d/$APP_NAME" 1100 | echo '${command} stop' >> "/etc/rc.d/$APP_NAME" 1101 | echo '}' >> "/etc/rc.d/$APP_NAME" 1102 | echo "${APP_NAME}_start() {" >> "/etc/rc.d/$APP_NAME" 1103 | echo '${command} start' >> "/etc/rc.d/$APP_NAME" 1104 | echo '}' >> "/etc/rc.d/$APP_NAME" 1105 | echo 'run_rc_command "$1"' >> "/etc/rc.d/$APP_NAME" 1106 | fi 1107 | echo "${APP_NAME}_enable=\"YES\"" >> /etc/rc.conf 1108 | chmod 555 "/etc/rc.d/$APP_NAME" 1109 | fi 1110 | elif [ "$DIST_OS" = "macosx" ] ; then 1111 | eval echo 'Detected Mac OSX:' 1112 | if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then 1113 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1114 | exit 1 1115 | else 1116 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1117 | if [ -f "${REALDIR}/${APP_PLIST}" ] ; then 1118 | ln -s "${REALDIR}/${APP_PLIST}" "/Library/LaunchDaemons/${APP_PLIST}" 1119 | else 1120 | echo "" > "/Library/LaunchDaemons/${APP_PLIST}" 1121 | echo "> "/Library/LaunchDaemons/${APP_PLIST}" 1122 | echo "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" >> "/Library/LaunchDaemons/${APP_PLIST}" 1123 | echo "" >> "/Library/LaunchDaemons/${APP_PLIST}" 1124 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}" 1125 | echo " Label" >> "/Library/LaunchDaemons/${APP_PLIST}" 1126 | echo " ${APP_PLIST_BASE}" >> "/Library/LaunchDaemons/${APP_PLIST}" 1127 | echo " ProgramArguments" >> "/Library/LaunchDaemons/${APP_PLIST}" 1128 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}" 1129 | echo " ${REALDIR}/${APP_NAME}" >> "/Library/LaunchDaemons/${APP_PLIST}" 1130 | echo " launchdinternal" >> "/Library/LaunchDaemons/${APP_PLIST}" 1131 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}" 1132 | echo " OnDemand" >> "/Library/LaunchDaemons/${APP_PLIST}" 1133 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}" 1134 | echo " RunAtLoad" >> "/Library/LaunchDaemons/${APP_PLIST}" 1135 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}" 1136 | if [ "X$RUN_AS_USER" != "X" ] ; then 1137 | echo " UserName" >> "/Library/LaunchDaemons/${APP_PLIST}" 1138 | echo " ${RUN_AS_USER}" >> "/Library/LaunchDaemons/${APP_PLIST}" 1139 | fi 1140 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}" 1141 | echo "" >> "/Library/LaunchDaemons/${APP_PLIST}" 1142 | fi 1143 | chmod 555 "/Library/LaunchDaemons/${APP_PLIST}" 1144 | fi 1145 | elif [ "$DIST_OS" = "zos" ] ; then 1146 | eval echo 'Detected z/OS:' 1147 | if [ -f /etc/rc.bak ] ; then 1148 | eval echo ' The $APP_LONG_NAME daemon is already installed.' 1149 | exit 1 1150 | else 1151 | eval echo ' Installing the $APP_LONG_NAME daemon..' 1152 | cp /etc/rc /etc/rc.bak 1153 | sed "s:echo /etc/rc script executed, \`date\`::g" /etc/rc.bak > /etc/rc 1154 | echo "_BPX_JOBNAME='${APP_NAME}' \"${REALDIR}/${APP_NAME}\" start" >>/etc/rc 1155 | echo '/etc/rc script executed, `date`' >>/etc/rc 1156 | fi 1157 | else 1158 | eval echo 'Install not currently supported for $DIST_OS' 1159 | exit 1 1160 | fi 1161 | fi 1162 | } 1163 | 1164 | removedaemon() { 1165 | if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then 1166 | eval echo 'Must be root to perform this action.' 1167 | exit 1 1168 | else 1169 | stopit "0" 1170 | APP_NAME_LOWER=`echo "$APP_NAME" | tr '[A-Z]' '[a-z]'` 1171 | if [ "$DIST_OS" = "solaris" ] ; then 1172 | eval echo 'Detected Solaris:' 1173 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1174 | eval echo ' Removing $APP_LONG_NAME daemon...' 1175 | for i in "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME" 1176 | do 1177 | rm -f $i 1178 | done 1179 | else 1180 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1181 | exit 1 1182 | fi 1183 | elif [ "$DIST_OS" = "linux" ] ; then 1184 | if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then 1185 | eval echo 'Detected RHEL or Fedora:' 1186 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1187 | eval echo ' Removing $APP_LONG_NAME daemon...' 1188 | /sbin/chkconfig "$APP_NAME" off 1189 | /sbin/chkconfig --del "$APP_NAME" 1190 | rm -f "/etc/init.d/$APP_NAME" 1191 | else 1192 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1193 | exit 1 1194 | fi 1195 | elif [ -f /etc/SuSE-release ] ; then 1196 | eval echo 'Detected SuSE or SLES:' 1197 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1198 | eval echo ' Removing $APP_LONG_NAME daemon...' 1199 | insserv -r "/etc/init.d/$APP_NAME" 1200 | rm -f "/etc/init.d/$APP_NAME" 1201 | else 1202 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1203 | exit 1 1204 | fi 1205 | elif [ -f /etc/lsb-release ] ; then 1206 | eval echo 'Detected Ubuntu:' 1207 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1208 | eval echo ' Removing $APP_LONG_NAME daemon...' 1209 | update-rc.d -f "$APP_NAME" remove 1210 | rm -f "/etc/init.d/$APP_NAME" 1211 | else 1212 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1213 | exit 1 1214 | fi 1215 | else 1216 | eval echo 'Detected Linux:' 1217 | if [ -f "/etc/init.d/$APP_NAME" ] ; then 1218 | eval echo ' Removing $APP_LONG_NAME daemon...' 1219 | for i in "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/rc5.d/K20$APP_NAME_LOWER" "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER" 1220 | do 1221 | rm -f $i 1222 | done 1223 | else 1224 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1225 | exit 1 1226 | fi 1227 | fi 1228 | elif [ "$DIST_OS" = "hpux" ] ; then 1229 | eval echo 'Detected HP-UX:' 1230 | if [ -f "/sbin/init.d/$APP_NAME" ] ; then 1231 | eval echo ' Removing $APP_LONG_NAME daemon...' 1232 | for i in "/sbin/rc3.d/K20$APP_NAME_LOWER" "/sbin/rc3.d/S20$APP_NAME_LOWER" "/sbin/init.d/$APP_NAME" 1233 | do 1234 | rm -f $i 1235 | done 1236 | else 1237 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1238 | exit 1 1239 | fi 1240 | elif [ "$DIST_OS" = "aix" ] ; then 1241 | eval echo 'Detected AIX:' 1242 | if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then 1243 | eval echo ' Removing $APP_LONG_NAME daemon...' 1244 | for i in "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER" "/etc/rc.d/init.d/$APP_NAME" 1245 | do 1246 | rm -f $i 1247 | done 1248 | else 1249 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1250 | exit 1 1251 | fi 1252 | elif [ "$DIST_OS" = "freebsd" ] ; then 1253 | eval echo 'Detected FreeBSD:' 1254 | if [ -f "/etc/rc.d/$APP_NAME" ] ; then 1255 | eval echo ' Removing $APP_LONG_NAME daemon...' 1256 | for i in "/etc/rc.d/$APP_NAME" 1257 | do 1258 | rm -f $i 1259 | done 1260 | sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf 1261 | else 1262 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1263 | exit 1 1264 | fi 1265 | elif [ "$DIST_OS" = "macosx" ] ; then 1266 | eval echo 'Detected Mac OSX:' 1267 | if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then 1268 | eval echo ' Removing $APP_LONG_NAME daemon...' 1269 | # Make sure the plist is installed 1270 | LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}` 1271 | if [ "X${LOADED_PLIST}" != "X" ] ; then 1272 | launchctl unload "/Library/LaunchDaemons/${APP_PLIST}" 1273 | fi 1274 | rm -f "/Library/LaunchDaemons/${APP_PLIST}" 1275 | else 1276 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1277 | exit 1 1278 | fi 1279 | elif [ "$DIST_OS" = "zos" ] ; then 1280 | eval echo 'Detected z/OS:' 1281 | if [ -f /etc/rc.bak ] ; then 1282 | eval echo ' Removing $APP_LONG_NAME daemon...' 1283 | cp /etc/rc /etc/rc.bak 1284 | sed "s/_BPX_JOBNAME=\'APP_NAME\'.*//g" /etc/rc.bak > /etc/rc 1285 | rm /etc/rc.bak 1286 | else 1287 | eval echo ' The $APP_LONG_NAME daemon is not currently installed.' 1288 | exit 1 1289 | fi 1290 | else 1291 | eval echo 'Remove not currently supported for $DIST_OS' 1292 | exit 1 1293 | fi 1294 | fi 1295 | } 1296 | 1297 | dump() { 1298 | eval echo 'Dumping $APP_LONG_NAME...' 1299 | getpid 1300 | if [ "X$pid" = "X" ] 1301 | then 1302 | eval echo '$APP_LONG_NAME was not running.' 1303 | else 1304 | kill -3 $pid 1305 | 1306 | if [ $? -ne 0 ] 1307 | then 1308 | eval echo 'Failed to dump $APP_LONG_NAME.' 1309 | exit 1 1310 | else 1311 | eval echo 'Dumped $APP_LONG_NAME.' 1312 | fi 1313 | fi 1314 | } 1315 | 1316 | # Used by HP-UX init scripts. 1317 | startmsg() { 1318 | getpid 1319 | if [ "X$pid" = "X" ] 1320 | then 1321 | eval echo 'Starting $APP_LONG_NAME... Wrapper:Stopped' 1322 | else 1323 | if [ "X$DETAIL_STATUS" = "X" ] 1324 | then 1325 | eval echo 'Starting $APP_LONG_NAME... Wrapper:Running' 1326 | else 1327 | getstatus 1328 | eval echo 'Starting $APP_LONG_NAME... Wrapper:$STATUS, Java:$JAVASTATUS' 1329 | fi 1330 | fi 1331 | } 1332 | 1333 | # Used by HP-UX init scripts. 1334 | stopmsg() { 1335 | getpid 1336 | if [ "X$pid" = "X" ] 1337 | then 1338 | eval echo 'Stopping $APP_LONG_NAME... Wrapper:Stopped' 1339 | else 1340 | if [ "X$DETAIL_STATUS" = "X" ] 1341 | then 1342 | eval echo 'Stopping $APP_LONG_NAME... Wrapper:Running' 1343 | else 1344 | getstatus 1345 | eval echo 'Stopping $APP_LONG_NAME... Wrapper:$STATUS, Java:$JAVASTATUS' 1346 | fi 1347 | fi 1348 | } 1349 | 1350 | showUsage() { 1351 | # $1 bad command 1352 | 1353 | if [ -n "$1" ] 1354 | then 1355 | eval echo 'Unexpected command: $1' 1356 | echo ""; 1357 | fi 1358 | 1359 | eval MSG=`gettext 'Usage: '` 1360 | if [ -n "$FIXED_COMMAND" ] ; then 1361 | if [ -n "$PASS_THROUGH" ] ; then 1362 | echo "${MSG} $0 {JavaAppArgs}" 1363 | else 1364 | echo "${MSG} $0" 1365 | fi 1366 | else 1367 | if [ -n "$PAUSABLE" ] ; then 1368 | if [ -n "$PASS_THROUGH" ] ; then 1369 | echo "${MSG} $0 [ console {JavaAppArgs} | start {JavaAppArgs} | stop | restart {JavaAppArgs} | condrestart {JavaAppArgs} | pause | resume | status | install | remove | dump ]" 1370 | else 1371 | echo "${MSG} $0 [ console | start | stop | restart | condrestart | pause | resume | status | install | remove | dump ]" 1372 | fi 1373 | else 1374 | if [ -n "$PASS_THROUGH" ] ; then 1375 | echo "${MSG} $0 [ console {JavaAppArgs} | start {JavaAppArgs} | stop | restart {JavaAppArgs} | condrestart {JavaAppArgs} | status | install | remove | dump ]" 1376 | else 1377 | echo "${MSG} $0 [ console | start | stop | restart | condrestart | status | install | remove | dump ]" 1378 | fi 1379 | fi 1380 | fi 1381 | 1382 | if [ ! -n "$BRIEF_USAGE" ] 1383 | then 1384 | echo ""; 1385 | if [ ! -n "$FIXED_COMMAND" ] ; then 1386 | echo "`gettext 'Commands:'`" 1387 | echo "`gettext ' console Launch in the current console.'`" 1388 | echo "`gettext ' start Start in the background as a daemon process.'`" 1389 | echo "`gettext ' stop Stop if running as a daemon or in another console.'`" 1390 | echo "`gettext ' restart Stop if running and then start.'`" 1391 | echo "`gettext ' condrestart Restart only if already running.'`" 1392 | if [ -n "$PAUSABLE" ] ; then 1393 | echo "`gettext ' pause Pause if running.'`" 1394 | echo "`gettext ' resume Resume if paused.'`" 1395 | fi 1396 | echo "`gettext ' status Query the current status.'`" 1397 | echo "`gettext ' install Install to start automatically when system boots.'`" 1398 | echo "`gettext ' remove Uninstall.'`" 1399 | echo "`gettext ' dump Request a Java thread dump if running.'`" 1400 | echo ""; 1401 | fi 1402 | if [ -n "$PASS_THROUGH" ] ; then 1403 | echo "`gettext 'JavaAppArgs: Zero or more arguments which will be passed to the Java application.'`" 1404 | echo ""; 1405 | fi 1406 | fi 1407 | 1408 | exit 1 1409 | } 1410 | 1411 | docommand() { 1412 | case "$COMMAND" in 1413 | 'console') 1414 | checkUser touchlock "$@" 1415 | if [ ! -n "$FIXED_COMMAND" ] ; then 1416 | shift 1417 | fi 1418 | console "$@" 1419 | ;; 1420 | 1421 | 'start') 1422 | if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then 1423 | macosxstart 1424 | else 1425 | checkUser touchlock "$@" 1426 | if [ ! -n "$FIXED_COMMAND" ] ; then 1427 | shift 1428 | fi 1429 | start "$@" 1430 | fi 1431 | ;; 1432 | 1433 | 'stop') 1434 | checkUser "" "$COMMAND" 1435 | stopit "0" 1436 | ;; 1437 | 1438 | 'restart') 1439 | checkUser touchlock "$COMMAND" 1440 | if [ ! -n "$FIXED_COMMAND" ] ; then 1441 | shift 1442 | fi 1443 | stopit "0" 1444 | start "$@" 1445 | ;; 1446 | 1447 | 'condrestart') 1448 | checkUser touchlock "$COMMAND" 1449 | if [ ! -n "$FIXED_COMMAND" ] ; then 1450 | shift 1451 | fi 1452 | stopit "1" 1453 | start "$@" 1454 | ;; 1455 | 1456 | 'pause') 1457 | if [ -n "$PAUSABLE" ] 1458 | then 1459 | pause 1460 | else 1461 | showUsage "$COMMAND" 1462 | fi 1463 | ;; 1464 | 1465 | 'resume') 1466 | if [ -n "$PAUSABLE" ] 1467 | then 1468 | resume 1469 | else 1470 | showUsage "$COMMAND" 1471 | fi 1472 | ;; 1473 | 1474 | 'status') 1475 | checkUser "" "$COMMAND" 1476 | status 1477 | ;; 1478 | 1479 | 'install') 1480 | installdaemon 1481 | ;; 1482 | 1483 | 'remove') 1484 | removedaemon 1485 | ;; 1486 | 1487 | 'dump') 1488 | checkUser "" "$COMMAND" 1489 | dump 1490 | ;; 1491 | 1492 | 'start_msg') 1493 | # Internal command called by launchd on HP-UX. 1494 | checkUser "" "$COMMAND" 1495 | startmsg 1496 | ;; 1497 | 1498 | 'stop_msg') 1499 | # Internal command called by launchd on HP-UX. 1500 | checkUser "" "$COMMAND" 1501 | stopmsg 1502 | ;; 1503 | 1504 | 'launchdinternal') 1505 | # Internal command called by launchd on Max OSX. 1506 | # We do not want to call checkUser here as it is handled in the launchd plist file. Doing it here would confuse launchd. 1507 | if [ ! -n "$FIXED_COMMAND" ] ; then 1508 | shift 1509 | fi 1510 | launchdinternal "$@" 1511 | ;; 1512 | 1513 | *) 1514 | showUsage "$COMMAND" 1515 | ;; 1516 | esac 1517 | } 1518 | 1519 | docommand "$@" 1520 | 1521 | exit 0 1522 | -------------------------------------------------------------------------------- /files/limits.conf: -------------------------------------------------------------------------------- 1 | # /etc/security/limits.conf 2 | # 3 | #Each line describes a limit for a user in the form: 4 | # 5 | # 6 | # 7 | #Where: 8 | # can be: 9 | # - an user name 10 | # - a group name, with @group syntax 11 | # - the wildcard *, for default entry 12 | # - the wildcard %, can be also used with %group syntax, 13 | # for maxlogin limit 14 | # - NOTE: group and wildcard limits are not applied to root. 15 | # To apply a limit to the root user, must be 16 | # the literal username root. 17 | # 18 | # can have the two values: 19 | # - "soft" for enforcing the soft limits 20 | # - "hard" for enforcing hard limits 21 | # 22 | # can be one of the following: 23 | # - core - limits the core file size (KB) 24 | # - data - max data size (KB) 25 | # - fsize - maximum filesize (KB) 26 | # - memlock - max locked-in-memory address space (KB) 27 | # - nofile - max number of open files 28 | # - rss - max resident set size (KB) 29 | # - stack - max stack size (KB) 30 | # - cpu - max CPU time (MIN) 31 | # - nproc - max number of processes 32 | # - as - address space limit (KB) 33 | # - maxlogins - max number of logins for this user 34 | # - maxsyslogins - max number of logins on the system 35 | # - priority - the priority to run user process with 36 | # - locks - max number of file locks the user can hold 37 | # - sigpending - max number of pending signals 38 | # - msgqueue - max memory used by POSIX message queues (bytes) 39 | # - nice - max nice priority allowed to raise to values: [-20, 19] 40 | # - rtprio - max realtime priority 41 | # - chroot - change root to directory (Debian-specific) 42 | # 43 | # 44 | # 45 | 46 | #* soft core 0 47 | #root hard core 100000 48 | #* hard rss 10000 49 | #@student hard nproc 20 50 | #@faculty soft nproc 20 51 | #@faculty hard nproc 50 52 | #ftp hard nproc 0 53 | #ftp - chroot /ftp 54 | #@student - maxlogins 4 55 | elasticsearch - nofile 32000 56 | elasticsearch - memlock unlimited 57 | # End of file 58 | -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- 1 | # Class: elasticsearch 2 | # 3 | # This class installs Elasticsearch 4 | # 5 | # Usage: 6 | # include elasticsearch 7 | 8 | class elasticsearch($version = "0.15.2", $xmx = "2048m") { 9 | $esBasename = "elasticsearch" 10 | $esName = "${esBasename}-${version}" 11 | $esFile = "${esName}.tar.gz" 12 | $esServiceName = "${esBasename}-servicewrapper" 13 | $esServiceFile = "${esServiceName}.tar.gz" 14 | $esPath = "${ebs1}/usr/local/${esName}" 15 | $esPathLink = "/usr/local/${esBasename}" 16 | $esDataPath = "${ebs1}/var/lib/${esBasename}" 17 | $esLibPath = "${esDataPath}" 18 | $esLogPath = "${ebs1}/var/log/${esBasename}" 19 | $esXms = "256m" 20 | $esXmx = "${xmx}" 21 | $cluster = "${esBasename}" 22 | $esTCPPortRange = "9300-9399" 23 | $esHTTPPortRange = "9200-9299" 24 | $esUlimitNofile = "32000" 25 | $esUlimitMemlock = "unlimited" 26 | $esPidpath = "/var/run" 27 | $esPidfile = "${esPidpath}/${esBasename}.pid" 28 | $esJarfile = "${esName}.jar" 29 | 30 | # Ensure the elasticsearch user is present 31 | user { "$esBasename": 32 | ensure => "present", 33 | comment => "Elasticsearch user created by puppet", 34 | managehome => true, 35 | shell => "/bin/false", 36 | require => [Package["sun-java6-jre"], lvmconfig[$ebs1]], 37 | uid => 901 38 | } 39 | 40 | file { "/etc/security/limits.d/${esBasename}.conf": 41 | content => template("elasticsearch/elasticsearch.limits.conf.erb"), 42 | ensure => present, 43 | owner => root, 44 | group => root, 45 | } 46 | 47 | # file { "/etc/init/${esBasename}.conf": 48 | # content => template("elasticsearch/upstart.elasticsearch.conf.erb"), 49 | # ensure => present, 50 | # owner => root, 51 | # group => root, 52 | # mode => 644 53 | # } 54 | 55 | exec { "mkdir-ebs-mongohome": 56 | path => "/bin:/usr/bin", 57 | command => "mkdir -p $ebs1/usr/local", 58 | before => File["$esPath"], 59 | require => user["$esBasename"] 60 | } 61 | 62 | # Make sure we have the application path 63 | file { "$esPath": 64 | ensure => directory, 65 | require => User["$esBasename"], 66 | owner => "$esBasename", 67 | group => "$esBasename", 68 | recurse => true 69 | } 70 | 71 | # Temp location 72 | file { "/tmp/$esFile": 73 | source => "puppet:///elasticsearch/$esFile", 74 | require => File["$esPath"], 75 | owner => "$esBasename" 76 | } 77 | 78 | # Remove old files and copy in latest 79 | exec { "elasticsearch-package": 80 | path => "/bin:/usr/bin", 81 | command => "mkdir -p $esPath && tar -xzf /tmp/$esFile -C /tmp && sudo -u$esBasename cp -rf /tmp/$esName/. $esPath/. && rm -rf /tmp/$esBasename*", 82 | unless => "test -f $esPath/bin/elasticsearch", 83 | require => File["/tmp/$esFile"], 84 | notify => Service["$esBasename"], 85 | } 86 | 87 | ## Note: this is a bit hackish, need to stop the old elasticsearch when upgrading 88 | exec { "stop-elasticsearch-version-change": 89 | command => "service elasticsearch stop", 90 | unless => "ps aux | grep ${esName} | grep -v grep", 91 | onlyif => "ps aux | grep ${esBasename} | grep -v grep", 92 | require => Exec["elasticsearch-package"], 93 | notify => Service["$esBasename"] 94 | } 95 | 96 | # Create link to /usr/local/ which will be the current version 97 | file { "$esPathLink": 98 | ensure => link, 99 | target => "$esPath", 100 | require => Exec["stop-elasticsearch-version-change"] 101 | 102 | } 103 | 104 | # Ensure the data path is created 105 | file { "$esDataPath": 106 | ensure => directory, 107 | owner => "$esBasename", 108 | group => "$esBasename", 109 | require => Exec["elasticsearch-package"], 110 | recurse => true 111 | } 112 | 113 | # Ensure the data path is created 114 | file { "/var/lib/${esBasename}": 115 | ensure => link, 116 | target => "${esDataPath}", 117 | require => File["$esDataPath"], 118 | } 119 | 120 | # Ensure the link to the data path is set 121 | file { "$esPath/data": 122 | ensure => link, 123 | force => true, 124 | target => "$esDataPath", 125 | require => File["$esDataPath"] 126 | } 127 | 128 | # Symlink config to /etc 129 | file { "/etc/$esBasename": 130 | ensure => link, 131 | target => "$esPathLink/config", 132 | require => Exec["elasticsearch-package"], 133 | } 134 | 135 | # Apply config template for search 136 | file { "$esPath/config/elasticsearch.yml": 137 | content => template("elasticsearch/elasticsearch.yml.erb"), 138 | require => File["/etc/$esBasename"] 139 | } 140 | 141 | # Stage the Service Package 142 | file { "/tmp/$esServiceFile": 143 | source => "puppet:///elasticsearch/$esServiceFile", 144 | require => Exec["elasticsearch-package"] 145 | } 146 | 147 | # Move the service wrapper into place 148 | exec { "elasticsearch-service": 149 | path => "/bin:/usr/bin", 150 | unless => "test -d $esPath/bin/service/lib", 151 | command => "tar -xzf /tmp/$esServiceFile -C /tmp && mv /tmp/$esServiceName/service $esPath/bin && rm /tmp/$esServiceFile", 152 | require => [file["/tmp/$esServiceFile"], user["$esBasename"]] 153 | } 154 | 155 | # Ensure the service is present 156 | file { "$esPath/bin/service": 157 | ensure => directory, 158 | owner => elasticsearch, 159 | group => elasticsearch, 160 | recurse => true, 161 | require => Exec["elasticsearch-service"] 162 | } 163 | 164 | # Set the service config settings 165 | file { "$esPath/bin/service/elasticsearch.conf": 166 | content => template("elasticsearch/elasticsearch.conf.erb"), 167 | require => file["$esPath/bin/service"] 168 | } 169 | 170 | # Add customized startup script (see: http://www.elasticsearch.org/tutorials/2011/02/22/running-elasticsearch-as-a-non-root-user.html) 171 | file { "$esPath/bin/service/elasticsearch": 172 | source => "puppet:///elasticsearch/elasticsearch", 173 | require => file["$esPath/bin/service"] 174 | } 175 | 176 | # Create startup script 177 | file { "/etc/init.d/elasticsearch": 178 | ensure => link, 179 | target => "$esPath/bin/service/./elasticsearch", 180 | require => [Exec["stop-elasticsearch-version-change"], File["$esPath/bin/service/elasticsearch"]] 181 | } 182 | 183 | # Ensure logging directory 184 | file { "$esLogPath": 185 | owner => "$esBasename", 186 | group => "$esBasename", 187 | ensure => directory, 188 | recurse => true, 189 | require => exec["elasticsearch-package"], 190 | } 191 | 192 | # Ensure logging link is in place 193 | file { "/var/log/$esBasename": 194 | ensure => link, 195 | target => "$esLogPath", 196 | require => [File["${esLogPath}"], File["/etc/init.d/$esBasename"]] 197 | } 198 | 199 | file { "$esPath/logs": 200 | ensure => link, 201 | target => "/var/log/$esBasename", 202 | force => true, 203 | require => File["/var/log/$esBasename"] 204 | } 205 | 206 | # Ensure the service is running 207 | service { "$esBasename": 208 | enable => true, 209 | ensure => running, 210 | hasrestart => true, 211 | require => File["$esPath/logs"] 212 | } 213 | 214 | } -------------------------------------------------------------------------------- /templates/elasticsearch.conf.erb: -------------------------------------------------------------------------------- 1 | set.default.ES_HOME=<%= esPath %> 2 | set.default.ES_MIN_MEM=<%= esXms %> 3 | set.default.ES_MAX_MEM=<%= esXmx %> 4 | 5 | #******************************************************************** 6 | # Wrapper Timeout Properties 7 | #******************************************************************** 8 | # How long to wait for the JVM to start (in seconds) 9 | wrapper.startup.timeout=300 10 | # How long to wait for the JVM to stop (in seconds) 11 | wrapper.shutdown.timeout=300 12 | # When a ping will timeout to consider the JVM hung (in seconds) 13 | wrapper.ping.timeout=300 14 | 15 | #******************************************************************** 16 | # Wrapper Java Properties 17 | #******************************************************************** 18 | # Java Application 19 | wrapper.java.command=java 20 | 21 | # Tell the Wrapper to log the full generated Java command line. 22 | #wrapper.java.command.loglevel=INFO 23 | 24 | wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp 25 | 26 | wrapper.working.dir=%ES_HOME% 27 | 28 | # Java Classpath (include wrapper.jar) Add class path elements as 29 | # needed starting from 1 30 | wrapper.java.classpath.1=%ES_HOME%/bin/service/lib/wrapper.jar 31 | wrapper.java.classpath.2=%ES_HOME%/lib/*.jar 32 | wrapper.java.classpath.3=%ES_HOME%/lib/sigar/*.jar 33 | 34 | # Java Library Path (location of Wrapper.DLL or libwrapper.so) 35 | wrapper.java.library.path.1=%ES_HOME%/bin/service/lib 36 | 37 | # Java Bits. On applicable platforms, tells the JVM to run in 32 or 64-bit mode. 38 | wrapper.java.additional.auto_bits=TRUE 39 | 40 | # Java Additional Parameters 41 | wrapper.java.additional.1=-Delasticsearch-service 42 | wrapper.java.additional.2=-Des-foreground=yes 43 | wrapper.java.additional.3=-Des.path.home=%ES_HOME% 44 | wrapper.java.additional.4=-Djline.enabled=true 45 | wrapper.java.additional.5=-XX:+UseParNewGC 46 | wrapper.java.additional.6=-XX:+UseConcMarkSweepGC 47 | wrapper.java.additional.7=-XX:+CMSParallelRemarkEnabled 48 | wrapper.java.additional.8=-XX:SurvivorRatio=8 49 | wrapper.java.additional.9=-XX:MaxTenuringThreshold=1 50 | wrapper.java.additional.10=-XX:CMSInitiatingOccupancyFraction=75 51 | wrapper.java.additional.11=-XX:+UseCMSInitiatingOccupancyOnly 52 | wrapper.java.additional.12=-XX:+HeapDumpOnOutOfMemoryError 53 | # wrapper.java.additional.13=-XX:+AggressiveOpts 54 | 55 | # Initial Java Heap Size (in MB) 56 | wrapper.java.initmemory=%ES_MIN_MEM% 57 | 58 | # Maximum Java Heap Size (in MB) 59 | wrapper.java.maxmemory=%ES_MAX_MEM% 60 | 61 | # Application parameters. Add parameters as needed starting from 1 62 | wrapper.app.parameter.1=org.elasticsearch.bootstrap.Bootstrap 63 | 64 | #******************************************************************** 65 | # Wrapper Logging Properties 66 | #******************************************************************** 67 | # Enables Debug output from the Wrapper. 68 | # wrapper.debug=TRUE 69 | 70 | # Format of output for the console. (See docs for formats) 71 | wrapper.console.format=PM 72 | 73 | # Log Level for console output. (See docs for log levels) 74 | wrapper.console.loglevel=INFO 75 | 76 | # Log file to use for wrapper output logging. 77 | wrapper.logfile=%ES_HOME%/work/logs/service.log 78 | 79 | # Format of output for the log file. (See docs for formats) 80 | wrapper.logfile.format=LPTM 81 | 82 | # Log Level for log file output. (See docs for log levels) 83 | wrapper.logfile.loglevel=INFO 84 | 85 | # Maximum size that the log file will be allowed to grow to before 86 | # the log is rolled. Size is specified in bytes. The default value 87 | # of 0, disables log rolling. May abbreviate with the 'k' (kb) or 88 | # 'm' (mb) suffix. For example: 10m = 10 megabytes. 89 | wrapper.logfile.maxsize=0 90 | 91 | # Maximum number of rolled log files which will be allowed before old 92 | # files are deleted. The default value of 0 implies no limit. 93 | wrapper.logfile.maxfiles=0 94 | 95 | # Log Level for sys/event log output. (See docs for log levels) 96 | wrapper.syslog.loglevel=NONE 97 | 98 | #******************************************************************** 99 | # Wrapper General Properties 100 | #******************************************************************** 101 | # Allow for the use of non-contiguous numbered properties 102 | wrapper.ignore_sequence_gaps=TRUE 103 | 104 | # Title to use when running as a console 105 | wrapper.console.title=ElasticSearch 106 | 107 | #******************************************************************** 108 | # Wrapper Windows NT/2000/XP Service Properties 109 | #******************************************************************** 110 | # WARNING - Do not modify any of these properties when an application 111 | # using this configuration file has been installed as a service. 112 | # Please uninstall the service before modifying this section. The 113 | # service can then be reinstalled. 114 | 115 | # Name of the service 116 | wrapper.name=ElasticSearch 117 | 118 | # Display name of the service 119 | wrapper.displayname=ElasticSearch 120 | 121 | # Description of the service 122 | wrapper.description=Open Source, Distributed, RESTful Search Engine 123 | 124 | # Service dependencies. Add dependencies as needed starting from 1 125 | wrapper.ntservice.dependency.1= 126 | 127 | # Mode in which the service is installed. AUTO_START, DELAY_START or DEMAND_START 128 | wrapper.ntservice.starttype=AUTO_START 129 | 130 | # Allow the service to interact with the desktop. 131 | wrapper.ntservice.interactive=false 132 | 133 | -------------------------------------------------------------------------------- /templates/elasticsearch.limits.conf.erb: -------------------------------------------------------------------------------- 1 | <%= esBasename %> - nofile <%= esUlimitNofile %> 2 | <%= esBasename %> - memlock <%= esUlimitMemlock %> 3 | <%= esBasename %> - core 0 4 | -------------------------------------------------------------------------------- /templates/elasticsearch.yml.erb: -------------------------------------------------------------------------------- 1 | # Managed by Puppet, DO NOT TOUCH! 2 | 3 | transport: 4 | tcp: 5 | port: <%= esTCPPortRange %> 6 | 7 | http: 8 | port: <%= esHTTPPortRange %> 9 | 10 | cluster: 11 | name: "<%= cluster %>" 12 | 13 | path: 14 | logs: <%= esLogPath %> 15 | data: <%= esDataPath %> 16 | 17 | boostrap: 18 | mlockall: true -------------------------------------------------------------------------------- /templates/upstart.elasticsearch.conf.erb: -------------------------------------------------------------------------------- 1 | # managed by puppet! 2 | 3 | start on startup 4 | start on runlevel [2345] 5 | stop on runlevel [06] 6 | 7 | env ES_HOME=<%= esPath %> 8 | env ES_CLASSPATH=<%= esJarfile -%>:<%= esLibPath -%>/* 9 | 10 | script 11 | JAVA=<%= jre6JavaHome %> 12 | 13 | JAVA_OPTS="$JAVA_OPTS -Xms<%= esXms %>" 14 | JAVA_OPTS="$JAVA_OPTS -Xmx<%= esXmx %>" 15 | 16 | # reduce the per-thread stack size 17 | JAVA_OPTS="$JAVA_OPTS -Xss128k" 18 | 19 | JAVA_OPTS="$JAVA_OPTS -Djline.enabled=true" 20 | 21 | # Enable reference compression, reducing memory overhead on 64bit JVMs 22 | JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedOops" 23 | 24 | JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC" 25 | JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC" 26 | JAVA_OPTS="$JAVA_OPTS -XX:+CMSParallelRemarkEnabled" 27 | JAVA_OPTS="$JAVA_OPTS -XX:SurvivorRatio=8" 28 | JAVA_OPTS="$JAVA_OPTS -XX:MaxTenuringThreshold=1" 29 | JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75" 30 | JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly" 31 | 32 | # GC logging options -- uncomment to enable 33 | # JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails" 34 | # JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps" 35 | # JAVA_OPTS="$JAVA_OPTS -XX:+PrintClassHistogram" 36 | # JAVA_OPTS="$JAVA_OPTS -XX:+PrintTenuringDistribution" 37 | # JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime" 38 | # JAVA_OPTS="$JAVA_OPTS -Xloggc:/var/log/elasticsearch/gc.log" 39 | 40 | # Causes the JVM to dump its heap on OutOfMemory. 41 | #JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError" 42 | # The path to the heap dump location, note directory must exists and have enough 43 | # space for a full heap dump. 44 | #JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=$ES_HOME/logs/heapdump.hprof" 45 | 46 | es_parms="-Delasticsearch -Des.path.home=$ES_HOME -Des-pidfile=<%= esPidfile %> -Des-daemon=yes" 47 | start-stop-daemon --start --quiet --pidfile <%= esPidfile %> --chdir <%= esPath %> --chuid <%= esBasename %>:<% esBasename %> --exec $JAVA -- $JAVA_OPTS $es_parms -cp $ES_CLASSPATH org.elasticsearch.bootstrap.ElasticSearch 48 | end script 49 | --------------------------------------------------------------------------------