2/28/18

HTTP endpoint to shut down a spring boot

Maven quick example for maven user to configure HTTP endpoint to shut down a spring boot web app using spring-boot-starter-actuator so that you can copy and paste:
1. Maven pom.xml:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2. application.properties:
#NEED auth  protected 
endpoints.shutdown.sensitive=true

#Enable shutdown endpoint
endpoints.shutdown.enabled=true
All endpoints are listed here:
3.Send a post method to shutdown the app:
curl -X POST localhost:port/shutdown

Security Note:

if you need the shutdown method auth protected, you may also need
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
</dependency>

management.security.enabled=true
security.user.name=admin
security.user.password=secret
management.security.roles=SUPERUSER

[Evolution] Error resolving 'outlook.office365.com': Name or service not known

Check below config to fix this bug:

$ cat /etc/resolv.conf
nameserver 127.0.1.1
multi on
order hosts,bind


$ cat /etc/nsswitch.conf
passwd:         compat
group:          compat
shadow:         compat
gshadow:        files

hosts:          files dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

2/26/18

HP EliteBook 840 G4

System:    Host: dqvnHP Kernel: 4.13.0-32-generic x86_64 (64 bit gcc: 5.4.0)
           Desktop: Cinnamon 3.6.7 (Gtk 3.18.9-1ubuntu3.3) dm: lightdm Distro: Linux Mint 18.3 Sylvia
Machine:   System: HP (portable) product: HP EliteBook 840 G4 Chassis: type: 10
           Mobo: HP model: 828C v: KBC Version 45.3C Bios: HP v: P78 Ver. 01.08 date: 10/17/2017
CPU:       Dual core Intel Core i7-7500U (-HT-MCP-) cache: 4096 KB
           flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx) bmips: 11616
           clock speeds: min/max: 400/3500 MHz 1: 2900 MHz 2: 2900 MHz 3: 2900 MHz 4: 2900 MHz
Graphics:  Card: Intel Device 5916 bus-ID: 00:02.0 chip-ID: 8086:5916
           Display Server: X.Org 1.18.4 drivers: intel (unloaded: fbdev,vesa)
           Resolution: 1920x1080@60.01hz, 1920x1080@60.00hz
           GLX Renderer: Mesa DRI Intel HD Graphics 620 (Kaby Lake GT2)
           GLX Version: 3.0 Mesa 17.2.8 Direct Rendering: Yes
Audio:     Card Intel Device 9d71 driver: snd_hda_intel bus-ID: 00:1f.3 chip-ID: 8086:9d71
           Sound: Advanced Linux Sound Architecture v: k4.13.0-32-generic
Network:   Card-1: Intel Ethernet Connection (4) I219-V
           driver: e1000e v: 3.2.6-k bus-ID: 00:1f.6 chip-ID: 8086:15d8
           IF: enp0s31f6 state: up speed: 1000 Mbps duplex: full mac: 
           Card-2: Intel Device 24fd driver: iwlwifi bus-ID: 02:00.0 chip-ID: 8086:24fd
           IF: wlp2s0 state: up speed: N/A duplex: N/A mac: 
Drives:    HDD Total Size: NA (-) ID-1: /dev/nvme0n1 model: N/A size: 256.1GB serial: N/A
Partition: ID-1: / size: 92G used: 35G (40%) fs: ext4 dev: /dev/nvme0n1p2
           ID-2: swap-1 size: 16.00GB used: 0.00GB (0%) fs: swap dev: /dev/dm-0
RAID:      System: supported: N/A
           No RAID devices: /proc/mdstat, md_mod kernel module present
           Unused Devices: none
Sensors:   System Temperatures: cpu: 39.0C mobo: 0.0C
           Fan Speeds (in rpm): cpu: N/A
Repos:     Active apt sources in file: /etc/apt/sources.list.d/chrome.list
           deb [arch=amd64] http: //dl.google.com/linux/chrome/deb/ stable main
           Active apt sources in file: /etc/apt/sources.list.d/official-package-repositories.list
           deb http: //packages.linuxmint.com sylvia main upstream import backport
           deb http: //archive.ubuntu.com/ubuntu xenial main restricted universe multiverse
           deb http: //archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse
           deb http: //archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse
           deb http: //security.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
           deb http: //archive.canonical.com/ubuntu/ xenial partner
           Active apt sources in file: /etc/apt/sources.list.d/peterlevi-ppa-xenial.list
           deb http: //ppa.launchpad.net/peterlevi/ppa/ubuntu xenial main
           deb-src http: //ppa.launchpad.net/peterlevi/ppa/ubuntu xenial main
           Active apt sources in file: /etc/apt/sources.list.d/skype-stable.list
           deb [arch=amd64] https: //repo.skype.com/deb stable main
           Active apt sources in file: /etc/apt/sources.list.d/stebbins-handbrake-git-snapshots-xenial.list
           deb http: //ppa.launchpad.net/stebbins/handbrake-git-snapshots/ubuntu xenial main
           deb-src http: //ppa.launchpad.net/stebbins/handbrake-git-snapshots/ubuntu xenial main
           Active apt sources in file: /etc/apt/sources.list.d/webupd8team-java-xenial.list
           deb http: //ppa.launchpad.net/webupd8team/java/ubuntu xenial main
           deb-src http: //ppa.launchpad.net/webupd8team/java/ubuntu xenial main
Info:      Processes: 261 Uptime: 4 days Memory: 7697.3/15920.6MB
           Init: systemd v: 229 runlevel: 5 default: 2 Gcc sys: 5.4.0
           Client: Unknown python2.7 client inxi: 2.2.35

12/6/17

How to Create Wi-Fi Hotspot in Ubuntu 17.04 (Support Android)

How to Create Wi-Fi Hotspot in Ubuntu 17.04 (Support Android)

This quick tutorial is going to show you how to create a WiFi hotspot in Ubuntu 17.04 laptop with support for Android devices.
First of all you need to connect to your Ubuntu laptop to a wired network, disable Wifi, and then do following steps:
1. Go to top-right corner network applet, select Edit Connections from drop-down menu.
In pop-up window, click the Add button.
edit-network-connection
2. Then choose Wi-Fi in the next ‘choose a connection type dialog’.
choose-wifi
3. Now in the new created WiFi hotspot, do:
  • In Wi-Fi tab, type in Connection name, SSID, and choose mode HotSpot.
  • In Wi-Fi security tab, choose an encrypted type and set a password.
  • In IPv4 Settings tab, select mode “Share to other computers”
  • wifi-hotspot
4. After saved the changes, enable Wi-Fi in the network menu, and it should automatically connected to this hotspot.
If not, select ‘Connect to Hidden Wi-Fi Network’ from network menu, and choose the new created hotspot from drop-down menu:
hidden-network
5. Finally your network menu will look like:
connect-to-hotspot
On you mobile phone or other devices, select connect to this Wi-Fi hotspot and enjoy!

11/3/17

CORS with spring-boot and angularjs not working

Add this class near to the place you create Application.java

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class SimpleCORSFilter implements Filter {

private final Logger log = LoggerFactory.getLogger(SimpleCORSFilter.class);

public SimpleCORSFilter() {
log.info("SimpleCORSFilter init");
}

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;

response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me");

chain.doFilter(req, res);
}

@Override
public void init(FilterConfig filterConfig) {
}

@Override
public void destroy() {
}

}

10/31/17

Find the Git Commit User — Jenkins Pipeline


I recently started to use Jenkins 2 Pipeline scripts to setup Continuous Delivery Process. I wanted to get the email of the Git user who has done the commit for that particular build. Initially idea was to use following global variables set by the Jenkins Git Plugin.
  • GIT_AUTHOR_NAME and GIT_COMMITTER_NAME
  • GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL
Somehow, things didn’t work as per the plugin documentation. So, I decided to use Git client with shell or batch scripts. Following is how it is done in both Linux and Windows environments.
In Windows — as usual some tricks required 
def commiterDetails = bat (
script: 'git --no-pager show -s --format=%%ae',
returnStdout: true
)
def commiter = extractCommiterEmail(commiterDetails)
def extractCommiterEmail(details) {
def arr = details.tokenize('\n')
def email = arr[2].trim()
return email
}

In Linux
committerEmail = sh (
script: 'git --no-pager show -s --format=\'%ae\'',
returnStdout: true
).trim()

9/26/17

Fix bug Intel Graphics Update tool for Linux* OS (the public key is not available: NO_PUBKEY 611B903CAB97EA77)

Fix bug "the public key is not available: NO_PUBKEY 611B903CAB97EA77"

$ sudo apt update
...                       
Err:7 https://download.01.org/gfx/ubuntu/17.04/main zesty InRelease   
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 611B903CAB97EA77
...                             
Reading package lists... Done                                                                                                                 
W: GPG error: https://download.01.org/gfx/ubuntu/17.04/main zesty InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 611B903CAB97EA77
E: The repository 'https://download.01.org/gfx/ubuntu/17.04/main zesty InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.



Solution:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 611B903CAB97EA77
sudo apt-get update