Upgrading to PostgreSQL 10 on Centos 7

Here’s a quick rundown on upgrading a very simply configured PostgreSQL 9.x server to PostgreSQL 10 running on Centos 7.

First, and this goes without saying, backup your server!

In these examples, I’m using upgrading from PostgreSQL 9.5. If you’re upgrading from a different version, just replace 9.5 and 95 wherever you see it with your appropriate version number.

Install the repo RPM for PosgresSQL 10

sudo yum install yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-1.noarch.rpm

Install PosgreSQL 10

sudo yum install postgresql10-server

Stop Postgresql 9.5 and Postgresql 10

sudo systemctl stop postgresql-9.5.service && sudo systemctl stop postgresql-10.service

Initialize the PostgreSQL 10 database

sudo su postgres
cd ~/
/usr/pgsql-10/bin/initdb -D /var/lib/pgsql/10/data/

Migrate your database from the 9.x version to 10

/usr/pgsql-10/bin/pg_upgrade --old-datadir /var/lib/pgsql/9.5/data/ --new-datadir /var/lib/pgsql/10/data/ --old-bindir /usr/pgsql-9.5/bin/ --new-bindir /usr/pgsql-10/bin/

Make any necessary changes to postgresql.conf . I’d recommend making the changes the new version rather than copying over postgresql.conf from 9.5, since there are a bunch of new options in the PostreSQL 10 version of the file.

You can view your 9.5 configuration with:

nano /var/lib/pgsql/9.5/data/postgresql.conf

You can make your changes to the 10 configuration with:

nano /var/lib/pgsql/10/data/postgresql.conf

If you need to connect from other servers, make sure to change:

#listen_addresses = 'localhost'

to (apostrophes may not survive copy/paste, may want to hand enter)

listen_addresses = '*'

(or whatever is appropriate for you)

Now do the same with pg_hba.conf

View the old configuration

nano /var/lib/pgsql/9.5/data/pg_hba.conf

Edit the new configuration

nano /var/lib/pgsql/10/data/pg_hba.conf

Start the server

systemctl start postgresql-10.service

Analyze and optimize the new cluster

./analyze_new_cluster.sh

If everything is working, set the PostgreSQL 10 service to start automtically

systemctl enable postgresql-10

If you wish to remove PostgreSQL 9.x and its data

./delete_old_cluster.sh
exit
sudo yum remove postgresql95-server
sudo yum remove pgdg-centos95

That should do it!

Fixing 404 Errors on WordPress with Let’s Encrypt

Since my SSL cert was nearing expiration, I thought it would be a good idea to give Let’s Encrypt (free SSL certs!) a try.

Let’s Encrypt has a helper app called certbot that will configure Apache for you automatically. The really nice thing about certbot is that it will also (via crontab) renew your cert and configure Apache to use the new cert. This is useful, since Let’s Encrypt certs expire every 90 days.

To use certbot effectively, you need an Apache configuration that’s setup the way your distro expects. Mine was not (I hand ported the configs from Ubuntu), so I figured it was a good time to reinstall Apache with the default configs, then run certbot (official instructions here: https://certbot.eff.org/ ).

This initially seemed to work great, but I quickly noticed all of my subpages returned 404 errors. WordPress works best when you allow it to configure a .htaccess file to do URL rewrites. Allowing URL rewrites via .htaccess requires some additional configuration in your ssl.conf file.

sudo nano /etc/httpd/conf.d/ssl.conf

Add the following just before </VirtualHost> at the very end of your config.

<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Thanks to Mike McMurray who posted the instructions at: https://mike.mcmurray.co.nz/2017/01/08/wordpress-permalink-404-with-https/

 

Fix: Office Updates and Malwarebytes

If any of you are big fans of Malwarebytes (and why wouldn’t you be?) you may be experiencing crashes in Office 2013 and 2016 under Windows 10.

Microsoft has identified the problem: https://support.office.com/en-us/article/Fixes-or-workarounds-for-recent-issues-in-Word-for-Windows-bf6bf17c-2807-4871-83ce-e337ae8f0b86?ui=en-US&rs=en-US&ad=US

The workaround is to use the latest beta of Malware Bytes: https://forums.malwarebytes.com/topic/200230-malwarebytes-version-310-beta-available-for-download/

Hope this helps!

Enabling HDR for XBox One with Samsung 4K TV

(Skip to the bottom for the instructions after my tale of woe)

Yesterday I setup a new 4K Samsung UN65KU650D TV with HDR.

Of course the 1st thing I did was to hook it up to XBox One to see it in all its 4K HDR glory! Once I selected the correct HDMI input, XBox One automatically recommended switching to 4K (very cool!). I also wanted to make sure it was also displaying in HDR.

I went to Settings > All settings > Display & sound, then chose Advanced video settings > 4K TV details as described here (https://support.xbox.com/en-US/xbox-one/console/checking-your-tv-4k-hdr-capabilities-on-xbox-one-s).

While 4K HDR was detected, HDR could could be found at any refresh rate and was therefore disabled for Video and Games. (Lots of yellows and reds, not nearly enough green checkboxes)

As you can imagine, my heart sank! But fear not, this is just some silliness on Samsung’s part, I imagine for compatibility with devices that don’t support HDR.

By default, this Samsung TV has HDR disabled for all inputs. To enable it for your XBox One (or other HDR device):

1) Turn on the TV and turn off whatever device will be using HDR.

2) Hit the Home button on your remote to bring up the menu
4khdr13) Choose the Settings icon (looks like a gear or cog)4) Choose Picture
4khdr35) Choose Expert Settings
4khdr46) Choose HDMI UHD Color
4khdr57) Choose the HDMI input you are using for your XBox One or other HDR capable device and select “On”.
Click “Close”
4khdr6 8) Turn your XBox One (or whatever) back on.
Go to Settings > All settings > Display & sound, then choose Advanced video settings > 4K TV details
It should now look like:
4khdr7
9) (Optional but highly recommended) Play Mass Effect: Andromeda in all its HDR glory!

Create 1 Frame Animations in Unity 3D

I was looking to make a 1 frame animation in Unity and wasn’t able to find a guide. In case anyone is curious, this is what I did:

When making a multi-frame animation, you can simply select all of the frames in a sprite and drag them to the prefab. This creates the animation for you. However, if you drag just one frame from the sprite, it will add it as a sprite renderer.

If you would like  a 1 frame animation from that sprite, right click the frame you want in the Unity Editor and click Create->Animation

Ta da! You’ve now got a 1 frame animation.

Installing Network Policy Server from PowerShell

Recently I encountered a strange error where I couldn’t install Network Policy Server from the Server Manager.

Rather than fight with Server Manager, I punted and installed it via PowerShell. The installation that way worked without an problem.

Run PowerShell as Administrator

Run:

Import-Module Servermanager

Run:

install-windowsfeature -name npas-policy-server -IncludeManagementTools

That’s it!

Fix: Unable to Auto-Update WordPress 7.1-7.2

When attempting to upgrade WordPress 7.1 to 7.2 I received the following error:

The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.: wp-admin/includes/update-core.php

A little Binging around and I found the solution here:
https://aaronjholbrook.com/wordpress-permissions-update-error-resolved/

Just in case that site goes down, here’s what to do:

SSH into your web server and run the following 3 commands:

Reset the permissions of all files to 664:

find /path/to/site/ -type f -exec chmod 664 {} \;

Reset permissions of directories to 775:

find /path/to/site/ -type d -exec chmod 775 {} \;

Reset the group to the apache group

chgrp -R apache /path/to/site/

Fix: Windows Media Center Can’t Update

If you’re still using Window Media Center to power your OTA cable cutting hotness: go you! We are a dwindling number :p

I recently had a problem where I kept being alerted that the guide data only had 3 days left. Allowing it to download the data did not seem to fix it.

(As a side note: it was also showing the wrong program icons for TV shows.)

The fix it turns out is very simple (so you can hold off buying that Tivo Roamio OTA for now):

Start->Run
C:\ProgramData\Microsoft\eHome\mcepg2-0

Delete all of the files in that folder. There will likely be 3 files and folder:
Root.mem
Events.mem
Blocks.mem
backup

You will probably be told that you can’t delete one or more of the files because they are in use by some process.
Don’t cancel, leave that message up and continue following these instructions.

Press: Control-Alt-Delete
Choose Task Manager
Click the “Processes” tab
At the bottom, click the “Show processes from all users” button.
Click the column header that says “Image Name” to sort by name (and make your life easier).
Find the process that in the error message when you delete.
Click the process, then click the “End Process” button in the lower-right corner.

In the error message window that said you couldn’t delete, click “Try Again.”
Repeat this process until all of the files are deleted.

Launch Windows Media Center
Go to Guide
You should now see a full schedule of programs.

Restart your Windows Media Center computer to make sure all of the processes you ended are started back up correctly.

Where’d the Timer Go?

So. System.Threading.Timer. Right.

I’m really starting to miss the old System.Timers.Timer. Built like a tank. System.Threading.Timer is a bit more finicky, but is the only option in .Net Core.

My fun of the day:

It turns out, when the timer goes out of scope, it will be disposed of. Even if you’d told it to, for example, tick every 3 seconds. Though I probably should have known that.

This will tick exactly once:

private void foo()
{
Timer t = new Timer(bar, null, 0, 3000);
}

Instead, you must do:

Timer t = null;
private void foo()
{
t = new Timer(bar, null, 0, 3000);
}

Just so you don’t waste a couple of frustrating hours like I did.

Happy coding!

Getting to the (.Net) Core of It

Migrating a .Net 4.x Console Application to .Net Core

I finally got the server side of Winds of Paradise running in .Net Core! I thought I’d share how it did in, in hopes that it might help you do the same. As cool as Mono is, I’m totally psyched to have all my C# code running on Microsoft’s .Net under Centos Linux!

If you haven’t watched it yet, I highly recommend Microsoft’s .Net Core lesson at the Microsoft Virtual Academy:
https://mva.microsoft.com/en-US/training-courses/introduction-to-net-core-16764?l=DoVafl7yC_7606218965

1st thing I did was update Visual Studio 2015 Community to Update 3 and install all of the prerequisites. These can be found at: http://getdotnet.azurewebsites.net/target-dotnet-platforms.html

You can also find instructions there on how to install .Net Core onto wherever your code will be hosted.

Once everything is installed (block out a good hour for this), I opened my existing solution in Visual Studio.

To the solution, I then added another project and chose the type: Console Application (.Net Core)

dot-net-core-console

Next, open that project and use the NuGet Manager to install any packages that you are using in your .Net 4.x project. For me, this was npgsql and Newtonsoft.JSON.

Once the new project is created, copy over all of your .cs files from your original project to the new .Net Core version.

Hit build, and start working on replacing any .Net 4.x functionality that is not available in .Net Core.

What I did was make corrections in the .Net Core version and then replicate those changes in the .Net 4.5 version. This way, I could build and run the old version with minor changes to prove the changes worked, rather than changing *everything* and trying to debug the .Net Core version. This worked, since the .Net 4.x encompasses everything .Net Core does.

Once you’ve worked out all of the bugs, copy all of your code over to whatever box your running on .Net Core on (Windows, Linux, MacOS, etc.).
Open a shell, cd in the folder with project.json and run:

dotnet restore
dotnet run

That’s it! .Net will download necessary packages from nuget, compile, and run.

Here’s some of the classes I had to find workarounds for:

System.Net.HttpWebRequest, System.IO.Stream.GetReqestStream:
The .Net Core version of this object only has async methods for GetRequestStream and GetResponse. You’ll have to move to GetRequestStreamAsync and GetResponseAsync, which also means having your methods return Task instead of void
Also, the .Net Core version does not have HttpWebRequest.ContentLength when doing a POST. So far, simply removing it seems to work fine in both  .Net 4.5 and .Net Core.

NpgsqlDataAdapter:
I’m guessing this could probably be made to work with .Net Core fairly easily, but moving NpgsqlDataAdpater usage to NpgsqlDataReader for better database efficiency has been on my TODO list for quite a while anyway.

System.Configuration:
I found a great resource for setting up json configuration files at:
https://csharp.christiannagel.com/2016/08/02/netcoreconfiguration/
A couple notes:
1) I had previously been targeting .Net 4.5. I needed to target 4.5.1 in order to install Microsoft.Extensions.Configuration
2) If you create appsetttings.json in your .Net 4.5 project 1st, make sure to create appsettings.json in your new .Net Core project, DON’T COPY it from from the .Net 4.5.1 one. Creating it new sets it as a “Content File”

System.Timers.Timer:
This was a tricky one. System.Timers.Timer allows easily add/subtracting events from occurring on the timer with Elapsed += [function].  This allowed me to have a couple of static timers that any other object could add events to.
The only alternative in .Net Core is the System.Threading.Timer. This timer is much less sophisticated. It can only accept one function to run at each tick, and this function cannot be changed. My workaround was to implement a separate timer for each object that needed one. I’m hoping this does not increase resource consumption. Hopefully a better timer alternative will work its way int nuget, I didn’t see anything that looked promising at the moment.

Happy coding!