How to delete stucked Route53 zone created by ECS service discovery

It happens when I tried to delete the NS that created by ECS service directory, then this error shows up:

The resource hostedzone/Z1OWcan only be managed through servicediscovery.amazonaws.com (arn:aws:servicediscovery:us-east-1:561660628307:namespace/ns-c6lvlchj2gbcsobc)

If there are services hanging around the in the NS you can’t delete then you could try:

$ aws servicediscovery list-services
$ aws servicediscovery delete-service --id=
$ aws servicediscovery delete-namespace --id=

pip error after upgrade: ImportError: cannot import name ‘main’

Sometimes pip can be really sucks, after upgrade the pip version, then you call it afterwards, it will fail somehow.

$ pip install --user --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
ImportError: cannot import name 'main'
$ pip
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in 
    from pip import main
ImportError: cannot import name 'main'

The problem is easily can be resolved by doing this:

$ hash -d pip

NerdTree command cheatsheet

Install NerdTree : http://chrisstrelioff.ws/sandbox/2014/05/29/install_and_setup_vim_on_ubuntu_14_04.html

ctrl+ww move cursor back to list directory
gt next tab
gT previous tab

Enable html syntax:

au BufReadPost *.ezt set syntax=html

Nerdtree setup alike:

let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 25
augroup ProjectDrawer
  autocmd!
  autocmd VimEnter * :Vexplore
augroup END

Open vertical term :vert term
Resize vertical term :vert resize +5

Alembic set autogenerate model

Alembic create revision autogenerate with comment:

$ alembic -c dev.ini revision --autogenerate -m "adding some tables"

Check upgrade script:

$ cat alembic/versions/123xxx_xxx.py

Alembic upgrade metadata with version

$ alembic -c dev.ini upgrade 123xxx

Alembic upgrade metadata with latest version

$ alembic -c dev.ini upgrade head

 

Setup Systemd Service on Ubuntu 16.04

$ sudo vim /etc/systemd/system/myservice.service
[Unit]
Description=Run the service

[Service]
User=ubuntu
# change the workspace
WorkingDirectory=/usr/local/src

#path to executable. 
#executable is a bash script which calls jar file
ExecStart=/usr/local/src/somescript

SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
$ sudo vim /usr/local/src/somescript
#!/bin/sh

java -jar /some/file.jar
sudo systemctl daemon-reload
sudo systemctl enable myservice.service
sudo systemctl start myservice
sudo systemctl status myservice

 

Install MySQL on Ubuntu And Skip the Password Prompt

When you install mysql on Ubuntu (I use 16.04), it requires you to fill the admin password for the first time before finishing the installation. This prompt will wait the user input until you fill the password.

This trick is very helpful if you want to install mysql in Dockerfile, and skipping the password prompt:

$ export DEBIAN_FRONTEND=noninteractive
$ sudo -E apt-get -q -y install mysql-server

Setup Simple Ruby on Rails App On Ubuntu 16.04 From Scratch

Rails is one of the most popular ruby framework out there. And now, I want to try to run the simple app on Ubuntu 16.04 machine. it’s for testing purpose.

First, update the system and install essential dependencies:

$ sudo apt-get update
$ sudo apt-get build-essential curl sudo vim

Install nodejs:

$ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
$ apt-get install nodejs

Create a dedicated user for the app, for example, ubuntu user. And this also make the ubuntu user with sudo privilege and run the command without password. Which is useful to run command that needs sudo privilege in the next steps.

$ useradd ubuntu -m
$ echo 'ubuntu ALL=(root) NOPASSWD: ALL' >> /etc/sudoers

swith to ubuntu user and install GPG keys for install rvm:

$ su - ubuntu
ubuntu~$ gpg --keyserver hkp://keys.gnupg.net \ --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \ 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Download and install rvm:

ubuntu~$ \curl -sSL https://get.rvm.io | bash -s stable

Install ruby interpreter with version 2.5.1, you might wanna change it with your preferable version:

ubuntu~$ source ~/.rvm/scripts/rvm
ubuntu~$ rvm install 2.5.1
ubuntu~$ rvm use 2.5.1 --default

Install rails with gem, and create new app without writing the Gemfile. Why? because everytime I create new app, I ended up facing errors with dependencies in Gemfile. So, it safe to setup new app without the Gemfile, we’ll create it manually later.

ubuntu~$ gem install rails
ubuntu~$ rails new app --skip-gemfile

Create the Gemfile:

ubuntu~$ touch ~/app/Gemfile
ubuntu~$ vim ~/app/Gemfile

Gemfile, fill these dependencies below into the file, save and exit:

source 'https://rubygems.org'
gem 'rails', '~> 5.2.1'
gem 'bootsnap', '~> 1.3.2'
gem 'tzinfo-data', '~> 1.2018.5'
gem 'listen', '~> 3.1.5'
gem 'sqlite3'

Now, install all the gems with bundle:

ubuntu~$ cd ~/app
ubuntu app~$ bundle install

Try run the rails:

ubuntu app~$ rails server -b 0.0.0.0

 

Linux machine Failed to hibernate, “system via logind: Sleep verb not supported”

So after using fedora 28 for a while. I tried to configure my power management using xfce power management system.

Looking at these power management settings, are very simple explanation. I set my machine to hibernate or sleep mode when inactive for 16 minutes.

Saved the settings. then I closed the laptop lid, so it started to be inactive until the next 16 minutes. Supposed to be hibernated.

But it did not, instead…

I opened up my laptop, and there is this error:

System via logind: Sleep verb not supported...

It turns out that the states of the machine are not available for hibernate. You can check them out with this simple command:

$ sudo cat /sys/power/disk
[disabled]

Now, that’s a problem. The machine cannot be hibernate, nor suspend if the output is disabled.

The solution is quite simple. Reboot the machine, then enter BIOS mode. This one is requires the BIOS setting, secure boot to be disabled.

Secure boot setting in BIOS

Switch the secure boot in BIOS setting to Disabled. Then reboot the system.

After I rebooted the system with secure boot disabled, the output of /sys/power/disk now is contains more than one, including suspend/hibernate.

$ cat /sys/power/disk 
[platform] shutdown reboot suspend test_resume

The machine’s power management system now can run the machine with hibernate mode.