Update Zabbix with a script - zabbix

I need to make a script that will update Zabbix on Ubuntu. It needs to update everything like the log files and so on. But I don't know how to make a script that will execute this. I've been trying to look up information on this subject but can't find anything.

Following is an old script that is used to install Zabbix-server automatically, but only for the first time, I think you must only edit thing which is required in the application
#!/bin/sh
#
# zabbix 2.0.2 install with postgresql and jabber support
#
#
# software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
#
# written by:
# Stefan Krueger
# tested on Debian Squeeze/Wheezy & Ubuntu 10.04 LTS/12.04 LTS (use sudo su -)
#
(
dbpw=$(dd if=/dev/urandom bs=1 count=6 2>/dev/null | openssl base64)
zbxver=zabbix-2.0.2
ipadd=$(env LC_ALL=C /sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
date
# update system
echo '###############'
echo 'update system'
echo '###############'
apt-get update
# install requirements
echo '###############'
echo 'install requirements'
echo '###############'
sleep 1
apt-get install -y postgresql build-essential fping apache2 php5 php5-pgsql php5-gd libsnmp-dev libcurl4-openssl-dev libapache2-mod-php5 libiksemel-dev libpq-dev libssh2-1-dev libopenipmi-dev
#DB setup
echo '###############'
echo 'database setup '
echo '###############'
sleep 1
adduser zabbix --no-create-home --system --group --disabled-password --shell /bin/false --quiet && echo 'User zabbix created' || echo 'User zabbix could not be created'
su postgres -c "echo \"create user zabbix with password '${dbpw}' createdb;\" | psql" && echo "database user zabbix created" || echo "database user zabbix could not be created"
su postgres -c "echo \"create database zabbix with owner=zabbix;\" | psql" && echo "database zabbix created" || echo "database zabbix could not be created"
sleep 2
# zabbix installation
echo '############################################################################'
echo ''
echo $zbxver installation
echo ''
echo '############################################################################'
cd /tmp/
mkdir -p /tmp/install
cd /tmp/install
wget http://prdownloads.sourceforge.net/zabbix/${zbxver}.tar.gz
tar -zxvf ${zbxver}.tar.gz
chmod -R 777 /tmp/install/*
su zabbix -s /bin/bash -c "psql -d zabbix -f /tmp/install/${zbxver}/postgresql/schema.sql" && echo "create schema success" || echo "create schema failed"
su zabbix -s /bin/bash -c "psql -d zabbix -f /tmp/install/${zbxver}/postgresql/images.sql" && echo "create schema success" || echo "create schema failed"
su zabbix -s /bin/bash -c "psql -d zabbix -f /tmp/install/${zbxver}/postgresql/data.sql" && echo "create schema success" || echo "create schema failed"
cd /tmp/install/${zbxver}
chmod +x /tmp/install/${zbxver}/configure
chmod +x ./configure
/tmp/install/${zbxver}/configure --enable-server --with-postgresql --with-net-snmp --with-libcurl --with-openipmi --with-jabber --with-ssh2 --enable-agent --prefix=/usr --mandir=\${prefix}/share/man --infodir=\${prefix}/share/info --sysconfdir=/etc/zabbix || exit
make install
#install frontend
echo '############################################################################'
echo ''
echo '$zbxver installation'
echo ' FRONTEND installation'
echo ''
echo '############################################################################'
sleep 1
sed -i.backup -e "s/post_max_size = 8M/post_max_size = 32M/g" -e "s/max_execution_time = 30/max_execution_time = 600/g" -e "s/max_input_time = 60/max_input_time = 600/g" -e '/date.timezon/a\date.timezone = "Europe/Berlin"' /etc/php5/apache2/php.ini
cd /tmp/install/${zbxver}/frontends/php
mkdir -p /var/www/zabbix
cp -a . /var/www/zabbix
chown www-data:www-data -R /var/www/zabbix
cat <<EOF > /etc/apache2/sites-available/zabbix
<VirtualHost /zabbix>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/zabbix
<Directory />
Options FollowSymLinks Indexes MultiViews
AllowOverride None
</Directory>
</VirtualHost>
EOF
echo '############################################################################'
echo ''
echo '$zbxver installation'
echo ' services installation agent & server'
echo ''
echo '############################################################################'
sleep 1
mkdir -p /var/log/zabbix && chown zabbix /var/log/zabbix && chmod 760 /var/log/zabbix
mkdir -p /var/run/zabbix && chown zabbix /var/run/zabbix && chmod 760 /var/run/zabbix
#cp /tmp/install/${zbxver}/misc/conf/zabbix_server.conf /etc/zabbix
#cp /tmp/install/${zbxver}/misc/conf/zabbix_agentd.conf /etc/zabbix
sed -i.backup -e "s|DBUser=root|DBUser=zabbix|g" -e "s|# DBPassword=|DBPassword=${dbpw}|g" -e "s|/tmp/zabbix_server.log|/var/log/zabbix/zabbix_server.log|g" -e "s|# PidFile=/tmp/zabbix_server.pid|PidFile=/var/run/zabbix/zabbix_server.pid|g" -e "s|# HousekeepingFrequency=1|HousekeepingFrequency=24|" /etc/zabbix/zabbix_server.conf
sed -i.backup -e "s|/tmp/zabbix_agentd.log|/var/log/zabbix/zabbix_agentd.log|g" -e "s|# PidFile=/tmp/zabbix_agentd.pid|PidFile=/var/run/zabbix/zabbix_agentd.pid|g" /etc/zabbix/zabbix_agentd.conf
chown -R zabbix:zabbix /etc/zabbix
cp /tmp/install/${zbxver}/misc/init.d/debian/zabbix* /etc/init.d/
sed -i.backup -e "s|/usr/local/sbin/|/usr/sbin/|" -e "s|PID=/tmp/|PID=/var/run/zabbix/|" /etc/init.d/zabbix-server
sed -i.backup -e "s|/usr/local/sbin/|/usr/sbin/|" -e "s|PID=/tmp/|PID=/var/run/zabbix/|" /etc/init.d/zabbix-agent
chmod 775 /etc/init.d/zabbix-server
chmod 775 /etc/init.d/zabbix-agent
update-rc.d zabbix-server defaults 90
update-rc.d zabbix-agent defaults 99
/etc/init.d/zabbix-agent start
/etc/init.d/zabbix-server start
/etc/init.d/apache2 restart
echo ""
echo ""
echo ""
if [ -e /var/run/zabbix/zabbix_server.pid ]; then echo " zabbix-server started succesfully"
else echo " !! zabbix-server dont start"
fi
if [ -e /var/run/zabbix/zabbix_agentd.pid ]; then echo " zabbix-agentd started succsfully"
else echo " !! zabbix-agentd dont start"
fi
echo " look at the zabbix_install.log"
echo ""
echo " please configure you postgresql.conf"
echo " the database password for zabbix is: ${dbpw}"
echo ""
echo " now you can configure the zabbix-frontend http://${ipadd}/zabbix"
) | tee zabbix_install.log

Related

To Add Junit tests in SonarQube

I am not able to view Junit tests in Sonarqube coverage report. We are running the pipeline in bitbucket and project is based on SAP hybris.
bit-bucket-pipeline.yml
mage: atlassian/default-image:3
clone:
lfs: true
pipelines:
custom:
qg-sonarqube-main:
- step:
name: 'sq init'
image: atlassian/default-image:3
script:
- |
echo "start notification"
echo "install java"
apt update
apt install -y --no-install-recommends openjdk-11-jdk rsync tree
java --version
echo "sonarqube scan of current branch; build dir $BITBUCKET_CLONE_DIR"
# assembly first
echo "download scanner-cli"
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli- 4.7.0.2747.zip -O $BITBUCKET_CLONE_DIR/sonarcli.zip
unzip -q $BITBUCKET_CLONE_DIR/sonarcli.zip -d $BITBUCKET_CLONE_DIR
ln -s $BITBUCKET_CLONE_DIR/sonar-scanner-4.7.0.2747/bin/sonar-scanner /bin/sonar-scanner
/bin/sonar-scanner -v
echo "hybris ootb assembly"
unzip -q ootb/CXCOM200500P_27-70004955.ZIP -d $BITBUCKET_CLONE_DIR
echo "unzip and copy modules"
unzip -q ootb/modules.zip -d $BITBUCKET_CLONE_DIR/hybris/bin/
echo "move sonar project configuration"
mv sonar-project.properties hybris/sonar-project.properties
echo "node version"
node -v
echo "move the customcode"
mv bin/custom hybris/bin/
echo "build the box"
cd hybris/bin/platform
. ./setantenv.sh
echo | ant clean
cd $BITBUCKET_CLONE_DIR
rsync -vau config/ hybris/config/
echo "check config dir"
cd hybris/bin/platform
ant customize
echo "copy valid props and localextensions taken from valid assembly"
ant build all
echo "scan"
cd $BITBUCKET_CLONE_DIR/hybris/
TODAY=$(date +'%d%m%Y')
echo "code version $BITBUCKET_BUILD_NUMBER.$TODAY"
/bin/sonar-scanner -Dsonar.login="$SONAR_LOGIN" -Dsonar.projectKey=alcon-"$BITBUCKET_BRANCH" -Dsonar.projectName=alcon-"$BITBUCKET_BRANCH" -Dsonar.projectVersion="$BITBUCKET_BUILD_NUMBER.$TODAY"
echo "waiting for CE"
# get ceTaskUrl var
source .scannerwork/report-task.txt
# up to 30 min
for _ in {0..60}; do
status=$(curl -s -H "Accept: application/json" -u "$SONAR_LOGIN:" $ceTaskUrl | jq -r .task.status)
case $status in
SUCCESS)
echo "notification about success"
echo "Task finished"
echo "Project dashboard: $dashboardUrl"
exit 0
;;
PENDING | IN_PROGRESS)
echo "Task still in progress"
sleep 30
;;
FAILED)
echo "notification about fail"
echo Got FAILED task status, exit
exit 1
;;
*)
echo "Unsupported task status: $status"
sleep 30
;;
esac
done
echo "Project dashboard: $dashboardUrl"
====================
Sonar-project.properties:
sonar.sources=bin/custom/
sonar.sourceEncoding=UTF-8
sonar.pdf.skip=true
sonar.language=java
sonar.java.source=1.8
sonar.java.binaries=bin/custom/
sonar.host.url=https://b2bint.sonarqube.alconcloud.com

Inject .sql files in order using a docker-compose

I'm running an MySQL server docker container using a docker-compose YAML file.
Here is how the file looks like:
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- ./mysql-dump/samples:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: db_example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
In the db service, the volumne is set to ./mysql-dump/samples:/docker-entrypoint-initdb.d this takes .sql files from ./mysql-dump/sample to inject them to the database.
In my case I have two files file2.sql for the sql schema of the database, and file1.sql for the data.
Since the file appear to be injected in order, I get a NO SUCH TABLE ERROR, surely because the schema is injected last (because it's name is file2.sql)
Is there a way to reverse the order of the injection beside changing the names of the files?
If you go through the documentation of mysql Dockerhub it clearly mentioned that it will dump file in alphabetical order.
When a container is started for the first time, a new database with
the specified name will be created and initialized with the provided
configuration variables. Furthermore, it will execute files with
extensions .sh, .sql and .sql.gz that are found in
/docker-entrypoint-initdb.d. Files will be executed in alphabetical
order. You can easily populate your mysql services by mounting a SQL
dump into that directory and provide custom images with contributed
data. SQL files will be imported by default to the database specified
by the MYSQL_DATABASE variable.
You need to replace file name, suppose db.sql and table.sql so it will first dump db.sql then table.sql
Updated:
To reverse the order of MySQL dump, you have to modify the docker file and entry point.
FROM mysql:8
#From mysql
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
EXPOSE 3306 33060
CMD ["mysqld"]
ENTRYPOINT:
#!/bin/bash
set -x
set -eo pipefail
shopt -s nullglob
# if command starts with an option, prepend mysqld
if [ "${1:0:1}" = '-' ]; then
set -- mysqld "$#"
fi
# skip setup if they want an option that stops mysqld
wantHelp=
for arg; do
case "$arg" in
-'?'|--help|--print-defaults|-V|--version)
wantHelp=1
break
;;
esac
done
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# usage: process_init_file FILENAME MYSQLCOMMAND...
# ie: process_init_file foo.sh mysql -uroot
# (process a single initializer file, based on its extension. we define this
# function here, so that initializer scripts (*.sh) can use the same logic,
ls -r
process_init_file() {
local f="$1"; shift
local mysql=( "$#" )
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${mysql[#]}" < "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[#]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
}
_check_config() {
toRun=( "$#" --verbose --help )
if ! errors="$("${toRun[#]}" 2>&1 >/dev/null)"; then
cat >&2 <<-EOM
ERROR: mysqld failed while attempting to check config
command was: "${toRun[*]}"
$errors
EOM
exit 1
fi
}
# Fetch value from server config
# We use mysqld --verbose --help instead of my_print_defaults because the
# latter only show values present in config files, and not server defaults
_get_config() {
local conf="$1"; shift
"$#" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null \
| awk '$1 == "'"$conf"'" && /^[^ \t]/ { sub(/^[^ \t]+[ \t]+/, ""); print; exit }'
# match "datadir /some/path with/spaces in/it here" but not "--xyz=abc\n datadir (xyz)"
}
# allow the container to be started with `--user`
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
_check_config "$#"
DATADIR="$(_get_config 'datadir' "$#")"
mkdir -p "$DATADIR"
chown -R mysql:mysql "$DATADIR"
exec gosu mysql "$BASH_SOURCE" "$#"
fi
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
# still need to check config, container may have started with --user
_check_config "$#"
# Get config
DATADIR="$(_get_config 'datadir' "$#")"
if [ ! -d "$DATADIR/mysql" ]; then
file_env 'MYSQL_ROOT_PASSWORD'
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
echo >&2 'error: database is uninitialized and password option is not specified '
echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
exit 1
fi
mkdir -p "$DATADIR"
echo 'Initializing database'
"$#" --initialize-insecure
echo 'Database initialized'
if command -v mysql_ssl_rsa_setup > /dev/null && [ ! -e "$DATADIR/server-key.pem" ]; then
# https://github.com/mysql/mysql-server/blob/23032807537d8dd8ee4ec1c4d40f0633cd4e12f9/packaging/deb-in/extra/mysql-systemd-start#L81-L84
echo 'Initializing certificates'
mysql_ssl_rsa_setup --datadir="$DATADIR"
echo 'Certificates initialized'
fi
SOCKET="$(_get_config 'socket' "$#")"
"$#" --skip-networking --socket="${SOCKET}" &
pid="$!"
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[#]}" &> /dev/null; then
break
fi
echo 'MySQL init process in progress...'
sleep 1
done
if [ "$i" = 0 ]; then
echo >&2 'MySQL init process failed.'
exit 1
fi
if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then
# sed is for https://bugs.mysql.com/bug.php?id=20545
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[#]}" mysql
fi
if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
export MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
fi
rootCreate=
# default root to listen for connections from anywhere
file_env 'MYSQL_ROOT_HOST' '%'
if [ ! -z "$MYSQL_ROOT_HOST" -a "$MYSQL_ROOT_HOST" != 'localhost' ]; then
# no, we don't care if read finds a terminating character in this heredoc
# https://unix.stackexchange.com/questions/265149/why-is-set-o-errexit-breaking-this-read-heredoc-expression/265151#265151
read -r -d '' rootCreate <<-EOSQL || true
CREATE USER 'root'#'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
GRANT ALL ON *.* TO 'root'#'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ;
EOSQL
fi
"${mysql[#]}" <<-EOSQL
-- What's done in this file shouldn't be replicated
-- or products like mysql-fabric won't work
SET ##SESSION.SQL_LOG_BIN=0;
ALTER USER 'root'#'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
GRANT ALL ON *.* TO 'root'#'localhost' WITH GRANT OPTION ;
${rootCreate}
DROP DATABASE IF EXISTS test ;
FLUSH PRIVILEGES ;
EOSQL
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
fi
file_env 'MYSQL_DATABASE'
if [ "$MYSQL_DATABASE" ]; then
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[#]}"
mysql+=( "$MYSQL_DATABASE" )
fi
file_env 'MYSQL_USER'
file_env 'MYSQL_PASSWORD'
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
echo "CREATE USER '$MYSQL_USER'#'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[#]}"
if [ "$MYSQL_DATABASE" ]; then
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'#'%' ;" | "${mysql[#]}"
fi
echo 'FLUSH PRIVILEGES ;' | "${mysql[#]}"
fi
echo
ls -r /docker-entrypoint-initdb.d/ > /dev/null
for f in $(ls -r /docker-entrypoint-initdb.d/*); do
process_init_file "$f" "${mysql[#]}"
done
if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
"${mysql[#]}" <<-EOSQL
ALTER USER 'root'#'%' PASSWORD EXPIRE;
EOSQL
fi
if ! kill -s TERM "$pid" || ! wait "$pid"; then
echo >&2 'MySQL init process failed.'
exit 1
fi
echo
echo 'MySQL init process done. Ready for start up.'
echo
fi
fi
exec "$#"
If you run the container, You will see the file is in processing reverse order

How to clean up temporary files after exec-ing inside entrypoint script?

I am trying to write my own mariadb docker image. I wanted to execute some sql statements just after container starts (After exec mysqld). However I found mysqld --init-file option useful for my case. So my entrypoint script is something like below.
Dockerfile
FROM alpine:edge
RUN set -ex \
&& apk add mariadb mariadb-client \
&& mkdir -p /run/mysqld \
&& chown -R mysql:mysql /run/mysqld \
&& ln -snf /usr/lib/mariadb /usr/lib/mysql \
&& mysql_install_db --user=mysql --skip-name-resolve --auth-root-authentication-method=socket --auth-root-socket-user=root --force --rpm --skip-test-db
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 3306
CMD ["mysqld"]
entrypoint.sh
#!/bin/sh
set -ex
{
echo "CREATE USER IF NOT EXISTS '${MYSQL_USER}'#'%' IDENTIFIED BY '${MYSQL_PASSWORD}';"
echo "CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE};"
echo "GRANT ALL ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'#'%';"
} > /tmp/mysqld-init.sql
exec $# --init-file="/tmp/mysqld-init.sql"
As you can see the temporary init file contains some sensitive information. I wanted to clean it after execution of exec $# --init-file="/tmp/mysqld-init.sql".
Now two ideas came to my mind. One is to create a named pipe (FIFO) file for temporary sql command or to use trap command.
Idea-1
But the problem here is a unnecessary child background process is keep running on container as I have used process control operator &. But I am in vain how can I exit that process.
if [ ! -p "/tmp/mysqld.init" ]; then
mkfifo /tmp/mysqld.init
fi
{
echo "CREATE USER IF NOT EXISTS '${MYSQL_USER}'#'%' IDENTIFIED BY '${MYSQL_PASSWORD}';"
echo "CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE};"
echo "GRANT ALL ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'#'%';"
} > /tmp/mysqld.init &
exec $# --init-file="/tmp/mysqld.init"
Idea-2
Use trap command and clean the temporary file when exec command gets executed. But I don't know how to catch the exec signal.
trap cleanup "the exec signal"
cleanup()
{
echo "Caught Signal ... cleaning up."
rm -rf /tmp/mysqld-init.sql
echo "Done cleanup ... quitting."
exit 1
}
set -ex
{
echo "CREATE USER IF NOT EXISTS '${MYSQL_USER}'#'%' IDENTIFIED BY '${MYSQL_PASSWORD}';"
echo "CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE};"
echo "GRANT ALL ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'#'%';"
} > /tmp/mysqld-init.sql
exec $# --init-file="/tmp/mysqld.init"
Use tini to solve this signal and zombie process issue.
FROM alpine:edge
RUN set -ex \
&& apk add --no-cache mariadb mariadb-client tini \
&& mkdir -p /run/mysqld \
&& chown -R mysql:mysql /run/mysqld \
&& ln -snf /usr/lib/mariadb /usr/lib/mysql \
&& mysql_install_db --user=mysql --skip-name-resolve --auth-root-authentication-method=socket --auth-root-socket-user=root --force --rpm --skip-test-db
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 3306
CMD ["mysqld"]
entrypoint.sh
if [ ! -p "/tmp/mysqld.init" ]; then
mkfifo /tmp/mysqld.init
fi
{
echo "CREATE USER IF NOT EXISTS '${MYSQL_USER}'#'%' IDENTIFIED BY '${MYSQL_PASSWORD}';"
echo "CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE};"
echo "GRANT ALL ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'#'%';"
} > /tmp/mysqld.init &
exec tini -g -- "$#" --init-file="/tmp/mysqld.init"
I think trap is a best solution for this
function interrupt(){
local dir=$1
[ -e ${dir} ] && rm -rf ${dir}
exit 128
}
TMP_DIR=$(mktemp -d /tmp/entrypoint.XXXX)
trap "interrupt ${TMP_DIR}" SIGINT SIGTERM
trap "rm -rf ${TMP_DIR}" EXIT
set -ex
{
echo "CREATE USER IF NOT EXISTS '${MYSQL_USER}'#'%' IDENTIFIED BY '${MYSQL_PASSWORD}';"
echo "CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE};"
echo "GRANT ALL ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'#'%';"
} > ${TMP_DIR}/mysqld-init.sql
exec $# --init-file="${TMP_DIR}/mysqld-init.sql"

Issues installing IDAS on CentOS 7 VM through provided RPMs

I've been trying to install IDAS GE in a CentOS 7 VM on my machine through the UL2.0 RPMs(download link!) available in its catalogue page.
I followed the instructions on github, but I get stuck in starting the IoT as per section 3 of the Deployment section of the instructions. If I execute the init_iotagent.sh, where I inserted the local IP of the VM, I get the error:
log4cplus:ERROR No appenders could be found for logger (main).
log4cplus:ERROR Please initialize the log4cplus system properly.
HTTPFilter DESTRUCTOR 0
HTTPFilter DESTRUCTOR 0
Also, in the instructions for Starting IoTAgent as a Service, it's said that:
After installing iot-agent-base RPM an init.d script can be found in
this folder /usr/local/iot/init.d .
But this file is not there, leading me to believe that the IoTAgent wasn't installed properly from the RPMs provided.
Also, I can't find log files regarding IoTAgent, only the MongoDB has its log file at /usr/local/iot/mongodb-linux-x86_64-2.6.9/log/mongoc.log.
If anyone could help, it would be apreciated. Also, if more info is needed, please let me know.
Thank you
I recommend you to get the GitHub repository and build the RPMs from the source and then install it in your CentOS. Like is explained in the documentation:
NOTE: I changed the BUILD_TYPE to Release, so I created the Release dir.
GIT_VERSION and GIT_COMMIT are not the latest ones.
git clone https://github.com/telefonicaid/fiware-IoTAgent-Cplusplus.git
cd fiware....
mkdir -p build/Release
cd build/Release
cmake -DGIT_VERSION=20527 -DGIT_COMMIT=217023407f25ed258043cfc00a46b6c05fb0b52c -DMQTT=ON -DCMAKE_BUILD_TYPE=Release ../../
make install
make package
The packages will be in pack/Linux/RPM/
rpm -i iot-agent-base-xxxxxxx (xxxxxxx will be the numbers of the build)
rpm -i iot-agent-ul-xxxxxx (xxxxxxx will be the numbers of the build)
Once installed with RPMs the init.d file is in: /usr/local/iot/init.d/iotagent
This is the content of the file:
#!/bin/bash
# Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
#
# This file is part of fiware-IoTagent-Cplusplus (FI-WARE project).
#
# iotagent Start/Stop iotagent
#
# chkconfig: 2345 99 60
# description: iotagent
. /etc/rc.d/init.d/functions
PARAM=$1
INSTANCE=$2
USERNAME=iotagent
EXECUTABLE=/usr/local/iot/bin/iotagent
CONFIG_PATH=/usr/local/iot/config
iotagent_start()
{
local result=0
local instance=${1}
if [[ ! -x ${EXECUTABLE} ]]; then
printf "%s\n" "Fail - missing ${EXECUTABLE} executable"
exit 1
fi
if [[ -z ${instance} ]]; then
list_instances="${CONFIG_PATH}/iotagent_*.conf"
else
list_instances="${CONFIG_PATH}/iotagent_${instance}.conf"
fi
for instance_config in ${list_instances}
do
local NAME
NAME=${instance_config%.conf}
NAME=${NAME#*iotagent_}
source ${instance_config}
local IOTAGENT_PID_FILE="/var/run/iot/iotagent_${NAME}.pid"
printf "Starting iotagent ${NAME}..."
status -p ${IOTAGENT_PID_FILE} ${EXECUTABLE} &> /dev/null
if [[ ${?} -eq 0 ]]; then
printf "%s\n" " Already running, skipping $(success)"
continue
fi
# Load the environment
set -a
source ${instance_config}
# Mandatory parameters
IOTAGENT_OPTS=" ${IS_MANAGER} \
-n ${IOTAGENT_SERVER_NAME} \
-v ${IOTAGENT_LOG_LEVEL} \
-i ${IOTAGENT_SERVER_ADDRESS} \
-p ${IOTAGENT_SERVER_PORT} \
-d ${IOTAGENT_LIBRARY_DIR} \
-c ${IOTAGENT_CONFIG_FILE}"
su ${USERNAME} -c "LD_LIBRARY_PATH=\"${IOTAGENT_LIBRARY_DIR}\" \
${EXECUTABLE} ${IOTAGENT_OPTS} & echo \$! > ${IOTAGENT_PID_FILE}" &> /dev/null
sleep 2 # wait some time to leave iotagent start
local PID=$(cat ${IOTAGENT_PID_FILE})
local var_pid=$(ps -ef | grep ${PID} | grep -v grep)
if [[ -z "${var_pid}" ]]; then
printf "%s" "pidfile not found"
printf "%s\n" "$(failure)"
exit 1
else
printf "%s\n" "$(success)"
fi
done
return ${result}
}
iotagent_stop()
{
local result=0
local iotagent_instance=${1}
if [[ -z ${iotagent_instance} ]]; then
list_run_instances="/var/run/iot/iotagent_*.pid"
else
list_run_instances="/var/run/iot/iotagent_${iotagent_instance}.pid"
fi
if [[ $(ls -l ${list_run_instances} 2> /dev/null | wc -l) -eq 0 ]]; then
printf "%s\n" "There aren't any instance of IoTAgent ${iotagent_instance} running $(success)"
return 0
fi
for run_instance in ${list_run_instances}
do
local NAME
NAME=${run_instance%.pid}
NAME=${NAME#*iotagent_}
printf "%s" "Stopping IoTAgent ${NAME}..."
local RUN_PID=$(cat ${run_instance})
kill ${RUN_PID} &> /dev/null
local KILLED_PID=$(ps -ef | grep ${RUN_PID} | grep -v grep | awk '{print $2}')
if [[ -z ${KILLED_PID} ]]; then
printf "%s\n" "$(success)"
else
printf "%s\n" "$(failure)"
result=$((${result}+1))
fi
rm -f ${run_instance} &> /dev/null
done
return ${result}
}
iotagent_status()
{
local result=0
local iotagent_instance=${1}
if [[ -z ${iotagent_instance} ]]; then
list_run_instances="/var/run/iot/iotagent_*.pid"
else
list_run_instances="/var/run/iot/iotagent_${iotagent_instance}.pid"
fi
if [[ $(ls -l ${list_run_instances} 2> /dev/null | wc -l) -eq 0 ]]; then
printf "%s\n" "There aren't any instance of IoTAgent ${iotagent_instance} running."
return 1
fi
for run_instance in ${list_run_instances}
do
local NAME
NAME=${run_instance%.pid}
NAME=${NAME#*iotagent_}
printf "%s\n" "IoTAgent ${NAME} status..."
status -p ${run_instance} ${NODE_EXEC}
result=$((${result}+${?}))
done
return ${result}
}
case ${PARAM} in
'start')
iotagent_start ${INSTANCE}
;;
'stop')
iotagent_stop ${INSTANCE}
;;
'restart')
iotagent_stop ${INSTANCE}
iotagent_start ${INSTANCE}
;;
'status')
iotagent_status ${INSTANCE}
;;
esac
And the logs file are in /tmp/ :
IoTAgent-IoTPlatform.log
IoTAgent.log
IoTAgent-Manager.log
Hope this helps you.

Issue with Facelets page regarding embeded scripts code in a 'code' element

Very confusing question I know, and it's a bit of a gobstopper for me!
I am trying to display bash script code in a Facelets page so that user can copy the scripts code from browser. This code is placed in a code element as posted below. But requesting the page gives me error(s) related to what I think is the cause (in bold). I have tried replacing the {, }, & - characters with the html replacements and I still get errors. Perhaps this is not allowed?
#!/bin/bash
#Author: Yucca Nel http://thejarbar.org
#Will restart system
#Modify these variables as needed...
tempWork=/tmp/work
defaultStartScript=/etc/init.d/rc.local
defaultMaven=3.0.4
locBin=/usr/local/bin
mavenUsrLib=/usr/lib/maven
sudo mkdir -p $mavenUsrLib
mkdir -p $HOME/.m2
read -p "Please [Enter] full path name of your local startup script ($defaultStartScript is the default). Please
make sure on this before providing a value by consulting documentation for your system:" locStartScript
locStartScript=${locStartScript:-$defaultStartScript}
read -p "Please [Enter] Maven Version ($defaultMaven is default):" mavenVersion
mavenVersion=${mavenVersion:-$defaultMaven}
if [ ! -f $locStartScript ]
then
echo "The file you provided could not be found. Remember to include the full path and try again. Exiting in 7 secs..."
sleep 7
exit 1
fi
mkdir -p /$tempWork
cd /$tempWork
wget http://mirrors.powertech.no/www.apache.org/dist//maven/binaries/apache-maven-$mavenVersion-bin.tar.gz
tar -zxvf ./
#Move it to a more logical location
sudo mv -f ./apache-maven-$mavenVersion $mavenUsrLib/
#If you have Maven on Windows and use VirtualBox, you can set up the maven to be a virtualbox shared folder.
#The name must match the name used below (ignore if irrelevant to you).
if [ -f /sbin/mount.vboxsf ]
then
sudo /sbin/umount $HOME/.m2
sudo /sbin/umount $mavenUsrLib
sudo /sbin/mount.vboxsf .m2 $HOME/.m2
sudo /sbin/mount.vboxsf maven $mavenUsrLib
fi
if mountpoint -q $HOME/.m2 && mountpoint -q $mavenUsrLib
then
#Add it to the start script to automate process...
if ! grep "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" $locStartScript
then
echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $locStartScript
fi
if ! grep "sudo /sbin/mount.vboxsf maven $mavenUsrLib" $locStartScript
then
echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $locStartScript
fi
echo "exit 0" | sudo tee -a $locStartScript
sudo chmod +x $locStartScript
#Create a mount and unmount script file...
rm -rf $tempWork/
echo '#!/bin/bash' > $tempWork/maven-mount.sh
echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" >> $tempWork/maven-mount.sh
echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" >> $tempWork/maven-mount.sh
echo "echo 'mounted maven'" >> $tempWork/maven-mount.sh
echo "exit 0" >> $tempWork/maven-mount.sh
echo '#!/bin/bash' > $tempWork/maven-umount.sh
echo "sudo umount $HOME/.m2" >> $tempWork/netbeans-umount.sh
echo "sudo umount $mavenUsrLib" >> $tempWork/netbeans-umount.sh
echo "echo 'unmounted maven'" >> $tempWork/maven-mount.sh
echo 'exit 0' >> $tempWork/maven-umount.sh
#Script for mounting ALL VirtualBox shared solders....
#If there isn't one create one...
if [ ! -f $locBin/mount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $tempWork/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $tempWork/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/mount-all-from-host.sh
#Otherwise if there is one, but no mount, add one...
elif ! grep "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" $locBin/mount-all-from-host.sh
then
sudo sed -ie '$d' $locBin/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $locBin/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $locBin/mount-all-from-host.sh
elif ! grep "sudo /sbin/mount.vboxsf maven $mavenUsrLib" $locBin/mount-all-from-host.sh
then
sudo sed -ie '$d' $locBin/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $locBin/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $locBin/mount-all-from-host.sh
fi
#Script for unmounting ALL VirtualBox shared folders...
#If there isn't one create one...
if [ ! -f $locBin/umount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/umount-all-from-host.sh
echo "sudo umount -a -t vboxsf" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "echo 'unmounted all VirtualBox shared folders'" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/umount-all-from-host.sh
fi
sudo chmod +x $tempWork/
sudo mv -f $tempWork/.sh $locBin/
rm -rf $tempWork
fi
sudo ln -f -s $mavenUsrLib/apache-maven-$mavenVersion/bin/* /usr/bin/
sudo rm -rf $tempWork
sudo /sbin/reboot
exit 0
Solved: mavenVersion=$<h:outputText value="{mavenVersion:-$defaultMaven}"/><br/>