Upgrade TeamCity to version 10

Upgrade TeamCity to version 10

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

  1. Disable the Chef-Client scheduled task and Chef-Client service to make sure Chef does not alter the server during the upgrade.
  2. Disable the authorized agents to stop them picking new jobs.
  3. 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.
  4. Save a copy of the TeamCity configuration directories to the data drive and an outside location
    1. D:\TeamCity\conf
    2. D:\ProgramData\JetBrains\TeamCity\config
      Some file names in the D:\ProgramData\JetBrains\TeamCity\config\projects directory can be very long, so save the backup first in the root of the data drive
  5. Create a backup image of your server,
  6. Create a backup snapshot of your database,
  7. If the image creation did not restart the server, restart the box to make sure no processes hold files in the TeamCity install folder.

Download the TeamCity installer

  1. Enable file download on your server. Set the Internet Explorer security level to Medium-high
  2. 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. It is not recommended to run agents on the server box. Uncheck the Windows Services and Core for the Build Agent,
  4. If you get Folder is not empty… messages, delete the files from the indicated locations and click the Retry button,
  5. Set the correct port TeamCity should to use 
  6. Even if you haven’t enabled the agent functionality on the TeamCity server, you will see the Configure Build Agent Properties page. Click the Save button to continue.
  7. Select the SYSTEM account to run the TeamCity service
  8. Click the Next button to start the TeamCity service

Warning:

If you have specified larger memory setting than 32 bit Java is capable of handling, the TeamCity service will not start. You will get the following error message in D:\TeamCity\logs\teamcity-winservice.log

ProcessCommand [Info] Process exited with code: 1
console [Info] Error occurred during initialization of VM
console [Info] Could not reserve enough space for 2097152KB object heap
ServiceExecuteProcessTask [Error] Service process exited without service stop request

To switch to 64 bit Java, follow the steps below.

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 OLD_jre, 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 Envirnment 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

Remove unsupported memory settings

TeamCity version 10 does not use -XX:MaxPermSize anymore. If you get

[Info] Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=2048m; support was removed in 8.0

remove “MaxPermSize” from theTEAMCITY_SERVER_MEM_OPTS environment variable.

Start the server

  1. Open Services and start the TeamCity Server Windows service
  2. Open a web browser and navigate to http://localhost:8111
  3. On the TeamCity Maintenance page select the I’m a server administrator, show me the details link
  4. Open the D:\TeamCity\logs\teamcity-server.log file and find the Administrator can login from web UI using authentication token line and copy the token number to the clipboard
  5. Paste the token to the textbox and click the Confirm button
  6. On the TeamCity Upgrade page click the Upgrade button
  7. TeamCity will make a backup of the current projects to D:\ProgramData\JetBrains\TeamCity\backup

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 ben 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

Restart

  1. Restart the box for the changes to take effect.

Set up the Artifactory repository authentication

To secure Artifactory repositories follow the steps below

  1. Log into Artifactory as an administrator
  2. On the left select Admin

Add users

  1. In the Security menu select Users
  2. In the upper right select New

  3. Create users for admin, writer, and reader. Make sure the Can Update Profile checkbox is NOT checked, so if someone logs in with the service account credentials cannot change the account settings.

    1. REPOSITORY-NAME_admin,
    2. REPOSITORY-NAME_writer,
    3. REPOSITORY-NAME_reader.

Create security groups and add the new users to the groups

  1. In the Admin menu select Security and Groups
  2. On the Group Management page select New
  3. Create groups for admins, writers, and readers. Add “s” to the name of the group to differentiate it from the user.
    1. REPOSITORY-NAME_admins,
    2. REPOSITORY-NAME_writers,
    3. REPOSITORY-NAME_readers.
  4. In the Users section add the appropriate user to the group

Create permissions and add the groups to the permissions

  1. In the Security menu select Permissions
  2. In the upper right corner select New
  3. Create permissions to administer, write, and read the repository
    1. REPOSITORY-NAME_administer,
    2. REPOSITORY-NAME_write,
    3. REPOSITORY-NAME_read.
      1. Select the repository, click the green arrow to add the repository to the Selected Repositories list, and click Next
      2. Click the arrow next to the name of the group to add it to the list of groups
      3. Select the appropriate check boxes
        1. For writers select Delete/Overwrite, Deploy/Cache, Annotate, and Read
      4. Click the Save & Finish button.

To allow anonymous read access to the repository

To allow everyone to read the repository without authentication, add the anonymous user to the REPOSITORY-NAME_readers group.

The User Profile Service failed the sign-in. User profile cannot be loaded.

When you try to start a remote desktop connection to a Windows computer on the domain you may get the error message:

The User Profile Service failed the sign-in. User profile cannot be loaded.

To enable the User Profile update

  1. Remote into the computer with a local administrator account,
  2. In Windows Explorer open the C:\Users\Default\AppData folder,
  3. Right click the Roaming folder and select Properties,
  4. On the Security tab click the Advanced button,
  5. In the Permission entries list select System,
  6. Check the Replace all child object permissions… check box,
  7. Click the OK button,
  8. Click the Yes button on the Windows Security popup,
  9. Close the Properties window with the OK button.

Add SSH key to a Jenkins Git step

To access a Git repository Jenkins can use an SSH key.

To add the SSH key to the Jenkins server use the following Chef script

Store the SSH key in an encrypted data bag called “keys”.

{
 "id": "ci_private_keys",
 "ci_github_key": "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----",
}

 

Add the following to the Jenkins Chef recipe

  • Install Git
package 'git'
  • Install the Git and Credentials Jenkins plugins
jenkins_plugin 'git'
jenkins_plugin 'credentials'
  • Copy the SSH key to the Jenkins server
rsa_key = data_bag_item('keys', 'ci_private_keys')
file '/var/lib/jenkins/.ssh/id_rsa' do
  content "#{rsa_key['ci_github_key']}"
  owner 'jenkins'
  group 'jenkins'
  mode '0600'
end
  • Add github.com to the known hosts
bash 'provide github.com RSA fingerprint' do
  code <<-EOF
   ssh-keyscan github.com >> /var/lib/jenkins/.ssh/known_hosts
   chown jenkins.jenkins /var/lib/jenkins/.ssh/known_hosts
  EOF
  not_if{system('grep github.com /var/lib/jenkins/.ssh/known_hosts')}
end

 

To specify the SSH key in the Git step

  1. When the Jenkins server is operational, navigate to the Web interface
  2. Create a new Jenkins project
  3. In the Source Code Management section
    1. Select Git
    2. Enter the SSH URL of the repository
    3. When you are adding the first project, click the Add button to create the credential

      1. Click Jenkins to select the credentials provider
      2. Select SSH Username with private key as the Kind
      3. Enter the username you used when you created the SSH key for the Git repository
      4. Select From the Jenkins master ~/.ssh as the Private Key
      5. Click the Add button
    4. In the Credentials drop down select the credential you have created (the Git user name)

 

Obfuscated passwords in TeamCity

Obfuscate the password in the TeamCity UI

When a TeamCity build step needs to use a password, there is a way to obfuscate it.

  1. In the TeamCity web interface navigate to the project,
  2. On the project page open the Parameters page,
  3. Click the Add new parameter button,
  4. Enter the name of the parameter, the password value, and click the Edit button to set the special settings,
  5. Set the Display to Hidden, and the Type to Password to hide the value from the user interface. Click the Save button on this window and the on the parent window to save the parameter.
  6. To use the parameter in a build step, surround it with % signs.

Display the obfuscated password in the TeamCity UI.

To display the value of the password in the TeamCity UI again

  1. Select the attribute in the list
  2. Click the Edit button
  3. Set the type to Text and click the Save button
  4. On the Edit Parameter window click the Save button
  5. The password will be displayed in the parameter list.

Manage Windows Backups

To manage the Microsoft Windows Backups you can use a command line tool.

Open a command prompt as administrator

Show the existing backup versions

Wbadmin get versions

Clean up the backup disk

To keep a number of latest backups and delete the rest

Wbadmin delete backup -keepversions:NUMBER_OF_BACKUPS_TO_KEEP

To keep the latest backup only

Wbadmin delete backup -keepversions:1

To delete all existing backups

Wbadmin delete backup -keepversions:0

 

Chef custom resource is using the same property name as the called resource

When you create a Chef custom resource, you can call other resources including custom resources you have created. For ease of use it can be convenient to use the same property name as the called resource use.

property :delay_mins,          Fixnum, default: 3

reboot 'Hostname was changed' do
 reason reboot_reason
 delay_mins delay_mins
 action :request_reboot
end

When you you execute the code, chef will display the following error message:

property delay_mins is declared in both reboot[Hostname was changed] and utils_reboot[hostname_reboot] action :request_reboot. Use new_resource.delay_mins instead.

To tell Chef that you want to use the property you have created in this custom resource, add new_resource. in front of your property:

property :delay_mins,          Fixnum, default: 3

reboot 'Hostname was changed' do
 reason reboot_reason
 delay_mins new_resource.delay_mins
 action :request_reboot
end

Bluetooth: Not Available in Sierra on the Macintosh

After software update in Sierra on my Macintosh, my Bluetooth mouse usually stops working.

The toolbar displays the Bluetooth not available icon: 

When I click it, the “Bluetooth: Not Available” message is displayed.

There are two recommended actions we can take to bring Bluetooth back to life. If the first one does not help, try to execute them together during the same shutdown and restart cycle.

Delete the com.apple.Bluetooth.plist file from Library / Preferences

  1. Start Finder,
  2. In the Go menu select Go to Folder,
  3. Enter /Library/Preferences into the text box and click the Go button,
  4. Move the com.apple.Bluetooth.plist file to the trash,
  5. Shut down the Macintosh,
  6. Start the computer again.

Reset the SMC to reinitialize the Bluetooth module

  1. Shut down the Macintosh,
  2. Disconnect all peripherals (external display, drives, mouse, printer),
  3. Make sure the power adapter is connected to the computer,
  4. Press and hold the Shift, Control and Option buttons for 10 seconds,
  5. Start the computer with the power button, with the peripherals still disconnected,
  6. Re-connect the peripherals.

Second monitor does not work on Toshiba P-70A in Windows 10

Since I installed Windows 10 on my Toshiba P-70A laptop, the computer does not recognize the second monitor.

To make the second monitor work, I had to uninstall the display drivers and remove them from the computer:

  1. Open the File Explorer
  2. Right click This PC and select Properties
  3. In the upper left corner select Device Manager
  4. Expand the Display adapters section
  5. Right click each display adapter,
    1. Select Uninstall
    2. Check  Delete the driver software for this device
  6. The computer will reboot.

To keep your second monitor working do not update the display drivers, keep the drivers that Windows installs during the reboot.