[RaspberryPi] Torrent 머신 만들기

Torrent 파일을 등록해놓으면, 집에 있는 서버에 해당 파일을 자동으로 다운로드 받아놓는다. transmission을 설치하면 된다.

# apt-get install transmission-cli transmission-common transmission-daemon
# service transmission-daemon stop
# vi /etc/transmission-daemon/settings.json

설정 파일의 다음 항목을 수정한다.

"download-dir": "/mnt/NAS/TorrentDownload",
"rpc-username": "dasomoli",
"rpc-password": "password",
"rpc-whitelist-enabled": false,
"umask": 2,

업로드 속도를 제한하고 싶다면 다음을 수정한다. 예를 들어, 10 KB/sec 로 제한한다면

"speed-limit-up": 10,
"speed-limit-up-enabled": true,

기본 포트를 바꾸고 싶다면 다음을 수정한다.

"rpc-port": 9000

# service transmission-daemon reload
# usermod -aG debian-transmission dasomoli

download-dir은 다운로드 받을 디렉토리, rpc-username은 웹 인터페이스로 들어갈 때 로그인 할 ID, rpc-password는 그 Password이다. rpc-whitelist-enabled를 false 로 설정하면, 말 그대로 whitelist를 사용하지 않으므로, 어디에서든 접속이 가능하다.

접속은 기본은 9091 포트로 접속하면 된다. 위에선 9000으로 바꿨다. 하지만, 포트 번호를 치긴 귀찮으므로 apache2의 proxy를 이용해서 접속하자.

# vi /etc/apache2/sites-available/torrent.dasomoli.org.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName torrent.dasomoli.org
        ServerAdmin dasomoli@gmail.com

        ProxyPass / http://localhost:9000/
        ProxyPassReverse / http://localhost:9000/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/torrent.log
        CustomLog ${APACHE_LOG_DIR}/torrent.access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

이제 proxy 모듈을 enable하고, site를 enable한 후, apache2를 재시작하자.

# a2enmod proxy
# a2enmod proxy_http
# a2ensite torrent.dasomoli.org.conf
# service apache2 restart

# sudo service transmission-daemon start

이제 http://torrent.dasomoli.org 로 접속하면 된다.
당연히 미리 DNS설정은 되어 있어야 한다.

부팅 시에 Web UI 가 연결이 안되는 경우가 있는데, 이 때는 transmission-daemon을 reload 하면 된다. 수많은 해결(이라고 주장하는) 방법이 있지만, 가장 간단하면서 잘 동작하는 방법은 그냥 raspi-config에서 “Network at Boot:”의 “Wait for network”을 체크하는 것이다.

가장 간단하지만 잘 동작하는 허무한 해결책…

참고: https://askubuntu.com/questions/157455/how-to-change-the-default-permissions-of-files-created-by-transmission-daemon

호갱노노 개발자가 읽었다는 “아파트에서 살아남기”

언젠가 페이스북에서 알게된 호갱노노라는 앱을 쓰고 있는데, 이거 물건이다.

간단히 소개하면, 부동산, 특히 아파트 실거래가를 한눈에 볼 수 있고, 해당 아파트 주변에 어느 어느 학교들이 있는지, 거기까지 얼마나 걸리는지, 주변에 시설은 무엇이 있는지 등등을 보여준다. 공개된 데이터를 모아서 보여준다는데, 공개된 데이터를 가공해서 정말 쓸모있는 정보(!)를 만들었다. 대단하다! 요새는 인구 이동도 보여주던데, 대박이다. 헐.

그 앱 개발자가 내가 아는 사람의 지인인 듯 한데 페북에 뜨길래 눌러서 타임라인을 죽 보았더니, 예전에 읽었다는 책인 것 같다. 앱이 너무 좋아서, 그 개발자가 읽었다는 책도 읽어보고 싶어졌다.

“아파트에서 살아남기” – 김효한 지음.

[C/C++] Variadic function의 default argument promotion

C/C++에서 함수에 가변 인자를 사용할 때, 그 parameter의 타입을 컴파일러가 알 수 없기 때문에, 컴파일러가 좀 쉽게 알 수 있도록, int보다 작은 타입은 int 혹은 unsigned int로, float은 double로 promotion이 일어난다고 한다.

이를 무시하고, va_start(), va_args() 매크로를 사용하면, undefined behavior이다.

[QuickBuild] RESTful API로 빌드 요청

QuickBuild를 이용할 때, 굳이 사이트에 접속해서 빌드를 돌리지 않아도 RESTful API를 이용하면 빌드를 걸 수 있다.

http://wiki.pmease.com/display/QB61/Interact+with+Build+Requests#InteractwithBuildRequests-requestnewbuild 에 해당 내용이 정리되어 있다.

Basic authentication 시에 curl을 이용해서 요청하는 방법은 다음과 같다.

$ curl -X POST -u dasomoli:password -d@request.xml http://<Server>:8810/rest/build_requests

위의 예제에서 사용한 request.xml 은 다음의 형식을 가진다. <varlables> 안에 채울 내용은 해당 configuration에서 실행한 빌드의 variables(http://<Server>:8810/build/<Build id>/variables) 페이지에서 확인 가능하다.

<com.pmease.quickbuild.BuildRequest>
  <!-- This element tells QuickBuild in what configuration to trigger build. -->
  <configurationId>10</configurationId>

  <!-- This element tells whether or not to respect build condition of the configuration. 
       If this is set to true, and if the build condition evaluates to false, build will 
       not be triggered. -->
  <respectBuildCondition>false</respectBuildCondition>

  <!-- This element is optional and is used to specify variables for build triggering. If 
       specified, it will override the variable with the same name defined in configuration
       basic setting. -->
  <variables>
    <entry>
      <string>var_name1</string>
      <string>var_value1</string>
    </entry>
    <entry>
      <string>var_name2</string>
      <string>var_value2</string>
    </entry>
  </variables>

  <!-- This element is optional and is used to tell QuickBuild to request a build promotion. -->
  <promotionSource>

    <!-- This element is optional and is used to tell QuickBuild that the source build resides on another 
         QuickBuild server. -->
    <server>
      <url>http://another-qb-server:8810</url>
      <userName>admin</userName>
      <password>admin</password>
    </server>

    <!-- Identifier of the source build to promote from -->
    <buildId>697</buildId>

    <!-- This element is optional and used to specify files to promote -->
    <deliveries>
      <com.pmease.quickbuild.FileDelivery>
        <srcPath>artifacts/dir1</srcPath>
        <filePatterns>**/*.jar</filePatterns>
      </com.pmease.quickbuild.FileDelivery>
      <com.pmease.quickbuild.FileDelivery>
        <srcPath>artifacts/dir2</srcPath>
        <filePatterns>**/*.war</filePatterns>
      </com.pmease.quickbuild.FileDelivery>
    </deliveries>
  </promotionSource>

</com.pmease.quickbuild.BuildRequest>

Sample XML의 comment에서 확인할 수 있듯이 <promotionSource>내부는 생략 가능하다.

분양사의 말바꾸기 대처 방법

분양사의 말바꾸기에 대한 대처방법에 대한 질문/답변을 보았다. 가장 좋은 방법은 국민권익위원회에 민원을 넣는 것이라 한다.

자료 수정하기 전에 모두 모아두고, 다음과 같은 형식으로 민원을 넣었다고 한다.

OOOO등의 행동은 국민의 이익에 반하고 기만하는 행위이며, 이에 따라 모든 부분 불신이 생겨 부실공사 등 안전에도 문제가 있을 것으로 생각됩니다. 입주민들의 안전과 이익을 담보삼아 재산권을 위협하는 AAA의 문제에 대해서 전반적으로 확인해주셨으면 좋겠습니다.

자료를 수정하고 준비를 하기 전에 바로 민원으로 넘어가는 것이 좋다고.. 시청에 허가받을 당시 도면 같은 것을 열람신청해서 받으라고 한다.

[RaspberryPi] USB Port control

24시간 내내 돌리면 라즈베리 파이가 너무 뜨거울 것 같아서 USB 선풍기를 포트에 연결하고, 이걸 껐다 켰다 하려고 시도했다. 결론적으론 다른 USB 기기를 쓰지 않는다면, 전체 USB 포트를 껐다 켜는 방식으로 가능하다. 다른 USB 기기를 사용한다면, 실패. 아직 디바이스 드라이버에 커널 컴파일까진 시도하고 싶지 않다.

https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=93463 쓰레드를 참고하면, hub-ctrl을 이용하면, 전체 포트 혹은 개별 포트를 껐다 켰다 하는 것을 할 수 있다.  그러나 개별 포트를 끄는 게, 실제 VBUS 전원까지 내리는 건 아니고, 그냥 못쓰게 할 뿐이다. 그래서, 전체 포트를 끄지 않는 한, 개별 포트를 꺼도 해당 포트 VBUS는 살아있기 때문에 USB 선풍기는 계속 돈다-_-;;

다음은 usb-ctrl의 설치 및 사용 방법이다.

라즈베리 파이에서 다음을 설치한다.

# apt-get install libusb-dev

다음으로 바이너리를 만든다.

# apt-get install git gcc
# git clone https://github.com/codazoda/hub-ctrl.c
# gcc -o hub-ctrl hub-ctrl.c -lusb

만든 바이너리를 적당한 곳(예를 들면, /usr/sbin/)에 설치한다.

# cp hub-ctrl /usb/sbin/

나의 경우 한 시간에 한번 정도, 50초 정도 돌게 하고 싶었다. /etc/cron.hourly 아래에 다음과 같은 스크립트를 만들어 실행 권한을 준다.

# vi /etc/cron.hourly/coolingusbfan
#!/bin/sh
hub-ctrl -h 0 -P 2 -p 1; sleep 50; sudo hub-ctrl -h 0 -P 2 -p 0

참고로, 다음 그림과 같이 포트 번호를 붙인다면,

라즈베리 파이 3 Model B의 경우, 다음과 같다고 한다.

Hub:Port — Controlled port(s)
0:1 — Controls the Ethernet port
0:2 — Controls all four USB ports (not the Ethernet)
0:3 — Controls USB Port 4
0:4 — Controls USB Port 2
0:5 — Controls USB Port 3

NAS를 위해, 외장 하드를 붙일 거라 이제 더는 위 스크립트를 사용하지 못한다.

오디오 북?

몇 주전에 메일로 거의 매일 날아오는 책 한구절을 보내주시는 분이 앞쪽에 몇 마디를 쓰시는데, 거기에 ‘부자들의 습관 10가지’류의 글을 링크해 뒀길래 심심풀이로 한번 읽어 보았었다.

책 읽는 습관에 관해 얘기하면서, 보지 못하더라도 이동 시간 중에 오디오북을 이용한단 얘기가 있었는데, 꽤 괜찮은 방법 같다. 한 7년전 쯤, 미국 출장을 갔을 때 ‘아웃라이어’ 오디오북을 사셨던 책임님이 있었는데 하는 생각도 나고. 말콤 글래드웰이 직접 읽어 주더란다. 7년 전부터 그랬으면 미국은 지금 커다란 시장이 됐겠다. 한국은 어떨까?