How to terminate/stop quarkus keycloak server version 17.x.x? - keycloak

Recently I downloaded the new version Keycloak 17.0.0 Quarkus distribution, unzipped and started the Keycloak server by running bin/kc.sh start-dev from my local $KEYCLOAK_HOME directory in a CygWin Bash window. The server is up and running and I have configured my initial admin user. I am also able to login to the Keycloak UI.
There is no cloud environment yet, no fancy configuration, it's only the bare standalone quarkus impl.
Question: How can I gracefull stop/quit/terminate the Keycloak server process? (Ctrl+C does not help in this case, because this command is not really scriptable)
Before moving to v17 I started my experiments with v16.1.0 Wildfly distribution and I was using ${KEYCLOAK_HOME}/bin/jboss-cli.sh --connect --commands="shutdown,quit" to terminate the server. But v17 (quarkus) does not contain the jboss-cli.sh script.

This may not be a graceful stoppage/shutdown but we can still use it in a script until we find a better way.
fuser : an utility to identify processes using files or sockets
If CygWin bash supports Linux fuser command you can try : fuser -k 8080/tcp
Here is what I'm using on Linux
If keycloak is running on its default https port
sudo fuser -k 8443/tcp
If keycloak is running on its http default port
sudo fuser -k 8080/tcp
If you running keycloak on some_custom_prot
sudo fuser -k some_custom_prot/tcp

It looks like capturing the PID and killing that later will work in v17 (I'm not sure this was true for v15 and WildFly):
$ ./keycloak-17.0.1/bin/kc.sh start-dev --http-port=8080 > keycloak.stdout 2>&1 & echo "$!" > keycloak.pid
$ cat keycloak.pid | xargs kill -TERM

Stop
Linux: ./jboss-cli.sh --connect command=:shutdown
Windows: jboss-cli.bat --connect command=:shutdown

Related

docker-compose syslog driver to loggly not working

I'm trying to implement centralised logging for a number of micro-service docker containers.
To achieve this I'm attempting to use the recommended syslog logging driver approach, to deliver logs to loggly.
https://www.loggly.com/docs/docker-logging-driver/
I've done the following...
On the remote docker-machine...
$ curl -O https://www.loggly.com/install/configure-linux.sh
$ sudo bash configure-linux.sh -a SUBDOMAIN -u USERNAME
It verified that everything worked correctly, and I can see that the host events are now going through to the loggly console.
I then configured the services in docker-compose, like so...
nginx_proxy:
build: nginx_proxy
logging:
driver: "syslog"
options:
tag: "{{.ImageName}}/{{.Name}}/{{.ID}}"
I then rebuilt and re-launched the containers, with...
$ docker-compose up --build -d
However I'm not getting any logs from the containers going to loggly.
I can verify that the syslog driver update has taken effect by doing...
$ docker-compose logs nginx_proxy
This reports...
nginx_proxy_1 | WARNING: no logs are available with the 'syslog' log driver
Which is what I would expect to see, as this log driver doesn't work for viewing logs locally.
Is there something else I need to do to get this working correctly?
Can you share Dockerfile in nginx_proxy directory? Did you confirm that it is generating logs?
To test, can you swap out nginx with basic ubuntu that echo's something like they show in loggly documentation: https://www.loggly.com/docs/docker-logging-driver/
Run:
sudo docker run -d --log-driver=syslog --log-opt tag="{{.ImageName}}\{{.Name}}\{{.ID}}" ubuntu echo "Test Log"
Check:
$ tail /var/log/syslog

How to run kafka rest proxy on windows

How to run kafka rest proxy on windows.
I downloaded confluent-2.0.1-2.11.7.tar.gz
in windows folder i cannot see kafka-rest-start.
Windows isn't currently a supported platform. However, it should work fine if you adapt the script. Even just running java io.confluent.kafkarest.KafkaRestMain with the appropriate classpath should work.
Here's the example of the command they are actually executing in the end of the bash script:
java -Xmx256M -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+DisableExplicitGC -Djava.awt.headless=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dlog4j.configuration=file:C:/Dev/kafka/confluent-4.0.0/etc/kafka-rest/log4j.properties -cp .;C:/Dev/kafka/confluent-4.0.0/target/kafka-rest-*-development/share/java/kafka-rest/*;C:/Dev/kafka/confluent-4.0.0/share/java/confluent-common/*;C:/Dev/kafka/confluent-4.0.0/share/java/rest-utils/*;C:/Dev/kafka/confluent-4.0.0/share/java/kafka-rest/* io.confluent.kafkarest.KafkaRestMain C:/Dev/kafka/confluent-4.0.0/etc/kafka-rest/kafka-rest.properties
Make sure you change paths to yours if you want to try it out.
Perhaps, this answer will help anybody who is new to Kafka and stumble upon this situation, like me :).
I was looking for an answer to the very same question a week ago, came across the official suggestion to run jar files(in this path confluent-x.x.x\share\java\kafka-rest) in windows and was NOT successful in doing so.
Always ran into this error no main attribute found with or without specifying the proper classpath and io.confluent.kafkarest.KafkaRestMain.
I even tried running the shell scripts packaged for Linux distribution using [babun]: http://babun.github.io/, but that resulted in the error like Error: Could not find or load main class io.confluent.kafkarest.KafkaRestMain .
Eventually, docker image built with zookeeper, kafka, schema-registry, kafka-rest worked like a charm.
Here is the official page with info about the image name, further reference to it's doc: https://hub.docker.com/r/confluentinc/cp-kafka-rest/
Upon pulling this image, a new virtual machine gets created with four more images inside it(one for each service like zookeeper, Kafka, schem-registry and Kafka-rest). Running the images runs a separate Docker container.
This guide should get you started quickly:
http://docs.confluent.io/current/cp-docker-images/docs/quickstart.html
And finally, if you would like to expose the kafka REST proxy server running as a Docker container to outside network(like windows machine which is part of the separate network than these containers) just mention the Docker host IP(find it by hitting docker-machine ip <hostname>) in KAFKA_REST_LISTENERS and expose the port with -p option.
Like this:
docker run -d \
--net=host \
--name=kafka-rest \
-p 8082:8082 \
-e KAFKA_REST_ZOOKEEPER_CONNECT=localhost:32181 \
-e KAFKA_REST_LISTENERS=http://192.168.99.100:8082 \
-e KAFKA_REST_SCHEMA_REGISTRY_URL=http://localhost:8081 \
-e KAFKA_REST_HOST_NAME=localhost \
confluentinc/cp-kafka-rest:3.2.1
If everything is OK, you will be able to access REST proxy at this url http://<Docker_host_IP>:8082 from the windows machine.
I was able to run the command that #lexler mentioned above, but outside of cygwin. (directly with the windows command prompt.)

postgresql: pg_ctl status shows no server running when the server is running as a windows service

I have PostgreSQL 9.4(not installed, rather self configured) which is also installed as a Windows service. Now I am trying to check the status of the server using pg_ctl.exe status -D data_dir_path, but it only shows the status when I start the console as admin.
My final goal is to be able to shutdown/ start the database server without admin rights. Is it possible to configure PostgreSQL so that I can start/stop the servers locally without admin rights?
As far I read in the PostgreSQL documentation, the services can be registered to a user using [-U username] [-P password] arguments but I am not sure whether this is the database user or the local windows user. I tried registering the service using the following code but it does not install it. And I do not see any logs too. The commnd follows:
pg_ctl.exe register -N service_name -U database_user -P database_user_password -D data_dir_path -S auto -o "-p port"
Thanks in advance

memcached doesn't start on vagrant up with CentOS 6.5

I'm trying to provision a development box with Vagrant and a CentOS 6.5 base box. I want memcached to automatically start at system boot/vagrant up.
I have tried adding memcached -d -l localhost -p11211 to /etc/rc.d/rc.local and this does not work.
I have also tried adding to /etc/init/vagrant-mounted.conf
start on vagrant-mounted
memcached -d -l localhost -p11211
[EDIT]
I've updated /etc/rc.d/rc.local to now use the following
chkconfig memcached on
service memcached start
I'm not seeing anything in the /var/log/boot.log. It looks like rc.local is not being run at all. It has ugo+x permissions; so the file is definitely executable, but it doesn't appear to run at all.
Does memcached -d -l localhost -p11211 exit immediately or spawn a process?
If it keeps running, try: nohup memcached -d -l localhost -p11211 &
Also, try putting it in /etc/rc.local as
memcached -d -l localhost -p11211 >/var/log/memcached.log 2>&1
That will give you a log file with possible errors.
Lastly, does your install of memcached not have an init.d file in /etc/init.d ?
if it does, simply do chkconfig servicename on && service servicename start

How to Install Postgresql v9.1 and JBoss AS v7.1.1 on Ubuntu 12.04 LTS

There are really good sources that describe how to install Postgresql and JBoss on Ubuntu 12.04 LTS but information is distributed accross other pages.
However, it would be good to have a walktrough guide to easily install and configure these.
Preparing for installation
sudo apt-get install postgresql postgresql-contrib postgresql-common pgadmin3 openssh-server openssh-client
This command will install latest Postgresql, PgAdmin3, Postgresql-contrib and SSH server packages. SSH server is not necessarily required but it is good to manage the server remotely. So I've added it to the install list. [1]
Oracle Java JDK and JBoss AS installations are not automatic. So we should download them from their web sites. We'll use jdk-7u10-linux-i586.tar.gz (or later version) and jboss-as-7.1.1.Final.tar.gz
See http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html for JDK and http://www.jboss.org/jbossas/downloads/ for JBoss.
or try the commandline links below [2]. (The links might get invalid in the future, sorry for that...)
wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-i586.tar.gz"
wget "http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.tar.gz"
Note that one might like to install OpenJDK which is available on apt-get repository and preferred by Ubuntu. However that is a preference and I'd like to use Oracle's JDK.
Optional: Adding extra locale support for Postgresql:
In my experience I needed Turkish locale support on Postgresql but it was not installed on Ubuntu by default. Here are sample commands to add Turkish collation support to Ubuntu, hence to Postgresql. [3]
sudo locale-gen tr_TR
sudo locale-gen tr_TR.UTF-8
Configuring Postgresql
We've already installed postgresql via apt-get. Now it would be good to make some changes to the config. [4]
By default Postgresql does not allow TCP connections. Edit postgresql.conf (my favorite editor is pico)
sudo pico /etc/postgresql/9.1/main/postgresql.conf
add
listen_addresses = '*' #Listens on all interfaces!!
or uncomment
listen_addresses = 'localhost' #More secure way to configure the server. Prefer this one if you won't connect to the server remotely
line.
If you selected to bind to all interfaces instead of localhost, then you'll need an extra configuration to allow remote connections. [5] Open up pg_hba.conf
sudo pico /etc/postgresql/9.1/main/pg_hba.conf
Add the line:
host all all 0.0.0.0/0 md5
Restart Postgresql to apply new config.
sudo /etc/init.d/postgresql restart
Now we'll set the password for default postgres user [6]. First fire up postgresql commandline.
sudo -u postgres psql
execute the following command. [7]
postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD '<your new password>';
Now you may connect to your server via PgAdmin3 or your favorite SQL Client or via command line...
Installing and Configuring Java and JBoss AS 7.1.1
I've selected /opt directory as our install directory. You are free to choose your own as long as you configure scripts accordingly. First extract JDK.
sudo tar -zxvf <Full Path to jdk-7u10-linux-i586.tar.gz> -C /opt
This will extract JDK to **/opt/jdk1.7.0_10* directory. Now we'll extract and configure JBoss AS. [8] [9]
First create a user for JBoss (jboss-as), it is a good habit to run your servers impersonating a user instead of directly executing them as root. This will tighten security.
sudo useradd -s /bin/sh jboss-as
Extract jboss-as-7.1.1.Final.tar.gz to /opt/jboss-as-7.1.1.Final
sudo tar -zxvf <Full Path to jboss-as-7.1.1.Final.tar.gz> -C /opt
I assume you'll run JBoss in standalone mode. Open up standalone.conf add the lines below.
JAVA_HOME="/opt/jdk1.7.0_10" #show your JAVA_HOME directory to JBoss
JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address=0.0.0.0" #Bind to 0.0.0.0 so that remote clients can connect to your server.
Impersonate jboss-as user by executing
sudo -su jboss-as
First test the server by executing
cd /opt/jboss-as-7.1.1.Final
./standalone.sh
It should fire-up without problems. Use CTRL+C to shut down the server. You might connect to the server on your browser at port 8080.
http://<your server address>:8080
Now we'll create a management user for JBoss. It is required to use administration console running at port 9990.
export JAVA_HOME=/opt/jdk1.7.0_10/
./add-user.sh
Management User -> Select (a)
Realm (Management Realm) -> Accept the default and press enter
Username : -> Enter <your admin user name>
Password : -> Enter <your password>
Is this correct yes/no? -> Type 'yes' and press Enter
Added user '<your admin user name>' to file '/opt/jboss-as-7.1.1.Final/standalone/configuration/mgmt-users.properties'
Added user '<your admin user name>' to file '/opt/jboss-as-7.1.1.Final/domain/configuration/mgmt-users.properties'
Exit from impersonated jboss-as user.
exit
Now you may configure your server via its web interface at
http://<your server address>:9990
This address only accept your if you are at localhost Whenever you need to configure your server remotely, fire up the server with the following command.
sudo -u jboss-as ./standalone.sh -Djboss.bind.address.management=0.0.0.0
Again for security reasons do not bind to 0.0.0.0 if you don't need it.
Install JBoss as System Service
We'll prepare a server management script for init daemon (aka. init.d) [10]
cd /etc/init.d/
sudo pico jboss
Copy and paste the content below. Do not forget to modify JAVA_HOME, JBOSS_HOME directories and --chuid jboss-as (impersonates as jboss-as user when running the server) parameter accordingly.
#!/bin/sh
### BEGIN INIT INFO
# Provides: jboss
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop JBoss AS v7.1.1 Final
### END INIT INFO
#
#source some script files in order to set and export environmental variables
#as well as add the appropriate executables to $PATH
export JAVA_HOME=/opt/jdk1.7.0_10
export PATH=$JAVA_HOME/bin:$PATH
export JBOSS_HOME=/opt/jboss-as-7.1.1.Final
export PATH=$JBOSS_HOME/bin:$PATH
case "$1" in
start)
echo "Starting JBoss AS 7.1.1 Final"
start-stop-daemon --start --quiet --background --chuid jboss-as --exec ${JBOSS_HOME}/bin/standalone.sh
;;
stop)
echo "Stopping JBoss AS 7.1.1 Final"
start-stop-daemon --start --quiet --background --chuid jboss-as --exec ${JBOSS_HOME}/bin/jboss-cli.sh -- --connect command=:shutdown
;;
*)
echo "Usage: /etc/init.d/jboss {start|stop}"
exit 1
;;
esac
exit 0
Set the script as executable and update rc.d
sudo chmod +x jboss
sudo update-rc.d jboss defaults
Now JBoss will start with your server. You might use the commands below to start and stop the server
sudo service jboss start
sudo service jboss stop