Bash scripts

Change upper case to lower case

#echo ‘TEST’|/usr/bin/tr -s ‘[:upper:]’ ‘[:lower:]’
test

Work with array

IFS=$’\n’ ##here tells how to devide the output, default is space
##but I want to put each line into a array
files=($(ls ./) ##put file names into an array using ()
for (( i=0;i<${#files[@]};i++ ));do mv $files[$i] $files[$i]_OLD done

Match pattern

if [[ $string =~ “data” ]];do
echo “$string contains data”
done

Enable status in PHP-fpm + Nginx

It was a little bit confusing to set it up. So here’s the memo.

vi /etc/php5/fpm/pool.d/www.conf

pm.status_path = /status
listen = 127.0.0.1:9000

vi /etc/nginx/sites-available/monitor
location ~ ^/(status|ping)$ {
include fastcgi_params;
#access_log off;
allow 127.0.0.1;
allow xx.xx.xx.xx;
deny all;
fastcgi_param SCRIPT_FILENAME /status;
fastcgi_pass 127.0.0.1:9000;
}

Restart nginx and php-fpm processes.

Ref: Here

The wind rises — Movie

As a big fan of Miyazaki Hayao animation movies, of cause I am not going to miss this newest one and seems to be the last production before his retirement.

Not every movie theater was showing it, so we had to drive to El Segundo and watched it in the Arclight theater.

The story is based on a real person’s biography, who designed the fighter air plane for Japanese army during WWII, mainly used for fighting with China and US. So it’s very different from other animation movies he made, which were telling fantasy stories.

The WWII background and the tragedy ending of the love story brought the movie a quite very sad and heavy feeling. The air plane technology and the engineer were brilliant but it was used for a war that killed millions of people.

I am not sure if the engineer himself really had this confliction in his mind or not but the producer seems want to show this feeling in his movie.

Resize root partition of a virtual machine on VMware

When it comes to a situation that the disk space is not enough on a virtual machine, it’s easy to extend the disk space if it’s on LVM, even the /root partition.

This post is very helpful.

For my own memo:
Case:
VM on VMware, installed with CentOS 6.x
#fdisk -l shows
Disk /dev/sda: 12GB ….
/dev/sda1 2 501 512000 83 Linux
/dev/sda2 502 12288 12069888 8e Linux LVM

On /dev/sda2
Disk /dev/mapper/vg_node1-lv_root: 7.5 GB
Disk /dev/mapper/vg_node1-lv_swap: 4 GB

Goal: Add 8G extra space to /dev/mapper/vg_node1-lv_root

Steps:
1. Using VMware GUI to add 8G to the virtual machine. Make sure it recognizes the new size.

2. Memo the current cylinder start number of /dev/sda2
/dev/sda2 502 12288 12069888 8e Linux LVM

3. Delete partition /dev/sda2 then recreate it with the new size
fdisk /dev/sda
Use command “d”, then “2” to delete /dev/sda2
Use “n” to create a new partition, partition number is “2”
Use “t” to change partition type to 8e as “Linux LVM”
Then “w” to save the change

Reboot the VM

Now the partition size is changed. I need to change the pv size and vg size.

5. Change pv size
pvsize /dev/sda2

6. Change vg size
#vgdisplay (found the free PE = 2048 )
#lvextend /dev/mapper/vg_node1-lv_root –extents +2048

7. Still need to increase file system size
#resize2fs /dev/mapper/vg_node1-lv_root

————————————————————————-
Another way to do it

1. Add disk space from vmware GUI, however the following command didn’t work, so reboot
echo “- – -” > /sys/class/scsi_host/host0/scan

2. frisk -l shows new disk space on /dev/sda
create a new partition on /dev/sda
frisk /dev/sda -> n -> p -> 3 -> it will show the right start/end block number automatically, so just hit enter,
-> t -> 8e -> w

3. fdisk shows /dev/sda3, the new partition created.
However it warns the kernel won’t use the new table until reboot, so reboot for the 2nd time

4. Create a new physical volume on lvm using sda3
pvcreate /dev/sda3

5. find vg name from vgdisplay, find vg name is using “centos”, add sda3 to virtual group
vgextend centos /dev/sda3

6. pvscan shows sda3 as a member of vg “centos”
[root@mononoke ~]# pvscan
PV /dev/sda2 VG centos lvm2 [15.51 GiB / 0 free]
PV /dev/sda3 VG centos lvm2 [9.00 GiB / 0 free]
Total: 2 [24.50 GiB] / in use: 2 [24.50 GiB] / in no VG: 0 [0 ]

7. lvdisplay shows 2 logical volumes, /dev/centos/root and /dev/centos/swap,
lvextend /dev/centos/root /dev/sda3

8. resize file system, since it’s using XFS on centos7,
xfs_growfs /dev/centos/root

Here‘s the reference

——————————————————-
To check how much free space left in a physical volume, do pvdisplay, then find value of “Free PE”

— Physical volume —
PV Name /dev/sdb2
VG Name test_vg
PV Size 20.00 GiB / not usable 1.31 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 5120
Free PE 2620
Allocated PE 2500

Catching the tail of summer in Mammoth -3

[singlepic id=355 w=640 h=480 float=left]
A River flowing slowly between the golden meadow with low clouds sitting on the mountains in the background.Some black cows were eating or resting on the meadow.
I found this is one of the most beautiful place in mammoth, the Owens river.

 
 
 
[singlepic id=374 w=640 h=480 float=left]

Look at how huge the cloud is! It’s hard to see this kind of cloud in LA. It might be able to hide a sky castle in it like the one in Miyazaki’s animation movie?