2013년 7월 31일 수요일

postgreSQL - backup script

0. The password file

"The file .pgpass in a user's home directory or the file referenced by PGPASSFILE can contain passwords to be used if the connection requires a password (and no password has been specified otherwise). On Microsoft Windows the file is named %APPDATA%\postgresql\pgpass.conf (where %APPDATA% refers to the Application Data subdirectory in the user's profile)
This file should contain lines of the following format:"
hostname:port:database:username:password
-  backup을 위해서 password 파일을 참고해야 하며, 나의 경우: C:\Documents and Settings\Administrator\Application Data\postgresql에 있다.

- 혹은 파일을 복사해서 사용해도 된다. (아래 script에서는 d:\pgpass.conf로 복사해서 사용함)

1. pg_dump.bat

Everyday db dump script

  @echo off
   for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
     set dow=%%i
     set month=%%j
     set day=%%k
     set year=%%l
   )
   set datestr=%month%_%day%_%year%
   echo datestr is %datestr%
   
   set FILE=pgdump_%date%.backup
   echo backup file name is %FILE%
   SET PGPASSFILE=D:\pgpass.conf
   echo on
   pg_dump -i -U username -Fc -b -v -f %FILE% dbname

2.  pg_dumpall.bat

"The above mechanism is cumbersome and inappropriate when backing up an entire database cluster. For this reason the pg_dumpall program is provided. pg_dumpall backs up each database in a given cluster, and also preserves cluster-wide data such as users and groups." 
SET PGPASSFILE=D:\pgpass.conf
"PostgreSQL_PATH\bin\pg_dumpall.exe" -U username > .\db.out postgres"

2013년 7월 30일 화요일

tomcat - clear tomcat shutdown errors

0. Tomcat shutdown errors?


- tomcat shutdown.bat 실행했는데 tomcat console 창이 닫히지 않는다. 

 - console log를 살펴 보면 "심각: The web application [] appears to have started a thread named ......" 이라고 찍혀있는데 대부분 user thread 처리에 대한 내용이다.

 - 사실 shutdown 시 발생하는 에러는 심각한 내용이 아니라서 그냥 넘어 갈수도 있는데, nightly build script 작성시 골치가 아프다.

1. Java Thread (Thread VS. Daemon Thread)

- Java thread에 대한 이해가 선행되어야 한다.

- "JVM doesn’t wait for any daemon thread to finish before exiting"

- 아래는 shutdown 후 java process를 확인해 봤다. 아직 종료되지 않은 user thread가 3개가 있다. 

2. A thread named [Timer-0]

문제가 되는 code snippet이다. 한 번 살펴보자.

public class xxx {
public static void init(){
Timer t= new Timer();
t.scheduleAtFixedRate(new xxxTask (), new Date(), 1000);
}
}
public class xxxTask extends TimerTask {
@Override
public void run() {
......
}
}
- 원인: 위 코드는 TimerTask를 이용하여 user thread를 시작했으나 중지 하는 코드가 없다.

해결 방법: tomcat 종료 시 callback 호출을 통해 user thread를 중지시킨다.

- web.xml에 servlet context listener 등록하고
<listener>
    <listener-class>pkg.xxx</listener-class>
</listener>

- ServletContextListener 구현하면 된다.

public class xxx implements ServletContextListener{ @Override
public void contextInitialized(ServletContextEvent arg0) {
t= new Timer();
t.scheduleAtFixedRatenew xxxTask(), new Date(), 1000);
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {             t.cancel();
            xxxTask.cancel();
}
}

3. A thread named [pool-17-thread-1]

- 문제가 되는 서버는 MINA를 사용하고 있다. 아래는 MINA Architecture다.
이따가 계속

2013년 7월 25일 목요일

github - android + egit + github

0. overview

  •  this article gives you some ideas how to integrate GitHub with Android development environment.
  • I tried to make it simple as possible. I didn't use any of unnecessary tools like GitHub client, Git bash shell etc.
  • EGit has a few bugs. (like pushing to remote error) I recommend you to do exactly same procedure as shown.

1. Android 

With a single download, the ADT Bundle includes everything you need to begin developing apps:


  • Eclipse + ADT plugin
  • Android SDK Tools
  • Android Platform-tools
  • The latest Android platform
  • The latest Android system image for the emulato
    • plus EGit! (eclipse git plugin)

    2. GitHub

    • Make a new repository on GitHub
    https://help.github.com/articles/create-a-repo

    3. EGit (Git eclipse plugin)

    • create a local git repository (from Git Repository Exploring perspective)
    • create new android project
    • share (Team > Share Project > Git > )
    workspace is changed !! you need to adjust java build path.
    •  commit (Team > Commit)
     you can skip Add To Index.
    •  create remote (with GitHub repo URL)

    •  push to remote (Team > Remote > Push)

    4. visit GitHub and check repository

    • or see show in history (Team > Show In History)

    2013년 7월 23일 화요일

    eclipse - flash builder plugin

    0. 개요 
     - Adobe FLEX는 Flash builder를 사용하여 개발하는데 java 코드와 함께 개발하기 위해서 두개의 IDE를 띄우는 건 불편하다. 
     - Flash builder를 eclipse의 plugin으로 설치하여 사용한다. 

    1. install 
     - Flash builder 4.5 부터는 flash builder 설치 폴더에 플러그 인 설치 파일이 있다. (즉 flash builder를 설치해야 eclipse plug-in을 설치할 수 있다.) 
     - run C:\Program Files\Adobe\Adobe Flash Builder 4.5\utilities\Adobe Flash Builder 4.5 Plug-in Utility.exe 

    2. 영문 모드 설정 
     - plug-in을 설치하면 한글 모드로 eclipse가 실행된다. 어째 더 불편하네.. 
     - Eclipse.ini에서 아래를 추가 
      -vm 
      -Duser.language=en -Duser.country=US 

    3. Flash player debug 버전 설치 
     - http://www.adobe.com/support/flashplayer/downloads.html

    4. Chrome 설정 (IE는 상관없음) 
     - Chrome은 flash player를 번들로 제공하면서 자체적으로 자동으로 업그레이드 하기 때문에 pc에 설치된 adobe player를 사용하지 않는다. 
    - chrome://plugins/ : 크롬 브라우저에 입력 
    - 오른쪽 상단의 세부 정보 클릭 --> "flash" 검색 
    - 크롬 폴더의 player는 ‘사용안함’ system의 player는‘사용' 으로 설정 (화면에 표시되는 건 반대니 주의)


    2013년 7월 18일 목요일

    apache - tomcat, jetty 연동

    0. overview











    - 위와 같은 구성의 Apache (Web) + Tomcat/Jetty (WAS) 연동을 위한 설정이다.

    1. Download Apache HTTP server
     - http://httpd.apache.org/download.cgi#apache22에서 httpd-2.2.22-win32-x86-openssl-0.9.8t.msi 파일 다운로드 후 디폴트 설치

    2. Download Apache Tomcat connector
     - http://apache.tt.co.kr/tomcat/tomcat-connectors/jk/binaries/windows/ 에서 tomcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip 파일을 다운로드 mod_jk.so 파일을 아파치 설치 폴더의 modules 폴더에 복사한다

    3. Apache web server configuration 
     - httpd.conf에서 아래와 같이 설정한다.
    ...
    Include conf/mod_jk.conf
    NameVirtualHost *:80
    <VirtualHost *:80>
                      ServerName 1.1.1.1
                      DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/root"
                      JkMount /*.jsp was
                      JkMount /servlet was               
                      JkMount /birt/* was
                     
                      JkMount /mobile/* mobile
    </VirtualHost>

    ProxyRequests Off
    <Proxy *>
    Order deny,allow
    Allow from all
    </Proxy>
    ProxyPass /jetty http://ip:port/jetty
    ProxyPreserveHost On

    ProxyStatus On
    ...

    3.1. Tomcat 연동
     - Include conf/mod_jk.conf : mod_jk configuration 파일을 include 한다
     - DocumentRoot : 아파치 root 폴더를 지정한다. http://x.x.x.x/index.html 로 접근한다면 DocumentRoot로 지정된 폴더의 index.html이 호출된다.
     - JkMount /*.jsp was: jsp 파일을 servlet container로 전달하는 설정이다. “was”는 worker.properties 파일에 정의 되어 있다

    3.2. Jetty 연동
     - Jetty 연동을 위한 방법은 아래 3가지 방법이 있다. Jetty 에서 권장하는 1번 방법으로 설정한다
    1. Using apache mod_proxy and an normal Jetty HTTP connector.
    2. Using apache mod_proxy_ajp and the Jetty AJP connector.
    3. Using apache mod_jk and the Jetty AJP connector

     - 설정 파일의 ProxyPass /jetty http://ip:port/jetty에 해당하는 부분이 proxy를 이용한 연동 설정이다. (reverse proxy 방법) jetty 만을 위한 설정은 proxy 설정으로 끝난다

    4. mod_jk.conf
    LoadModule jk_module modules/mod_jk.so
    <IfModule mod_jk.c>
                      JkWorkersFile conf/workers.properties
                      JkLogFile logs/mod_jk.log
                      JkLogLevel info
                      JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
                      JkRequestLogFormat "%w %V %T"

    </IfModule>

     - 디폴트로 아파치 설치시에는 해당 파일이 없으므로 위 내용으로 파일을 작성한 후 conf 폴더에 저장한다. LoadModule 를 통해 해당 모듈을 load한 후 기타 설정을 한다. 중요한 부분은 workers.properties를 설정한 부분이다

    5. workers.properties
    worker.list=was, mobile
    worker.conv_bp.port=123
    worker.conv_bp.host=10.10.10.10
    worker.conv_bp.type=ajp13

    worker.mobile.port=321
    worker.mobile.host=20.20.20.20
    worker.mobile.type=ajp13

     - tomcat ajp13 프로토콜을 이용한 연동 설정이다. was, mobile 두개의 tomcat과 연동하는 설정이다. Tomcat server.xml ajp13 포트를 확인한 후 작성한다.

    6. ref

    2013년 7월 17일 수요일

    mssql - drop database (single user mode)

    0. 사용중인 database를 drop 하기 위해선 single_user 모드로 바꿔줘야 한다.

    1. single_user mode
    USE master;
    GO
    ALTER DATABASE AdventureWorks2012
    SET SINGLE_USER
    WITH ROLLBACK IMMEDIATE;
    GO
    ALTER DATABASE AdventureWorks2012
    SET READ_ONLY;
    GO
    ALTER DATABASE AdventureWorks2012
    SET MULTI_USER;
    GO
    
    2. 나 같은 경우 여전히 session에 물려있어 drop database 혹은 multi_user로 바뀌지가 않는다. 이럴 때 아래를 참고해서 session id를 찾아서 kill 해준 후 drop 해준다.

    select d.name, d.dbid, spid, login_time, nt_domain, nt_username, loginame
      from sysprocesses p inner join sysdatabases d on p.dbid = d.dbid
     where d.name = 'database_name'
    go
    
    
    kill 51 go

    3. ref
     - http://remidian.com/2008/01/remove-sql-server-database-from-single-user-mode/

    2013년 7월 3일 수요일

    literal ?

    0. JavaScript: The Good Parts by 
     - javascript 관련 서적 중 가장 많이 추천되고, 실제로도 잘 쓰여진 책이다.
     - 책에 보면 literal이라는 용어가 많이 나오는데 이게 멀까? syntax랑 머가 다를까?

    1. literals in java
     - java의 primitive data type은 아래와 같다












     - literal이라는 것은 이러한 data type에 값을 대입할 때의 값 자체를 말한다. (네이버에는 상수로 번역이 되어 있는데 흔히 말하는 constant variable과는 구분 되어야 될 것 같다.) 

     - 다만 number 26을 decimal, hexadecimal, binary로 표기하면 각각 26, 0x1a, 0b11010 (java se7 and later)이 되는데, 표기법만 다르지 값 자체는 같다. 즉 값을 어떻게 표기하는가 하는 것이 literal이 되겠다. (앞의 예는 java tutorial의 integer literals의 예시다)

     - 표기법엔 여러가지가 있다. 0x1a처럼 prefix를 사용하거나, 0.0f 처럼 suffix를 사용하거나, null 처럼 예약어를 사용할 수도 있다.

     - JAVA SE 7 부터는 아래도 가능하다고 하니 관심 있으면 (Using Underscore Characters in Numeric Literals) 챕터를 참고 하면 되겠다.
    long creditCardNumber = 1234_5678_9012_3456L;

    2. literals in javascript












     - douglas crockford의 책에 보면 위의 그림이 나온다.

     - Javascript에서는 아래와 같이 변수에 object나 function도 대입이 가능하다. 그리고 script 언어이기 때문에 따로 compile 되지 않는다. 그래서 literal이라는 용어를 사용한 것 같다. 






    3. summary
     - syntax, grammar 이렇게 쓰면 이해가 쉽게 되는데, literal이라고 하니 이해가 힘들어서 정리를 좀 했는데, 사실 literal이라는 것도 값 자체를 나타내는 표기법이니 구문, 문법의 일종이라고 생각하면 속 편하겠다.


    * ref