setlock
setlock - runs another program with a file locked.
setlock [-nNxX] fn child,简单说 setlock 会打开 fn 并加锁,然后执行 child。如果 lock 失败,可以指定 child 退出或等待:
-n: fn 被其他进程锁住,setlock 放弃执行 child
-N: fn 被其他进程锁住,setlock 会等待,直到重新加锁,并执行 child
-x: fn 打开失败或已加锁,setlock exit 0
-X: fn 打开失败或已加锁,setlock 输出错误并退出
setlock 可以和 crontab 搭配使用,比如某个任务每十分钟执行一次,如果上一次执行尚未退出,不再开启新任务:
*/10 * * * * /usr/bin/setlock -n /tmp/test.lock /home/x.sh
Stop
Stop, 是一个行程的中止。
Stop, 也是一个站点,下车,上车,继续前进。
2010.6 - 2018.5.
Nginx + Websocket
upstream ws {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 8090;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://ws;
}
}
在 Nginx reload 的时候,socket 连接并不会中断。
Linux Performance Analysis in 60s
uptime/w --------------------> load average
dmesg | tail ----------------> kernel errors
vmstat 1 --------------------> overall stats every second
mpstat -P ALL 1 -------------> CPU balance
pidstat 1 -------------------> process usage, every second
iostat -xz 1 ----------------> disk I/O
free -m ---------------------> memory usage
sar -n DEV 1 ----------------> network I/O
sar -n TCP,ETCP 1 -----------> TCP stats
top -------------------------> check overview
dmidecode
You can use dmidecode to display server physical info, for example RAM max capacity.
dmidecode -t 16
Handle 0x0032, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 48 GB
Error Information Handle: Not Provided
Number Of Devices: 6
App Store Front Code
X-Apple-Store-Front header is needed to scrape in App Store.
// 29 or 26 or 9
CN 143465-19,29
US 143441-1,29
JP 143462-9,29
KR 143466-13,29
HK 143463-18,29
AU 143460,29
TW 143470-18,29
CA 143455-6,29
DK 143458-2,29
RU 143469-16,29
ID 143476-2,29
TR 143480-2,29
GR 143448-2,29
DE 143443-4,29
IT 143450-7,29
NO 143457-2,29
FR 143442-3,29
TH 143475-2,29
SE 143456-17,29
FI 143447-2,29
GB 143444,29
NL 143452-10,29
BR 143503-15,29
PT 143453-24,29
MX 143468-28,29
ES 143454-8,29
VN 143471-2,29
App info:
curl -H 'x-apple-store-front: 143465-19,29' 'https://itunes.apple.com/cn/app/id1318151064?mt=8'
Top Free iPhone Apps:
curl -H 'x-apple-store-front: 143465-0,9' 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/topChartFragmentData?popId=27&pageNumbers=0&pageSize=1000'
curl -H 'x-apple-store-front: 143465-19,29' 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?id=25204&popId=27&genreId=36'
Rating & reviews:
curl -H 'x-apple-store-front: 143441-0,9' 'https://itunes.apple.com/us/customer-reviews/id284882215?dataOnly=true&displayable-kind=11'
curl -H 'x-apple-store-front: 143441-1,29' 'https://itunes.apple.com/us/customer-reviews/id284882215?dataOnly=true&displayable-kind=11'
curl -H 'x-apple-store-front: 143441-1,29' 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/userReviewsRow?id=284882215&displayable-kind=11&startIndex=0&endIndex=100&sort=1'
Search:
curl -H 'x-apple-store-front: 143441-1,29' 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/search?clientApplication=Software&term=NBA'
curl -H 'x-apple-store-front: 143441-1,29' 'https://search.itunes.apple.com/WebObjects/MZSearchHints.woa/wa/trends?maxCount=10'
curl -H 'x-apple-store-front: 143465-1,29' 'https://search.itunes.apple.com/WebObjects/MZSearchHints.woa/wa/hints?clientApplication=Software&term=NBA'
Nginx map
map $room $room_server {
default 192.168.1.101:8080;
1 192.168.1.101:8080;
2 192.168.1.102:8080;
}
server {
listen 80;
location ~ /api/(\d+)/room {
set $room $1;
echo $room_server;
}
}
split_clients 类似的结构,可以用来做请求 A/B 测试:
split_clients $arg_app_key $variant {
0.5% .one;
2.0% .two;
* "";
}
Shell Notes
&& || ; in shell command:
cmd1 && cmd2means cmd2 will only run while cmd1 success.cmd1 || cmd2means cmd2 will only run while fmd1 fails.cmd1 ; cmd2will run cmd2 regardless cmd1 success or not.