SQL Server AWS RDS instance ALARM FreeableMemory <=... MB

The SQL database servers use the available memory for caching to speed up the database operation. If we do not restrict the SQL database server memory usage, the operating system will not have enough memory to run. This setting is also necessary for an AWS RDS instance, otherwise, you will get the alert

ALARM FreeableMemory <=… MB

In AWS we can specify the maximum SQL server memory dynamically, so every RDS instance type will leave enough memory for the operating system regardless of the size of the available memory size. in this example, we will leave 1.5 GB (1536 MB) memory for the operating system so the default 1024 MB free memory alarm will not sound.

DBInstanceClassMemory returns the total memory size in bytes, so we need to convert the value to MB, to be able to set the value of “max server memory (mb)” to the correct number.

If you use Terraform to create your RDS instance, create a script with the aws_db_parameter_group resource to create a Parameter Group in your AWS account. You need to execute it once, as all RDS instances will use the same group.

resource "aws_db_parameter_group" "default" {

  name = "max-server-memory"
  family = "sqlserver-se-12.0"
  description = "DBInstanceClassMemory"

  parameter {
    name = "custom-sqlserver-se-12-0"
    value = "SUM({DBInstanceClassMemory/1048576},-1536)"
    apply_method = "immediate"
  }
}

In the RDS instance creation script assign the Parameter Group to the RDS instance and increase the timeout of the create and delete operations to make sure Terraform waits during the creation and deletion process.

resource "aws_db_instance" "default" {
...
  # Add the Max Server Memory parameter group to the instance
  parameter_group_name = "custom-sqlserver-se-12-0"
...
  timeouts {
    create = "120m"
    delete = "120m"
  }
...
}

 

 

 

Terraform provider.aws: no suitable version installed

The new versions of Terraform do not contain all plugins after the application installation. When you try to access a provider the first time, Terraform may not be able to communicate with it.

* provider.aws: no suitable version installed
version requirements: “(any version)”
versions installed: none

To download the necessary plugins, initialize the Terraform script directory

terraform init

The command will instruct Terraform to get all referenced modules and download all necessary plugins.

 

 

Display all teams you belong to in GitHub

To get the information on all teams you are part of in Github

  1. Open a Terminal window
  2. Execute this command with your Personal Access Token
curl -H "Authorization: token YOUR_PERSONAL_ACCESS_TOKEN" https://api.github.com/user/teams

The returned JSON will display all information on the teams you belong to.

To generate a personal access token

See Create a Personal Access Token to use it as password in the Git client at Git configuration

Chef NoMethodError, undefined method

When you try to bootstrap a node to a Chef server, you may get the error message

Compiling Cookbooks…
==============================================================
Recipe Compile Error in c:/chef/cache/cookbooks/…/attributes/default.rb
==============================================================
NoMethodError
————-
undefined method `…=’ for #<Chef::Node::VividMash:0x0000000004ca3268>

Relevant File Content:
>> default. …

In my case, the cookbook compiler could not interpret the dot notation in the recipes.

There are multiple ways to declare and use the Chef attributes:

default['ATT_NAME']

default["ATT_NAME"]

default[:ATT_NAME]

default.ATT_NAME

The last format, the dot notation is a legal form, but not accepted by the compiler that checks the cookbooks during bootstrapping. The same cookbook works perfectly in Test Kitchen, and in chef-client.

The solution is to change the dot notation to one of the other formats, preferably to the first in the list above.

 

Package dependent Java JAR files into the project JAR file

When you execute your Java JAR file, you need to include all dependent JAR files in the “fat jar” file, so the Java virtual machine can find them at runtime.

Set up NetBeans to include the JAR files from the library

In NetBeans you need to add the list of dependent libraries to the build.xml file.

  1. On the Files tab double-click the build.xml file to open it in the editor,
  2. Add the lines below to the build.xml file before the </project> statement. Change the value of the second line to specify the name of your project.
    <target name="package-for-store" depends="jar">
        <property name="store.jar.name" value="MY_PROJECT"/>
        <property name="store.dir" value="store"/>
        <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
        <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
        <delete dir="${store.dir}"/>
        <mkdir dir="${store.dir}"/>
        <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
            <zipgroupfileset dir="dist" includes="*.jar"/>
            <zipgroupfileset dir="dist/lib" includes="*.jar"/>
            <manifest>
            <attribute name="Main-Class" value="${main.class}"/>
            </manifest>
        </jar>
        <zip destfile="${store.jar}">
            <zipfileset src="${store.dir}/temp_final.jar"
            excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
        </zip>
        <delete file="${store.dir}/temp_final.jar"/>
    </target>
  3. Save the build.xml file.

Build the project

  1. Right click the build.xml file,
  2. Select Run Target > Other Targets > package-for-store
  3. The generated file is going to be located in the store directory.

Restore Windows Server 2012 R2 from backup

Windows Server contains the Windows Backup functionality. It can create full backups of your server that contain all volumes. With the bare metal recovery, you are able to fully restore the server even if the hard disks fail, after a virus attack, or security breach. Depending on the size of the server drives and the backup media, set up frequent backup times, so when you need to restore the server, less data has to be entered again.

To restore a Windows Server from a backup image

  1. Insert the Windows Server 2012 R2 installation DVD into the DVD drive of the server
  2. Boot the server from the DVD
  3. Connect the drive, that contains the backup images, to the server
  4. On the first screen select the language and keyboard options
  5. On the next screen, select Repair  your computer
  6. Select the Troubleshoot icon
  7. Click the System Image Recovery
  8. Select your operating system as the target operating system
  9. Select the backup image to restore; latest or from a previous date
  10. If you selected Select a system image option
    1. In the table select the backup device
    2. Select the time of the backup
    3. If you want to clear the drives of the server select the Format and repartition disks option

Tomcat web server installation

Tomcat is one of the most popular free web servers. Tomcat runs on the Linux, Macintosh, and Windows operating systems.

To install Tomcat

Install the Java Runtime Environment (JRE)

  1. Download the Java JRE from http://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. Install the Java JRE

On Windows

  1. Execute the downloaded .exe file
  2. Create an environment variable to point to the installed Java
    1. If you installed the Java JDK (Java Development Kit)
      1. JAVA_HOME=c:\Program Files\Java\jdk-…
    2. If you installed the JRE (Java Runtime Environment)
      1. JRE_HOME=C:\Program Files\Java\jre-…

 

Install Tomcat

  1. Download the Tomcat installer from https://tomcat.apache.org/
  2. To select the right file to download read the explanation on the page linked to “Please see the README file for packaging information”.

On Windows

Select the installer based on the operating system and the Java environment you want to run:

  • 32 bit Java Virtual Machine on32 bit or 64 bit Windows: apache-tomcat-[version]-windows-x86.zip
  • 64 bit Java Virtual Machine on 64 bit Windows: apache-tomcat-[version]-windows-x64.zip
  1. Unzip the downloaded archive and move the apache-tomcat-x.x.x directory to C:\Program File
  2. Create the Tomcat environment variable
    CATALINA_HOME=C:\Program Files\apache-tomcat-x.x.x

Start Tomcat

  1. Open a terminal or console in the Tomcat bin directory
  2. Execute
    startup
  3. Enable the access to the Tomcat server through the firewall
    1. On Windows

Test Tomcat

  1. Open a web browser on the server and navigate to http://localhost:8080/
  2. You should see the Tomcat default page

Auto start Tomcat

If you want to use Tomcat as a web server, it should start automatically when the computer starts.

On Windows

  1. Open a command prompt in the tomcat bin directory
  2. Execute
    service.bat install
  3. On the User Account Control popup click the Yes button
  4. The last message in the command prompt should say

    The service ‘Tomcat..’ has been installed.

  5. Open  Services and select the Apache Tomcat service
  6. Set the Startup type to Automatic, click the Start button to start the service, and click OK.

 

Enable Single Sign-On (SSO) in TeamCity

Enable Single Sign-On (SSO) in TeamCity

TeamCity can use the Windows Active Directory to authenticate users. To configure TeamCity to automatically log in users who are already logged into the Windows domain enable the Single Sign-On (SSO) functionality.

  1. In the upper right corner of the TeamCity web interface select Administration,
  2. On the left side in the Server Administration section select Authentication,
  3. Under HTTP authentication modules click the Load preset… button,
  4. In the drop-down list select Microsoft Windows Domain,
  5. Click the Edit link of the Microsoft Windows domain,
  6. Enter the name of the domain in your organization. If you leave the Allow creating new users… checkbox enabled, when new users log into TeamCity they are placed into a default user role. Make sure that role does not give them any authority.

Accessing TeamCity using Single Sign-On (SSO)

  1. With your web browser navigate to MY_TEAMCITY_SERVER/ntlmLogin.html,
  2. If asked, enter your domain username and password once,
  3. Subsequent logins in the same browser will not require authentication while the browser stays open.

Upgrade TeamCity to a new version

Create a backup of the database and the server before the upgrade

  1. Place an instance with a maintenance screen in the load balancer,
  2. Remove the TeamCity server from the load balancer,
  3. Disable the Chef-Client scheduled task and Chef-Client service to make sure Chef does not alter the server during the upgrade.
  4. Disable the authorized agents to stop them picking new jobs.
  5. Stop the TeamCity process on the server,
    1. If TeamCity is started by a scheduled task at startup
      1. Disable the “teamcityserver” scheduled task in the Task Scheduler,
      2. Stop the “Java(TM) Platform SE binary” process in Task Manager.
    2. If TeamCity is running as a Windows Service
      1. Stop and disable the “TeamCity” service.
  6. Save a copy of the TeamCity configuration directories to the data drive and an outside location
    1. D:\TeamCity\conf to D:\backup\conf – TODAY’S_DATE
    2. D:\ProgramData\JetBrains\TeamCity\config to D:\backup\config – TODAY’S_DATE
      Some file names in the D:\ProgramData\JetBrains\TeamCity\config\projects directory can be very long, so save the backup close to the root of the drive.
  7. Create a backup image of your server,
    1. Select the server in the EC2 server list
    2. Click the Actions button and select Image, Create Image
    3. If you want to keep the server running, check the No reboot check box, but the file system integrity is not guaranteed.
  8. Create a backup snapshot of your database,
    1. In the RDS instance list select the database instance,
    2. Click the Instance actions button and select Take snapshot
  9. If the image creation did not restart the server, restart the box to make sure no processes hold files in the TeamCity install folder.

 


Upgrade TeamCity from the web user interface

  1. Remote into the TeamCity server
  2. Start the TeamCity service
  3. In a web browser navigate to http://localhost:8111/
  4. Log into TeamCity as an administrator
  5. Click the Administration link in the upper right corner
  6. Select the Updates link on the left under System Administration
  7. Click the Check for updates button
  8. On the Updates page click the Download update button
  9. TeamCity will start the download of the installer
  10. Click the Update button to start the update process
  11. Click the Update button to update the server
  12. Click the I’m a server administrator… link to allow the database upgrade. If TeamCity asks for the Authentication Token, find it at the end of the D:\TeamCity\logs\teamcity-server.log file
  13. Leave the Backup… checkbox checked and click the Upgrade button
  14. When the update suceeds, the Updates page appears again
  15. In case of the automatic update failure follow the instructions at https://confluence.jetbrains.com/display/TCD10/Upgrade#Upgrade-AutomaticUpdate

 


To install an earlier version of TeamCity, manually download the installer

  1. Turn off the Internet Explorer Enhanced Security Configuration,
  2. Enable file download on your server. Set the Internet Explorer security level to Medium-high
  3. Download the TeamCity server installer
    1. To download the latest TeamCity version navigate to
      http://www.jetbrains.com/teamcity/download/
    2. For earlier versions go to https://confluence.jetbrains.com/display/TW/Previous+Releases+Downloads

Install the new version of TeamCity server

  1. Execute the downloaded installer from the Downloads folder,
  2. If the current version of TeamCity is not on the C drive, make sure you select the correct drive,
  3. JetBrains recommends the uninstallation of the previous version of TeamCity,
  4. JetBrains does not recommend the agent instalation on the server, disable it,
  5. Run TeamCity under the SYSTEM account,
  6. To start TeamCity, leave the checkbox selected,
  7. TeamCity can automatically open the web user interface in your default browser,

TeamCity configuration


When you first try to launch the TeamCity server on a 64 bit Windows, you may get the message:

This page can’t be displayed
•Make sure the web address http://localhost:8111 is correct.
•Look for the page with your search engine.
•Refresh the page in a few minutes.

The D:\TeamCity\logs\teamcity-winservice.log file also contains the error message:

ProcessCommand [Info] Process exited with code: 1
console [Info] Error: Could not create the Java Virtual Machine.
console [Info] Error: A fatal exception has occurred. Program will exit.
console [Info] Invalid maximum heap size: -Xmx10g
console [Info] The specified size exceeds the maximum representable size.
ServiceExecuteProcessTask [Error] Service process exited without service stop request

Follow the instructions below to switch to 64 Java.

TeamCity on 64-bit Java

The TeamCity installer also installs the 32-bit version of the Java Runtime Environment (JRE) in the “D:\TeamCity\jre” folder. To use the 64 bit Java, test if your server has 64-bit Java installed:

  1. Open a command window and execute,
    java.exe -d64 -version
  2. The installed Java is 32 bit if you get the error message:
    Error: This Java instance does not support a 64-bit JVM.
    Please install the desired version.

Switch to 64-bit Java

  1. Stop the TeamCity Windows Service,
  2. Rename the D:\TeamCity\jre to jre_32bit, so TeamCity will not find it anymore,
  3. If you have not specified the memory settings in the Set the TEAMCITY_SERVER_MEM_OPTS environment variable based on the physical memory size of your server and the estimated usage
    1. Start Windows Explorer
    2. Right-click This PC and select Properties
    3. Select Advanced system settings
    4. Click the Environment Variables… button
    5. In the System Variables section select TEAMCITY_SERVER_MEM_OPTS
    6. Set the value based on the expected server load:
      1. minimum setting for 32-bit and 64-bit java:
        -Xmx750m
      2. recommended setting for medium 64-bit server and maximum for 32-bit server:
        -Xmx1024m
      3. recommended setting for large server (64-bit java only):
        -Xmx4g -XX:ReservedCodeCacheSize=350m
      4. maximum settings for large-scale server use (64-bit java only):
        -Xmx10g -XX:ReservedCodeCacheSize=512m

Source: https://confluence.jetbrains.com/display/TCD10/Installing+and+Configuring+the+TeamCity+Server#InstallingandConfiguringtheTeamCityServer-SettingUpMemorysettingsforTeamCityServer

 


Finish the TeamCity upgrade

    1. Remote into the TeamCity server,
    2. Start the TeamCity Server Windows service,
    3. Open a web browser and navigate to http://localhost:8111/
    4. Click the I’m a server administrator… link,
    5. Find the authentication token at the end of the D:\TeamCity\logs\teamcity-server.log file
    6. Enter it into the textbox
    7. Allow TeamCity to make a backup of your current data,
    8. TeamCity will display the progress of the backup process.
    9. TeamCity will automatically start the server initialization.
    10. And finally, will display the login page.
  1. Navigate to the Agents page.

    First, all agents will be on the Disconnected tab. The agents will upgrade themselves to the same version as the server, and one-by-one will appear on the Connected tab.

In case of the automatic update failure follow the instructions at https://confluence.jetbrains.com/display/TCD10/Upgrade#Upgrade-AutomaticUpdate

 


Disaster recovery

If for some reason the server does not work after the upgrade, you can restore the database and the server from the backups you made before the upgrade.

Rebuild the environment

  1. Terminate the failed TeamCity server
  2. Restore the database from the backup snapshot
  3. Launch a new server instance from the backup server image

Make sure that the TeamCity process is not running on the restored server

When the server has started, remote into it.

  1. Check if the TeamCity process has been stopped:
    1. If TeamCity is started by a scheduled task at startup
      1. Disable the “teamcityserver” scheduled task in the Task Scheduler,
      2. Stop the “Java(TM) Platform SE binary” process in Task Manager.
    2. If TeamCity is running as a Windows Service
      1. Stop and disable the “TeamCity” service.

Update the server configuration

TeamCity stores the address of the database and the IP address of the server in config files. To be able to use the restored server, make the following changes:

Update the database address

  1. Update the database address in the connectionUrl line of D:\ProgramData\JetBrains\TeamCity\config\database.properties

Update the IP address of the server

  1. Update the server IP address in the server rootURL element of D:\ProgramData\JetBrains\TeamCity\config\main-config.xml

Start TeamCity

  1. Start the TeamCity service or scheduled task

Test the TeamCity server

  1. Open a web browser on the server and navigate to http://localhost:8111/

Load Balancer

  1. Attach the server to the load balancer

`pwd’: No such file or directory – getcwd (Errno::ENOENT)

When you rename a subdirectory under the directory where your Linux or MacOS terminal is open you may get the error message

/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.4.19/lib/chef/knife/cookbook_download.rb:45:in `pwd’: No such file or directory – getcwd (Errno::ENOENT)

You need to refresh the directory cache of the terminal.

  1. Go one level higher
    cd ..
  2. Go back to the directory
    cd MY_DIRECTORY