Start the app through the puppet with params based on the fact - java

I have a part in init.pp, that starts my app:
systemd::service {'app':
user => 'java',
exec => "${java_home}/bin/java \
-server \
'-XX:OnOutOfMemoryError=\\'kill -9 %%p\\'' \
-Dmw.config=/etc/app/app.config \
-cp /usr/share/app/app.jar ru.app.main.Main app",
}
The newer version of the app.jar starts differently. There's a way, stop the puppet on the nodes, deregister the node from the consul, start the puppet with the new init.pp, and put that node back to the consul. But that just doesn't feel right.
Is there a way to put some "if" in there so I'd be able to make smooth transitions back and forth depending on my app's version or any other field?

found it
if $app_v2 == 'true' {
systemd::service {'app':
user => 'java',
exec => "${java_home}/bin/java \
-server \
'-XX:OnOutOfMemoryError=\\'kill -9 %%p\\'' \
-Dmw.config=/etc/app/app_new.config \
-cp /usr/share/app/app.jar ru.app.main.App app",
}
} else {
systemd::service {'app':
user => 'java',
exec => "${java_home}/bin/java \
-server \
'-XX:OnOutOfMemoryError=\\'kill -9 %%p\\'' \
-Dmw.config=/etc/app/app.config \
-cp /usr/share/app/app.jar ru.app.main.Main app",
}
}
and for getting app_v2 flag, add to /lib/facter/app_v2.rb
require 'facter'
Facter.add(:app_v2) do
confine :kernel => :Linux
setcode do
result = false
if Facter::Core::Execution.exec('dpkg -l | grep app|awk \'{print$3}\'| cut -c1') == '2'
result = true
end
result
end
end

Related

How to pass space separated value as a single Argument to execute the java code from spark?

ALL,
update
I am trying to execute java code from spark by passing the argument(argument will have space separated value).
e.g.
arg4 = "country='USA' AND state='Newyork'"
my code will be like this:
spark-submit --jars <path>/spark-sql-kafka-0-10_2.11-2.3.0.jar \
--driver-java-options "-Djava.security.auth.login.config=<path>/devjaas.conf" \
--conf "spark.executor.extraJavaOptions=-Djava.security.auth.login.config=./jaas_hdfs_dev.conf" \
--master yarn \
--deploy-mode client \
--files <path>/jaas_hdfs_dev.conf,<credential> \
--executor-memory 10g \
--executor-cores 5 \
--driver-cores=5 \
--driver-memory=10G \
--conf spark.executor.cores=5 \
--conf spark.yarn.am.cores=5 \
--conf spark.yarn.am.memory=15g \
--conf spark.executor.memoryOverhead=4096 \
--class "<java class>" <jar file> $arg1 $arg2 $arg3 $arg4
this is throwing as error because arg4 has space and code is not treat value of arg4 as a single argument. I am executing spark code inside shell script,I have passed all the values to the variable in shell script.
arg1= "first"
arg2="second"
arg3="third"
arg4="country='USA' AND state='Newyork'"
while executing shell script by sh -x , i do see value of arg4 in command line like this
'country='\''USA'\'' AND '\''state=NEWYORK'\'''
How can we handle this problem? can you please help me to solve this problem.
Java treats the set of all words between double quotes (") as one string.
Therefore, using double quotes will allow reading of space-separated list of words as one argument.
Here is a working demo:
// File name: ShowArgs.java
public class ShowArgs {
public static void main (String[] args) {
int count = 0;
for (String s: args) {
count++;
System.out.println("arg # " + count + " : " + s);
}
}
}
Output #1 (Run the program from command line):
$ javac ShowArgs.java
$ java ShowArgs arg1 arg2 arg3 "country='USA' AND state='Newyork'"
arg # 1 : arg1
arg # 2 : arg2
arg # 3 : arg3
arg # 4 : country='USA' AND state='Newyork'
Output #2 (Run the program through shell script)
$ export arg1="Hello!"
$ export arg2="How are you doing"
$ export arg3=", buddy?"
$ export arg4="country='USA' AND state='New York'"
$ java ShowArgs "$arg1" "$arg2" "$arg3" "$arg4"
arg # 1 : Hello!
arg # 2 : How are you doing
arg # 3 : , buddy?
arg # 4 : country='USA' AND state='New York'
We have to pass arguments separated by space to main class, Can you try passing arguments like below.
--class "<java class>" <jar file> arg1 arg2 arg3 "country='USA' AND state='Newyork'"
If you add comma , between arguments main class will treat those arguments as single value till it find space.
Try to put your arguments inside quotes. like below.
--class "<java class>" <jar file> "$arg1" "$arg2" "$arg3" "$arg4"

WEKA quote parse error

While using java "setOptions" function with the bellow properties I am getting an error : "Quote parse error."...
"weka.classifiers.meta.OneClassClassifier -num \"weka.classifiers.meta.generators.GaussianGenerator -S 1 -M 0.0 -SD 1.0\" -nom \"weka.classifiers.meta.generators.NominalGenerator -S 1\" -trr 0.1 -tcl F&B -cvr 10 -cvf 10.0 -P 0.5 -S 1 -W weka.classifiers.meta.Bagging -- -P 100 -S 1 -num-slots 1 -I 10 -W weka.classifiers.trees.REPTree -- -M 2 -V 0.001 -N 3 -S 1 -L -1 -I 0.0"
I understand that this is occurring because of error in applying quotes, but I am not sure as to where they should be applied.
I thought of applying them before calling REPTree but that doesn't seem to work.
Whenever using a Weka classifier with Java code, use the weka.core.Utils.splitOptions method to parse the config string without worrying about quoting and escaping characters.
// set your configurations parameters here, e.g., "-S 1"
String options = "whatever configuration you want";
// instantiate the classifier object
REPTree tree = new REPTree();
// parse and set the classifier's configuration
tree.setOptions(Utils.splitOptions(options));
Also, remember to provide your current code and to format your question.

Concatenate list of paths in bash-script, with colon as separator

I have the following difficult to read script consisting of a single command:
#!/bin/sh
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java \
-classpath /Users/afarber/src/jetty-newbie/EmbeddedWebsocket/target/classes:/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-server/9.3.9.v20160517/jetty-server-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-http/9.3.9.v20160517/jetty-http-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-util/9.3.9.v20160517/jetty-util-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-io/9.3.9.v20160517/jetty-io-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-servlet/9.3.9.v20160517/jetty-servlet-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-security/9.3.9.v20160517/jetty-security-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.3.9.v20160517/websocket-api-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-server/9.3.9.v20160517/websocket-server-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.3.9.v20160517/websocket-common-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.3.9.v20160517/websocket-client-9.3.9.v20160517.jar:/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-servlet/9.3.9.v20160517/websocket-servlet-9.3.9.v20160517.jar \
de.afarber.MyServlet
As slight readability improvement I would like to list all the paths after the -classpath in a separate variable, each aligned after the other:
PATHS= /Users/afarber/src/jetty-newbie/EmbeddedWebsocket/target/classes \
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-server/9.3.9.v20160517/jetty-server-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-http/9.3.9.v20160517/jetty-http-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-util/9.3.9.v20160517/jetty-util-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-io/9.3.9.v20160517/jetty-io-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-servlet/9.3.9.v20160517/jetty-servlet-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-security/9.3.9.v20160517/jetty-security-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.3.9.v20160517/websocket-api-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-server/9.3.9.v20160517/websocket-server-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.3.9.v20160517/websocket-common-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.3.9.v20160517/websocket-client-9.3.9.v20160517.jar \
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-servlet/9.3.9.v20160517/websocket-servlet-9.3.9.v20160517.jar
This way I can easier add and remove the paths, and sort them in Vim.
My question is: how to join them back for my command?
UPDATE:
If all JAR-files would be located in the same dir, I could have used the new Java 8 wildcard syntax java -classpath "/that/dir/*" de.afarber.MyServlet - but that wasn't the case here.
I suggest using heredoc for easy maintenance of this long list of class paths:
#!/bin/bash
# populate array cpath with all the the classpaths each one on different lines
read -d '' -ra cpath<<'EOF'
/Users/afarber/src/jetty-newbie/EmbeddedWebsocket/target/classes
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-server/9.3.9.v20160517/jetty-server-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-http/9.3.9.v20160517/jetty-http-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-util/9.3.9.v20160517/jetty-util-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-io/9.3.9.v20160517/jetty-io-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-servlet/9.3.9.v20160517/jetty-servlet-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/jetty-security/9.3.9.v20160517/jetty-security-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.3.9.v20160517/websocket-api-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-server/9.3.9.v20160517/websocket-server-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.3.9.v20160517/websocket-common-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.3.9.v20160517/websocket-client-9.3.9.v20160517.jar
/Users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-servlet/9.3.9.v20160517/websocket-servlet-9.3.9.v20160517.jar
EOF
# merge them with : as separator in classpath
printf -v classpath "%s:" "${cpath[#]}"
# execute the java command line
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java \
-classpath "${classpath%:}" de.afarber.MyServlet
Since you are using bash, you can store the directory names in an array (with some refactoring just to make this example more readable):
repo=/Users/afarber/.m2/repository
jetty="$repo/org/eclipse/jetty"
websocket="$jetty/websocket"
paths=(
/Users/afarber/src/jetty-newbie/EmbeddedWebsocket/target/classes
"$jetty"/jetty-server/9.3.9.v20160517/jetty-server-9.3.9.v20160517.jar
$repo/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar
"$jetty"/jetty-http/9.3.9.v20160517/jetty-http-9.3.9.v20160517.jar
"$jetty"/jetty-util/9.3.9.v20160517/jetty-util-9.3.9.v20160517.jar
"$jetty"/jetty-io/9.3.9.v20160517/jetty-io-9.3.9.v20160517.jar
"$jetty"/jetty-servlet/9.3.9.v20160517/jetty-servlet-9.3.9.v20160517.jar
"$jetty"/jetty-security/9.3.9.v20160517/jetty-security-9.3.9.v20160517.jar
"$websocket"/websocket-api/9.3.9.v20160517/websocket-api-9.3.9.v20160517.jar
"$websocket"/websocket-server/9.3.9.v20160517/websocket-server-9.3.9.v20160517.jar
"$websocket"/websocket-common/9.3.9.v20160517/websocket-common-9.3.9.v20160517.jar
"$websocket"/websocket-client/9.3.9.v20160517/websocket-client-9.3.9.v20160517.jar
"$websocket"/websocket-servlet/9.3.9.v20160517/websocket-servlet-9.3.9.v20160517.jar
)
Note you don't need to end each line with a backslash; whitespace (including newlines) separate elements of the array. Once you have the array, you can join the elements with a colon using parameter expansion with a modified value of the IFS parameter.
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java \
-classpath "$(IFS=:; echo "${paths[*]}")" de.afarber.MyServlet
A sed should do the trick:
colonPATHS=$(echo "$PATHS" | sed -r 's/\s+/:/g')
echo "$colonPATHS"
The sed turns sequences of whitespace into a ":".
Simple sed can do this
pathwithcolons=`echo $PATHS|sed 's/ \+\\ \+/:/g'`
I've ended up using the following script:
#!/bin/sh
REPO=/Users/afarber/.m2/repository
VERSION=9.3.9.v20160517
CPATHS=/Users/afarber/src/jetty-newbie/WebsocketServlet/target/classes
CPATHS=$CPATHS:$REPO/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/jetty-http/$VERSION/jetty-http-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/jetty-io/$VERSION/jetty-io-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/jetty-security/$VERSION/jetty-security-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/jetty-server/$VERSION/jetty-server-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/jetty-servlet/$VERSION/jetty-servlet-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/jetty-util/$VERSION/jetty-util-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/websocket/websocket-api/$VERSION/websocket-api-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/websocket/websocket-client/$VERSION/websocket-client-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/websocket/websocket-common/$VERSION/websocket-common-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/websocket/websocket-server/$VERSION/websocket-server-$VERSION.jar
CPATHS=$CPATHS:$REPO/org/eclipse/jetty/websocket/websocket-servlet/$VERSION/websocket-servlet-$VERSION.jar
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java \
-classpath $CPATHS de.afarber.MyServlet
I like it better than other solutions, because it does not spawn additional processes (like sed), is easier to read and can be translated to Windows CMD batch file:
#echo off
set REPO="C:\Users\user1\.m2\repository"
set VERSION=9.3.9.v20160517
set CPATHS=C:\Users\user1\jetty-newbie\WebsocketServlet\target\classes
set CPATHS=%CPATHS%;%REPO%\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\jetty-http\%VERSION%\jetty-http-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\jetty-io\%VERSION%\jetty-io-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\jetty-security\%VERSION%\jetty-security-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\jetty-server\%VERSION%\jetty-server-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\jetty-servlet\%VERSION%\jetty-servlet-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\jetty-util-ajax\%VERSION%\jetty-util-ajax-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\jetty-util\%VERSION%\jetty-util-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\websocket\websocket-api\%VERSION%\websocket-api-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\websocket\websocket-client\%VERSION%\websocket-client-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\websocket\websocket-common\%VERSION%\websocket-common-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\websocket\websocket-server\%VERSION%\websocket-server-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\eclipse\jetty\websocket\websocket-servlet\%VERSION%\websocket-servlet-%VERSION%.jar
set CPATHS=%CPATHS%;%REPO%\org\postgresql\postgresql\9.4.1208.jre7\postgresql-9.4.1208.jre7.jar
"C:\Program Files\Java\jdk1.8.0_66\bin\java.exe" -cp %CPATHS% de.afarber.MyServlet

Svn PRE-COMMIT Hook scanning java class content

First time I'm doing an hook like this..
I need a pre-commit hook that scan all the java classes to commit, it should check for the presence of some character into the class and avoid the commit if found some of them, chars like † or ¥ and so on, i think a good way to make this dynamically change could be put all these invalid chars into a plan file in order to change it easily if we need to...
I'm starting from a simple hook that i wrote long time ago..
Now the BIG problem is getting the location of the working copy files..
The one I should scan the content.
I tried many svnlook commands, but I'm really unable to catch this information into the pre-commit hook....
Getting a lot of information but not the local path of the file. I'm using this to scan for content...
OUTPUT="$($SVNLOOK changed -t $TXN $REPOS)"
echo $SVNLOOK changed -t $TXN $REPOS 1>&2
echo "$BASEDIR" 1>&2
echo "${OUTPUT}" 1>&2
echo "$TXN $REPOS" 1>&2
Maybe it is my approach that is wrong?
Thanks a lot!
UPDATED
Thanks "CaffeineAddiction", you know it is always a "BIG QUESTION" when you do something for the first time.
In reality, the real issue in the end, after one day of attempts was another one, a SVN Bug related to the client char coding:
Error output could not be translated from the native locale to UTF-8
Now also this last issue is solved and the script works as well, you can see it below, it just need to be beautified, by the way thanks for yours, i'll get some ideas from yours:
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
OUTPUT="$($SVNLOOK changed -t $TXN $REPOS | awk '{print $2}')"
for LINE in $OUTPUT
do
FILE=`echo $LINE`
MESSAGE=`$SVNLOOK cat -t "$TXN" "$REPOS" "${FILE}"`
echo "File is: $FILE" 1>&2
echo "${MESSAGE}" > /tmp/app.txt
grep -P -n '[\x80-\xFF]' /tmp/app.txt | cut -f1 -d: 1>&2
done
This is not a full answer, but it might be enough to get you headed in the right direction. A while back I was asked to run gjslint against javascript files before allowing them to be checked into SVN. Here is the pre-hook I used for the task:
#!/bin/sh
SVNLOOK=/usr/bin/svnlook
GJSLINT=/usr/local/bin/gjslint
ECHO=$(which echo)
GREP=$(which grep)
SED=$(which sed)
## Used for Debug
#MYRUNLOG=/run/svn-pre-commit/pre-commit.log
#touch $MYRUNLOG
#echo "" > $MYRUNLOG
MYTEMPJS=/run/svn-pre-commit/temp.js
touch $MYTEMPJS
echo "" > $MYTEMPJS
MYTEMPLOG=/run/svn-pre-commit/gjslint.log
touch $MYTEMPLOG
echo "" > $MYTEMPLOG
REPOS="$1"
TXN="$2"
FILES_CHANGED=`$SVNLOOK changed -t$TXN $REPOS | $SED -e "s/^....//g"`
LINTERROR=0
for FILE in $FILES_CHANGED
do
if $ECHO $FILE | $GREP "\.js$"
then
if ! $ECHO "$REPOS/$FILE" | $GREP "/paweb5/\|/pamc/"; then exit 0; fi
if $ECHO "$REPOS/$FILE" | $GREP "/doc/"; then exit 0; fi
if $ECHO "$REPOS/$FILE" | $GREP "/docs/"; then exit 0; fi
$SVNLOOK cat -t$TXN $REPOS $FILE > $MYTEMPJS
$ECHO "$REPO/$FILE" >> $MYTEMPLOG
$GJSLINT --strict --disable 0001 $MYTEMPJS >> $MYTEMPLOG
GJSL_ERROR_CODE=$?
if [ $GJSL_ERROR_CODE != 0 ]
then
LINTERROR=1
fi
$ECHO "~~~" >> $MYTEMPLOG
fi
done
if [ $LINTERROR != 0 ]
then
echo "..........................................................................." >&2
while read line; do
if $ECHO $line | $GREP "Line\|no errors\|new errors\|paweb5\|~~~"
then
echo $line >&2
fi
done < $MYTEMPLOG
echo "..........................................................................." >&2
exit 1
fi
# If we got here, nothing is wrong.
exit 0
I believe the answer to your "BIG problem" getting the location of the working copy files might lie within $SVNLOOK cat -t$TXN $REPOS $FILE > $MYTEMPJS
If you have questions about the script feel free to ask

Force Solr to read from an updated index

I have a lucene index that i build and update using raw lucene indexers. I was wondering if there is a way to force solr to re-read the index without restarting the solr instance. Ive tried the update?commit=true but it doesnt seem to matter. The only way i can be sure solr -re-reads the index is by a total restart, which of course is not ideal in a production environment.
If you are using a multi-core setup, you can just reload that single core. AFAIK, while the core is being reloaded, the requests to that core are queued.
Not sure if there is another better way to do it.
But I wrote this script to perform full or delta imports.
#!/bin/bash
# script to index Solr
# by Felipe Ferreira Sept 2013
TYPE=$1
DATE=`date +%d_%m_%y`
DATEFULL=`date +%H:%M:%S_%d_%m_%y`
LOG="/var/log/solr/solr_import_${TYPE}_${DATE}.log"
LOGTMP="/var/log/solr/solr_status_${DATE}.log"
URL="http://<SERVER>:8080/solr/dataimport?command=status"
pt() {
echo -e $1
echo -e $1 >> $LOG
}
if [ $TYPE == "full" ]; then
pt "$DATEFULL - Starting full import"
URL="http://<SERVER>:8080/solr/dataimport?command=full-import"
# CMD="curl --location --no-buffer --fail --silent --output ${LOG} '${URL}'"
CMD="curl --location --silent --no-buffer '${URL}' >> $LOG"
pt "Executing $CMD"
CMD_E=`eval $CMD`
pt $CMD_E
elif [ $TYPE == "delta" ]; then
pt "$DATEFULL - Starting delta import"
URL="http://<SERVER>:8080/solr/dataimport?command=delta-import"
#CMD="curl --location --no-buffer --fail --silent --output ${LOG} '${URL}'"
CMD="curl --location --silent --no-buffer '${URL}' >> $LOG"
pt "Executing $CMD"
CMD_E=`eval $CMD`
pt $CMD_E
else
pt "ERROR - $TYPE not found, only delta or full,\n Usage: $0 delta/full"
fi
sleep 3
#check status after command
pt "$DATEFULL - Checking $TYPE status"
URL="http://infofish2:9080/solrcadin/cadin/dataimport?command=status"
CMD="curl --location --silent --no-buffer '${URL}' > $LOGTMP"
pt "Executing $CMD"
CMD_E=`eval $CMD`
pt $CMD_E
CHECK=0
CHECK=`grep -c failed $LOGTMP`
if [ $CHECK -eq 0 ]; then
pt "OK - Command $TYPE executed with success!"
exit 0
else
pt "CRITICAL - Command $TYPE failed, solr did not index!"
pt "grep -c failed $LOGTMP"
pt "CHECK $CHECK"
exit 0
fi

Categories

Resources