Fix apache2 after upgrading to ubuntu 16

After upgrading to ubuntu 16, my wordpress was acting weird. I get errors like apache2.service – LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: failed (Result: exit-code), and Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Here are some of the steps I took to re-enabled my blog.
If you are using php 7.0, then do

sudo a2dismod php5
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0
sudo apt-get install php7.0-mysql
sudo a2enmod php7.0
sudo systemctl restart apache2

Then then your blog should get back up, but for me all of my blog post content are missing. I still can see the post content in the editor, but not on the webpage. It turns out some of the plugins were not up-to-date yet. So turn on/off and update your plugins and at the end your posts should get back to normal.


Learned Optimism

Reginald Braithwaite talked about a book called “Learned Optimism,” by Dr. Martin Seligman. Sounds interesting.

When we explain something that happened to us, it’s usually in terms of
– Personal vs. Impersonal
– Specific vs. General
– Temporary vs. Permanent

Pessimists tend to explain bad things as being personal, general, and permanent, while explain away the good things as being impersonal, specific, and temporary.

I am always bad at doing just about everything.
That project for team A is just a one-time win.

Optimists tend to explain in the opposite ways: explain good things as being personal, general, and permanent, while explain away the bad things as being impersonal, specific, and temporary.

I am always good at solving puzzles.
That bug for project A will be fixed in a day or two.

Reginald concluded: Changing your explanations through repetition and consistency, changes your life: You become happier and more productive.

Reattach to a terminal process when x11 is restarted

Let me describe my case. I was running 4 long commands in 4 terminals. They were all splitting out log files to stdout so I could see the progress. Then all of a sudden I found my X11 frozen. I thought it would just go away when my tasks became less busy. But after like an hour I decided that I needed to do something since my screen was still frozen. I grabbed my laptop and ssh’ed to my box and found the 4 tasks still running, so the system is ok. Then I had no choice but to restart my display session. I did:

sudo restart lightdm

Depending on your display manager, you may run slightly different commands. Then I saw my login window came back. I logged back in, and it was a clean empty desktop. I did a top and saw that my 4 tasks were still running. So now, it would be nice to see the stdout lines they spit out.

I found many articles talking about gdb. I tried once but was too scared to move forward. Then I found this tool called strace, which really does the thing I wanted. The command is:

sudo strace -ewrite -p 12345 -s 1024

The -p flag is to specify your task’s PID. The -s flag is to specify the length of your line, default is 32 characters but it is not quite readable.

When you run that, the output from your task comes out which is good. However the output line is a bit strange. It would look something like the following.

write(1, "The output of your original line\n", NNN) = NNN

The NNN is the length of your line I guess. But if you really want to take away the extra prefix and suffix, here is the command you want:

sudo strace -ewrite -p 12345 -s 1024 2>&1 | sed -r 's/write\(1, \"(.*)\\n\"(.*)/\1/'

strace prints things out to stderr, so the 2>&1 is to redirect the output back to stdout for us to pipe. The sed is just using regex match to parse out the middle part.