https://github.com/djacobs/PyAPNs

Problem 1. Push notification Failed right after sending invalid token

APNS uses socket to send notification object. and if it use invalid token, that connection will be disconnected. you can overcome this by re-generating APNs Object.

But there is one more problem. If you use for loop with same APNs Object, and there is an invalid token, the tokens right after sending invalid token will be failed. 

So, there is an option named enhanced=True, it will check each tokens if it succeeded. and It uses non-blocking ssl socket, and check error using another thread. So I think there is no critical waiting. In the function "_resend_notification_by_range" It sends only notifications after invalid token.

They also provide "send_notification_multiple" function. This function doesn't check error and discard all tokens after invalid token.


Issue 1. FeedbackConnection

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3

- connection method and how many tokens you can receive?

they use socket. and It reads data using streaming until there is no data. see below


Once you are connected, transmission begins immediately; you do not need to send any command to APNs. Read the stream from the feedback service until there is no more data to read.

... 

The feedback service’s list is cleared after you read it. Each time you connect to the feedback service, the information it returns lists only the failures that have happened since you last connected.


'분류없음' 카테고리의 다른 글

[cpp] std::move는 단지 캐스팅일 뿐이라고?  (0) 2017.02.08
Same string but different length  (0) 2016.10.28
JIT vs Interpreter  (0) 2016.10.25
git pushed merge cancel  (0) 2015.04.13
[encoding] javascript write to csv  (0) 2015.04.11
블로그 이미지

시간을 거스르는자

,

nginx log ratation

nginx 2015. 4. 6. 11:15

nginx설정을 따로 안하면 미친듯이 로그를 쌓아서 10기가나 차지하고 있는것을 볼수 있다.

weekly로 쌓는 로그를 가능하면 daily로 바꿔주거나 로그가 필요하면 디스크용량을 충분히 갖춰야!

설정법

http://www.nginxtips.com/how-to-rotate-nginx-logs/

'nginx' 카테고리의 다른 글

Loadbalancer를 통해서 올때 client ip가 전달되도록하는 방법  (0) 2018.01.12
ssl setting  (0) 2015.03.12
mac 에서 nginx 설치 및 설정 하기  (0) 2014.10.24
블로그 이미지

시간을 거스르는자

,

Approach1. Using awscli (you don't have to make codes)

1. before collecting some metrics from your instance, your instance must be lauched with CloudWatchFullAccess IAM role.

ref: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/UsingIAM.html

Amazon CloudWatch integrates with AWS Identity and Access Management (IAM) so that you can specify which CloudWatch actions a user in your AWS Account can perform. For example, you could create an IAM policy that gives only certain users in your organization permission to use GetMetricStatistics. They could then use the action to retrieve data about your cloud resources. 

* in my  case, I made new role(named cloudwatch_test) on IAM service with CloudWatchFullAccess, CloudWatchLogsFullAccess policies. and launch ec2 instance with this IAM role. 


2. follow this. to install cloudwatch tool stuffs

http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/mon-scripts-perl.html


3. After installing perl stuffs and finishing role settings, you can use perl command like this.

$ sudo mv aws-scripts-mon /usr/local/bin/aws-scripts-mon

$ echo "* * * * * ubuntu /usr/local/bin/aws-scripts-mon/mon-put-instance-data.pl --mem-used --mem-avail --disk-path=/dev/xvda1 --disk-space-used --dis-space-avail --from-cron" | sudo tee /etc/cron.d/aws-monitor-mem-disk-usage

* "ubuntu" is user name 

now you can check your custom metric in Ec2 monitoring->View all CloudWatch metrics->Metrics-> Linux System Metrics

if you want to monitor your existing ec2 instance, unfortunately there is no way. I tried below, but it was not working.

(you should install awscli tool first, just type $sudo apt-get install awscli, $aws configure)

1. aws iam create-instance-profile --instance-profile-name CloudWatchProfile

2. aws iam add-role-to-instance-profile --instance-profile-name CloudWatchProfile --role-name cloudwatch_test


Approach2. Using Boto (you have to do some works, but could be more flexible)

http://arr.gr/blog/2013/08/monitoring-ec2-instance-memory-usage-with-cloudwatch/

followed record.

1. make t2 micro ec2 instance (ubuntu)

2. install prerequisites

$sudo apt-get update

$sudo apt-get install python-pip

$sudo pip install boto

3. setup boto config file

$sudo vim /etc/boto.cfg

[Credentials]
aws_access_key_id = <your_access_key_here>
aws_secret_access_key = <your_secret_key_here>

4. get source code and set to cron job

$ curl https://gist.githubusercontent.com/shevron/6204349/raw/cw-monitor-memusage.py | sudo tee /usr/local/bin/cw-monitor-memusage.py

$ sudo chmod +x /usr/local/bin/cw-monitor-memusage.py

$ echo "***** ubuntu /usr/local/bin/cw-monitor-memusage.py" | sudo tee /etc/cron.d/cw-monitor-memusage

* "ubuntu" is user name 

5. check it in AWS management console

Ec2 monitoring->View all CloudWatch metrics->Metrics-> Custom Metrics (it will take a time, wait until this menu created)




'aws' 카테고리의 다른 글

AWS lambda 삽질 일기  (0) 2017.03.17
kinesis firehose 삽질일기  (0) 2017.03.16
elasticache dump to file  (1) 2015.03.23
[ubuntu server instance] mytoon setting  (0) 2014.10.24
HTTP 505: HTTP Version Not Supported  (0) 2014.07.09
블로그 이미지

시간을 거스르는자

,

elasticache dump to file

aws 2015. 3. 23. 21:48

elasticache는 save명령어가 disable되어있다. 

replica set으로 구성되어있어서 불필요한 disk 저장이 필요없기도 하거니와 save명령어는 synchronous 하기때문에 redis block을 초래하기 떄문일지도 모르겠다.

암튼, 혹 redis를 아마존 서비스를 이용해서가 아닌 그냥 ec2에 띄워서 쓰고 싶다면, 어쨌거나 data를 백업해서 가져와야하는데 save가 없으니 어떻게 하냐

redis-cli -h hostname sync > dump.rdb

명령어를 이용. (로컬에서 해봤더니 자체 sync만 동작하고 파일엔 데이터가 안써짐. 아무래도 remote host에 있는걸 여기로 sync한다는 것으로 remote에 있는 redis host를 써야하나봄)

아무튼 elasticache host는 위 명령어로 data를 backup할 수 있고 

redis.conf 파일에 셋팅된 dir 패스에 dump.rdb를 넣어놓고 redis를 다시 시작하면 쭉~ 들어간다.

'aws' 카테고리의 다른 글

kinesis firehose 삽질일기  (0) 2017.03.16
How to EC2 disk and memory usage monitoring  (0) 2015.03.27
[ubuntu server instance] mytoon setting  (0) 2014.10.24
HTTP 505: HTTP Version Not Supported  (0) 2014.07.09
boto s3 Broken pipe error  (0) 2014.04.25
블로그 이미지

시간을 거스르는자

,

celery 오해와 진실

celery 2015. 3. 13. 11:44

Python Celery를 보면 기본적으로 워커와 잡의 개념이기 때문에

일단 task를 요청하면 무조건 잡이 큐에 들어갈 것같다.

하지만 이건 오해다.


진실을 말하자면,

잡은 sync와 async로 요청을 할 수 있는데, 이때 sync로 요청하면 큐에 들어가지 않고 부른 프로세스에서 걍 처리한다. 

이렇게 직접 일을 처리하기위함도 있고 기타 등등의 설정을 유지하기 위해 워커뿐 아니라 잡을 요청하는 녀석도 celery app을 실행시키는 스크립트를 실행한다. (보통 celery.py 라고 명명하고 쓰는..)


그래서 주의할 것은

다이나믹 실행환경을 쓸경우 env라는 키를 만들어서 큐 Broker url을 동적으로 넣어줄 수 있는데, 이때 워커가 실행될때 설정되는것 이외에 잡을 던지는 녀석이 실행될때도 올바른 Broker url 이 들어가도록 해야한다는 것이다.

블로그 이미지

시간을 거스르는자

,

ssl setting

nginx 2015. 3. 12. 10:48

sites-available 에 ssl 파일을 만들어 다음을 추가한다.

server {

listen        443 ssl;

        root /usr/share/nginx/www;

keepalive_timeout         70;

server_name        any.yourdomain.com;

ssl_protocols               TLSv1 TLSv1.1 TLSv1.2;

        ssl_certificate             /etc/nginx/conf/self-cert.pem;

        ssl_certificate_key         /etc/nginx/conf/privkey.pem;

        ssl_session_cache           shared:SSL:10m;

        ssl_session_timeout         10m;

}

reference

http://nginx.org/en/docs/http/configuring_https_servers.html


블로그 이미지

시간을 거스르는자

,

1. crossdomain.xml Issue

-> your target server should offer this file via https(443 port) But not CA certificate needed. self-signed certificate is available.

<?xml version="1.0"?>

<cross-domain-policy>

<allow-access-from domain="*" to-ports="*" secure="false"/>

</cross-domain-policy>

-> I noticed that webPlayer send request for "crossdomain.xml" file via http not https. if your server domain "sub.yourdomain.com:9989", the webPlayer will send request to find "crossdomain.xml" via "sub.yourdomain.com:9989/crossdomain.xml"  

(So, I think "Https setting is not neccessary for crossdomain.xml)


2. explorer blocks post request.

-> check your headers, If there is an empty value on the key, The request could be blocked when using microsoft explorer.


3. (python tornado) request.arguments could be empty

-> just use request.body instead of arguments

블로그 이미지

시간을 거스르는자

,

가이드: https://www.openssl.org/docs/HOWTO/certificates.txt

이 문서에서 2, 3번 항목 참조


Terminal 에서 다음순서로 생성

2. Relationship with keys: $openssl genrsa -out privkey.pem 2048 (default는 1024)
3. Creating a certificate request: $openssl req -new -key privkey.pem -out csr.pem

Country Name (2 letter code) [AU]:KR

State or Province Name (full name) [Some-State]:Seoul

Locality Name (eg, city) []:Seoul

Organization Name (eg, company) [Internet Widgits Pty Ltd]:Makamoye

Organizational Unit Name (eg, section) []:Mytoon

Common Name (e.g. server FQDN or YOUR name) []:contents.mytoon.com

Email Address []:ytkang86@gmail.com


Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:


이렇게 csr.pem을 생성해서 CA기관에 인증 요청을 한다.

가비아에 요청해서 codomo인증을 받았는데 아래와 같은 파일들을 보내줬다.

1. RootCA_ChainCAs_Basic.zip

2. Seal_sample.zip

3. contents_mytoon_com_csr.pem

4. contents_mytoon_com_cert.pem

여기서 2번은 인증마크 홈페이지에 붙이는샘플이고, 1번은 chain파일과 rootCA파일이 있다. 본인은 처음에 rootCA인증서는 뭐지? 했는데 이건 선택한 CA기관이 이 rootCA에 의해서 믿을만 한것이란 의미라고 한다. 아무튼 우리는 4번을 signed certificate으로 이용하면되고. 필요에 따라서 chainCA를 같이 쓰면되겠다.


  • self signed certificate 생성 명령어

$openssl x509 -req -days 365 -in csr.pem -signkey privkey.pem -out self-cert.pem

'서버 교양' 카테고리의 다른 글

[펌] 인증 암호화와 해쉬  (0) 2016.10.29
Docker overview  (0) 2015.06.13
글로벌 푸시 시스템 구성하기  (0) 2015.01.16
글로벌 푸시 보내기  (0) 2014.11.27
mongodb만 쓰면 mysql을 과연 안써도 될까?  (0) 2014.04.23
블로그 이미지

시간을 거스르는자

,

비동기처리를 쓰는 서버에서 1개의 connection을 공유해서 쓴다고 했을때 그냥 모르고 쓰다보면 일단 2가지 문제가 생길 수 있는데..

문제1. select 요청

2개 의 커서를 쓴다고 해보자.

이때 1번 커서가 select를 해놓고 fetchall을 안한 상태에서 

2번 커서가 select를 요청하면 unread query가 있다고 exception이 발생한다. (insert 는 가능)

그리고 select의 결과는 connection에 있기 때문에 1번 커서가 select하고 2번 커서에서 fetchall을 해도 결과가 전달 된다.


문제 2. transaction

mysql transaction을 걸어놓고 비동기에 빠져 있다면,

다른 핸들러가 새로운 transaction을 시작할 수 있다. 이렇게 되면 exception 발생!

따라서 connection pool을 만들어 놓고 쓰는 것이 아닌이상 transaction을 걸고 비동기로 들어가면 안된다!


'mysql' 카테고리의 다른 글

Making scheduler for expiry  (0) 2018.01.19
블로그 이미지

시간을 거스르는자

,

LITE IDE setup

Go 2015. 1. 28. 12:58

https://github.com/visualfc/liteide/blob/master/liteidex/deploy/welcome/en/install.md

* MAC OS X 사용


1. ./update_pkg.sh

./update_pkg.sh 하는순간

../liteide-master/liteidex/src/golang.org/x/tools/astutil (from $GOPATH)

이런 에러를 경험한다.

일단 $GOPATH를 ~~~/liteide-master/liteidex 로 잡아준뒤

go get golang.org/x/tools/go/ast/astutil

로 패키지 설치해줌

그런뒤 실행해보면 똑같은 에러를 경험할 것이다. 자세히 보면

../liteide-master/liteidex/src/golang.org/x/tools/go/ast/astutil

설치는 여기 되어있는데 이상한데서 찾고있음

소스코드가 업데이트 중이라는데 아직 반영안됬나봄 짱나서 그냥 심링크 걸어줌

ln -s /Users/ytkang/liteide-master/liteidex/src/golang.org/x/tools/go/ast/astutil /Users/ytkang/liteide-master/liteidex/src/golang.org/x/tools/astutil


그리고 실행하면 이런 에러를 맞본다

liteidex/src/golang.org/x/tools/astutil expects import "golang.org/x/tools/go/ast/astutil"

코드 다 찾아가서 import "golang.org/x/tools/go/ast/astutil" 로 바꿔줌 (파일 2개밖에 안됨)

이제 ./update_pkg.sh 통과.


2. ./build_osx.sh

이거 할려면 QT SDK를 깔아야되는데 망할 다운로드 페이지가 열리지 않는다. QT Creator를 깔았는데 폴더 구조가 맞지 않음 ==;;

그래서 아직 진행중.. 데밋! IDE까는게 왜케 힘들어!


'Go' 카테고리의 다른 글

Goroutine context switching 시점  (0) 2018.04.20
How to run go app in heroku by your own project (with github)  (0) 2017.02.24
cannot download, $GOPATH not set  (0) 2015.01.28
블로그 이미지

시간을 거스르는자

,