Check IP on Docker Image

Problem

I had a situation where one docker image with a webserver was connecting to another docker image with a MySQL server. Now couple of other docker images were added to the server and this caused an IP change on the MySQL docker image. So I needed a way to check the New IP.

Solution

Used the following to get the IP of the docker image:

# docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)

Resources

Getting a docker container’s ip address from the host

Linux Change Timezone Terminal

Problem

Had a docker images that wasnt in the correct timezone.

Solution

For one docker image, the solution was to use:

ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime

The other docker image, I used:

dpkg-reconfigure tzdata

Another way to do this is to list the timezones and then set as follows:

#timedatectl list-timezones
#timedatectl set-timezone Europe/Athens

Resources

How to change time-zone settings from the command line

Upsource and Youtrack Start Failure

Problem

On server reboot, Upsource and Youtrack would intermittently start up. I had changed the runlevels so that these 2 start after hub but still the problem persisted.

Solution

Changed the order of starting hub from K20 S20 to K10 S10 for the different runlevels.

# update-rc.d -f hub remove
 Removing any system startup links for /etc/init.d/hub ...
 /etc/rc0.d/K20hub
 /etc/rc1.d/K20hub
 /etc/rc2.d/S20hub
 /etc/rc3.d/S20hub
 /etc/rc4.d/S20hub
 /etc/rc5.d/S20hub
 /etc/rc6.d/K20hub
# update-rc.d hub start 10 2 3 4 5 . stop 10 S 0 1 6 .
Adding system startup for /etc/init.d/hub ...
/etc/rc0.d/K10hub -> ../init.d/hub
/etc/rc1.d/K10hub -> ../init.d/hub
/etc/rc6.d/K10hub -> ../init.d/hub
/etc/rcS.d/K10hub -> ../init.d/hub
/etc/rc2.d/S10hub -> ../init.d/hub
/etc/rc3.d/S10hub -> ../init.d/hub
/etc/rc4.d/S10hub -> ../init.d/hub
/etc/rc5.d/S10hub -> ../init.d/hub

Resources

System run levels and init.d scripts

ubuntu 14.04 /etc/init.d/ vs /etc/init/ start service at startup

Runlevel

The Upstart Event System: What It Is And How To Use It

UpstartHowto

UbuntuBootupHowto

how-to-enable-or-disable-services

how-to-enable-or-disable-services 2 

Configure Docker to start on boot

Running Docker

Change DNS IP Linux Mint 18

Problem

The automatic ISP DNS IP was faulty. Need to switch to another DNS server. Another problem was that Editing the resolv.conf would be overwritten.

Solution

  • Click on the Wi-fi button And select Network Connections:
Wifi Icon
Wifi Icon
Network Connections
Network Connections
  • Click on the Wifi Network you want to add the DNS addresses. From the resulting Dialogue box, click on the IPv4 Settings and add the Additional DNS servers e.g the OpenDNS IPs 208.67.220.220; 208.67.222.222 and then save:
Add DNS IPs
Add DNS IPs
  • Then Click on the Wi-Fi Icon and click on Network Settings. Then select the Preferences Icon (As shown in the screenshot below). Then Click on IPv4 and In the DNS Section Click on the Automatic ON button so that its OFF and then click Apply:
Network Settings
Network Settings

Network Preferences - IPv4 selection

Network Preferences – IPv4 selection

Network Preferences - Save Changes

Network Preferences – Save Changes

  • Finally turn of the Wifi and Turn it ON again and your changes should persist. You should be using the New DNS addresses IPs ONLY.

Docker – HowTos

Tips

  • To check which containers are running:
docker ps
  • To get into a docker container’s terminal:
docker exec -it docker-container-name sh
  • To copy a file to a docker container:
docker cp /home/user/path to file you want to copy.txt docker-container-name:/home/destination_folder/

Review Tomcat7 Ubuntu Package Upgrade Before Updating

Problem

I needed to see what had changed in the new ubuntu update of tomcat 7 before installing the update for apt-get upgrade.

Solution

First check the version of ubuntu installed. Also check the version of ubuntu you are running:

 # lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty

Then go to the tomcat7 package in Ubuntu and depending on you Ubuntu release check what has changed :

Ubuntu Tomcat 7 Package information (https://launchpad.net/ubuntu/+source/tomcat7)
Ubuntu’s Tomcat7 Package Information (https://launchpad.net/ubuntu/+source/tomcat7)
Ubuntu Tomcat 7 Package information (https://launchpad.net/ubuntu/+source/tomcat7)
Ubuntu’s Tomcat7 Package Information (https://launchpad.net/ubuntu/+source/tomcat7)

Sources

tomcat7 package in Ubuntu

Why don’t the Ubuntu repositories have the latest versions of software?

 

Check Tomcat Version

Problem

Needed to check the version of tomcat running before I could decide whether of not to update it.

Solution

From the command line look for where the version.sh file is:

$ sudo find / -name "version.sh"

Once you find it run this bash script as follows:

# /usr/share/tomcat7/bin/version.sh
Using CATALINA_BASE: /usr/share/tomcat7
Using CATALINA_HOME: /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME: /usr/lib/jvm/java-7-oracle
Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.52 (Ubuntu)
Server built: Jun 30 2016 01:59:37
Server number: 7.0.52.0
OS Name: Linux
OS Version: 3.13.0-53-generic
Architecture: amd64
JVM Version: 1.7.0_80-b15
JVM Vendor: Oracle Corporation

Sources

How to check Tomcat version Installed

Mysql 5.7 Customizations

Problem

Needed to remove the ONLY GROUP BY sql mode and also change the default Character Set

Solution

Login to the MySQL shell and the select the available SQL Modes excluding the ONLY GROUP BY mode:

mysql> select @@sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Add the SQL modes to the mysql conf file on Ubuntu 16_04, located in /etc/mysql/mysql.conf.d/mysqld.cnf

Also add the utf8 character set under mysqld in the above conf file so you will have the following:

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

Then restart MySQL:

root@whiscardz ~ # service mysql stop
root@whiscardz ~ # ps aux | grep mysql
root 9789 0.0 0.0 15444 1028 pts/1 S+ 09:27 0:00 grep --color=auto mysql
root@whiscardz ~ # service mysql start
root@whiscardz ~ # ps aux | grep mysql
mysql 9828 12.0 0.8 1229212 146004 ? Ssl 09:27 0:00 /usr/sbin/mysqld
root 9865 0.0 0.0 15444 980 pts/1 S+ 09:27 0:00 grep --color=auto mysql

Check the Character SET and sql mode:

mysql> select @@sql_mode;
+------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode |
+------------------------------------------------------------------------------------------------------------------------+
| STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show variables where variable_name like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> show variables where variable_name like '%collation%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

References

disable-only-full-group-by

mysql-5-7-12-disabling-only-full-group-by-sql-mode-is-not-fully-successful

cant-change-charset-in-mysql-5-7-from-latin-to-utf8

mysql-utf8-character-set

Java Heap Size Exception

Problem

I was getting this error after setting up a new instance of Tomcat7, using Java 1.7 and running OpenMRS2:

Exception in thread “ActiveMQ Journal Checkpoint Worker” java.lang.OutOfMemoryError: Java heap space
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethod(Class.java:2128)
at java.io.ObjectStreamClass.getInheritableMethod(ObjectStreamClass.java:1442)
Exception in thread “ActiveMQ Broker[localhost] Scheduler” at java.io.ObjectStreamClass.access$2200(ObjectStreamClass.java:72)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:510)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:472)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:472)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:369)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1134)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at org.apache.activemq.store.kahadb.MessageDatabase.checkpointProducerAudit(MessageDatabase.java:1250)
at org.apache.activemq.store.kahadb.MessageDatabase.checkpointUpdate(MessageDatabase.java:1134)
at org.apache.activemq.store.kahadb.MessageDatabase$10.execute(MessageDatabase.java:698)
at org.apache.kahadb.page.Transaction.execute(Transaction.java:728)
at org.apache.activemq.store.kahadb.MessageDatabase.checkpointCleanup(MessageDatabase.java:696)
at org.apache.activemq.store.kahadb.MessageDatabase$3.run(MessageDatabase.java:293)
java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.newNode(HashMap.java:1734)
at java.util.HashMap.putVal(HashMap.java:630)
at java.util.HashMap.putMapEntries(HashMap.java:514)
at java.util.HashMap.<init>(HashMap.java:489)
at org.apache.activemq.broker.region.AbstractRegion.getDestinationMap(AbstractRegion.java:223)
at org.apache.activemq.broker.region.RegionBroker.getDestinationMap(RegionBroker.java:134)
at org.apache.activemq.broker.region.RegionBroker.purgeInactiveDestinations(RegionBroker.java:922)
at org.apache.activemq.broker.region.RegionBroker$1.run(RegionBroker.java:110)
at org.apache.activemq.thread.SchedulerTimerTask.run(SchedulerTimerTask.java:33)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

A Java Heap Size error occurs because of certain memory intensive actions (like Data Exporting). The new Spring managed API uses a lot of memory to cache the xml beans. You may need to increase the default memory allocation.

Solution

According to this wiki page, the solution was to adjust the memory settings. Depending on your OS, I was using Ubuntu 16.04.1 LTS.

vim /etc/default/tomcat7

Then change the JAVA_OPTS variable to:

JAVA_OPTS=”-Djava.awt.headless=true -Xmx1024M -Xms1024M -XX:PermSize=256m -XX:MaxPermSize=256m -XX:NewSize=128m”

You can adjust the memory as per your needs, in my case this was multiplying everything by 2:

JAVA_OPTS=”-Djava.awt.headless=true -Xmx2048M -Xms2048M -XX:PermSize=512m -XX:MaxPermSize=512m -XX:NewSize=256m”

Resources

Troubleshooting Memory Errors

Java heap space errors when starting a new installation