-
-
Save neogenix/04922c0c3f30be7dcaf8 to your computer and use it in GitHub Desktop.
Pillar, Jinja, Salt, Dictionary, Oh My!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include: | |
- formulas/services/java/oracle-java-7 | |
# Setup base variables via Pillar | |
{% set base = pillar['twinkie-consumers']['setup']['base'] %} | |
{% set user = pillar['twinkie-consumers']['setup']['user'] %} | |
{% set uid = pillar['twinkie-consumers']['setup']['uid'] %} | |
{% set group = pillar['twinkie-consumers']['setup']['group'] %} | |
{% set gid = pillar['twinkie-consumers']['setup']['gid'] %} | |
{% set shell = pillar['twinkie-consumers']['setup']['shell'] %} | |
{% set mode = pillar['twinkie-consumers']['setup']['mode'] %} | |
{% set doomsday = pillar['twinkie-consumers']['setup']['doomsday'] %} | |
{% set consumers = pillar['twinkie-consumers']['consumers'] %} | |
twinkie-user: | |
group: | |
- present | |
- name: {{ group }} | |
- gid: {{ gid }} | |
user: | |
- present | |
- name: {{ user }} | |
- uid: {{ uid }} | |
- gid: {{ gid }} | |
- shell: {{ shell }} | |
- home: {{ base }} | |
- createhome: False | |
- require: | |
- group: twinkie-user | |
file: | |
- directory | |
- name: {{ base }} | |
- user: {{ user }} | |
- group: {{ group }} | |
- mode: {{ mode }} | |
- makedirs: true | |
- require: | |
- user: twinkie-user | |
- recurse: | |
- user | |
- group | |
- mode | |
twinkie-doomsday: | |
file: | |
- directory | |
- name: {{ doomsday }} | |
- user: {{ user }} | |
- group: {{ group }} | |
- require: | |
- file: twinkie-user | |
# Start loop for consumers | |
{% for consumer in consumers %} | |
twinkie-{{ consumer }}-dir: | |
file: | |
- directory | |
- name: {{ base }}/{{ consumer }} | |
- user: {{ user }} | |
- group: {{ group }} | |
- mode: {{ mode }} | |
- recurse: | |
- user | |
- group | |
- mode | |
- require: | |
- user: twinkie-user | |
twinkie-{{ consumer }}-service: | |
file: | |
- managed | |
- name: /etc/init.d/twinkie-{{ consumer }} | |
- source: salt://formulas/services/twinkie-consumers/files/service.jinja | |
- template: jinja | |
- defaults: | |
consumer: {{ consumer }} | |
service: | |
- running | |
- enable: True | |
- name: twinkie-{{ consumer }} | |
- require: | |
- file: twinkie-{{ consumer }}-service | |
- file: twinkie-{{ consumer }}-dir | |
- watch: | |
- file: twinkie-{{ consumer }}-service | |
{% endfor %} | |
# vim: syntax=yaml ts=4 sts=4 sw=4 expandtab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twinkie-consumers: | |
setup: | |
user: 'twinkie' | |
group: 'twinkie' | |
uid: '10033' | |
gid: '10033' | |
shell: '/bin/bash' | |
mode: '755' | |
base: '/opt/twinkie' | |
doomsday: '/opt/twinkie/doomsday' | |
consumers: | |
twinkie-result-consumer: | |
version: '316' | |
broker-url: moo | |
broker-port: 61617 | |
queue-name: | |
auth-client-id: | |
auth-secret: | |
auth-access-token-uri: | |
rest-host: | |
rest-port: | |
rest-protocol: http | |
useradmin-jdbc-uri: | |
jdbc-user: | |
jdbc-pass: | |
mail-host: | |
mail-port: | |
test-email-address: | |
hibernate-show-sql: | |
db-fetcher-use-cache: true | |
twinkie-order-email-result-queue-name: | |
local-properties: /opt/twinkie/twinkie-twinkie.properties | |
sprint-properties-active: | |
send-email-for-real: | |
log4j-configuration-file: /opt/cb/twinkie-log4j.xml | |
result-queue-name: | |
send-ipns-for-real: | |
file-encoding: UTF-8 | |
twinkie-send-consumer: | |
version: '316' | |
# vim: syntax=yaml ts=4 sts=4 sw=4 expandtab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# This file is generated by SaltStack, edit at your peril | |
### BEGIN INIT INFO | |
# Provides: twinkie-{{ consumer }} | |
# Required-Start: | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: {{ consumer }} manager daemon | |
# Description: | |
# Clickbank JMS Consumers! | |
### END INIT INFO | |
# Do NOT "set -e" | |
PATH=/sbin:/bin | |
DAEMON=xxxx | |
NAME=twinkie-{{ consumer }} | |
DESC="JMS Consumer - {{ consumer }}" | |
BASEOPTS=" | |
-DbrokerURL=tcp://{{ consumer.broker-url }}:{{ consumer.broker-port }} \ | |
-DqueueName=\"{{ consumer.queue-name }}\" \ | |
-DoauthClientId=\"{{ consumer.auth-client-id }}\" \ | |
-DoauthSecret=\"{{ consumer.auth-secret }}\" \ | |
-DoauthAccessTokenUri=\"{{ consumer.auth-access-token-uri }}\" \ | |
-DrestHost=\"{{ consumer.rest-host }}\" \ | |
-DrestPort=\"{{ consumer.rest-port }}\" \ | |
-DrestProtocol={{ consumer.rest-protocol }} \ | |
-DuseradminJdbcUrl=\"{{ consumer.useradmin-jdbc-uri }}\" \ | |
-DjdbcUser=\"{{ consumer.jdbc-user }}\" \ | |
-DjdbcPassword=\"{{ consumer.jdbc-pass }}\" \ | |
-DmailHost=\"{{ consumer.mail-host }}\" \ | |
-DmailPort={{ consumer.mail-port }} \ | |
-DtestEmailAddress=\"{{ consumer.test-email-address }}\" \ | |
-DhibernateShowSql=\"{{ consumer.hibernate-show-sql }}\" \ | |
-DdbFetcherUseCache={{ consumer.db-fetcher-use-cache }} \ | |
-DtwinkieOrderEmailResultQueueName=\"{{ consumer.twinkie-order-email-result-queue-name }}\" \ | |
-DlocalProperties={{ consumer.local-properties }} \ | |
-Dspring.profiles.active=\"{{ consumer.spring-properties-active }}\" \ | |
-DsendEmailForReal=\"{{ consumer.send-email-for-real }}\" \ | |
-Dlog4j.configurationFile={{ consumer.log4j-configuration-file }} \ | |
-DresultQueueName=\"{{ consumer.result-queue-name }}\" \ | |
-Dfile.encoding=\"{{ consumer.file-encoding }}\" \ | |
-jar /opt/twinkie/{{ consumer }}/{{ consumer }}-current.jar \"xxxxnewrelic\" > /dev/null 2>&1 & | |
" | |
test -x $DAEMON || exit 0 | |
PIDFILE=/run/$NAME.pid | |
# Load the VERBOSE setting and other rcS variables | |
. /lib/init/vars.sh | |
# Define LSB log_* functions. | |
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present | |
# and status_of_proc is working. | |
. /lib/lsb/init-functions | |
DAEMON_ARGS="$BASEOPTS" | |
do_stop() | |
{ | |
# Return | |
# 0 if daemon has been stopped | |
# 1 if daemon was already stopped | |
# 2 if daemon could not be stopped | |
# other if a failure occurred | |
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME | |
RETVAL="$?" | |
[ "$RETVAL" = 2 ] && return 2 | |
# Wait for children to finish too if this is a daemon that forks | |
# and if the daemon is only ever run from this initscript. | |
# If the above conditions are not satisfied then add some other code | |
# that waits for the process to drop all resources that could be | |
# needed by services started subsequently. A last resort is to | |
# sleep for some time. | |
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON | |
[ "$?" = 2 ] && return 2 | |
# Many daemons don't delete their pidfiles when they exit. | |
rm -f $PIDFILE | |
return "$RETVAL" | |
} | |
do_start() | |
{ | |
# Return | |
# 0 if daemon has been started | |
# 1 if daemon was already running | |
# 2 if daemon could not be started | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ | |
|| return 1 | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ | |
$DAEMON_ARGS \ | |
|| return $? | |
sleep 1 | |
} | |
case "$1" in | |
restart|force-reload) | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) | |
do_start | |
case "$?" in | |
0) log_end_msg 0 ;; | |
1) log_end_msg 1 ;; # Old process is still running | |
*) log_end_msg 1 ;; # Failed to start | |
esac | |
;; | |
*) | |
# Failed to stop | |
log_end_msg 1 | |
;; | |
esac | |
;; | |
start) | |
log_daemon_msg "Starting $DESC" "$NAME" | |
do_start | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
stop) | |
log_daemon_msg "Stopping $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
status) | |
status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $? | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|force-reload}" >&2 | |
exit 3 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment