Hatena::ブログ(Diary)

kinneko@転職先募集中の日記

検索エンジンから来た方へ: 申し訳ないですが、日記なので日々積み重なっています。
目的の情報にたどり着くには、右の検索窓から日記内を再検索してください。
北陸エリア内(もしくはエリア外でも)で転職先を探しています。
(マジです。ネタではありません。ホントですって...)
詳細履歴書をご希望の方はメールでご連絡下さいませ。(kinneko at gmail.com)

2012-01-07

[][] OSQAの鯖を立ててみる(trunk失敗)

基本は、以下のいしもとさんの情報をなぞるだけ。

http://d.hatena.ne.jp/atsuoishimoto/20110510/1305012665

ターゲットは、AtomなQNAPマシン。

ずっと前にredmine立てる勉強してたときに使ってたもの。

http://d.hatena.ne.jp/kinneko/20110527/p6

http://d.hatena.ne.jp/kinneko/20110527/p1

http://d.hatena.ne.jp/kinneko/20110526/p36

http://d.hatena.ne.jp/kinneko/20110526/p37

去年の5月なのね...

久しぶりに電源を入れたら、236日起動してないってfsckかかったよ。

確かミニマムインストールから、パッケージ追加していったやつだったよな。

なので、sudoも入っていない。

とりあえず、squeezeではあるので、apt-get update && upgradeする。

さすがに時計は数分ズレている。

ntpdateを追加インストールして時刻合わせする。

# ntpdate ntp.ring.gr.jp
# hwclock -w

ホスト名がredmineなので、OSQAに変更する。

# vi /etc/hostname
# vi /etc/hosts

kernelも上がったので、再起動しておく。

redmineの残骸を削除。

root@OSQA:~# apt-get remove --purge redmine redmine-sqlite
root@OSQA:~# apt-get autoremove

残パッケージは216ある。

まだ多い気がするけど、とりあえずこんなもんで進める。


python 2.6以降

OSQAは、Python/Django上で動作する。

Pythonのバージョン確認。2.6以降が必要。

pythonはいってねぇ...

入れる。

root@OSQA:~# apt-get install python
The following NEW packages will be installed:
  python python-minimal python2.6 python2.6-minimal

python-setuptoolsやdjangoを入れる。

root@OSQA:~# apt-get install python-setuptools
The following NEW packages will be installed:
  python-pkg-resources python-setuptools
root@OSQA:~# apt-get install python-django
The following NEW packages will be installed:
  javascript-common libjs-jquery python-django python-support wwwconfig-common

easy_installで、必要なパッケージを自動インストールする。

root@OSQA:~# easy_install South django django-debug-toolbar markdown html5lib python-openid
install_dir /usr/local/lib/python2.6/dist-packages/
Searching for South
Reading http://pypi.python.org/simple/South/
Reading http://south.aeracode.org/
Reading http://south.aeracode.org/wiki/Download
Best match: South 0.7.3
Downloading http://pypi.python.org/packages/source/S/South/South-0.7.3.tar.gz#md5=32bd32fd98a912547976c2434703109e
Processing South-0.7.3.tar.gz
Running South-0.7.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-0pNbUu/South-0.7.3/egg-dist-tmp-EFQOC1
zip_safe flag not set; analyzing archive contents...
south.migration.base: module references __file__
south.tests.__init__: module references __file__
Adding South 0.7.3 to easy-install.pth file

Installed /usr/local/lib/python2.6/dist-packages/South-0.7.3-py2.6.egg
Processing dependencies for South
Finished processing dependencies for South
Searching for django
Best match: Django 1.2.3
Adding Django 1.2.3 to easy-install.pth file

Using /usr/lib/pymodules/python2.6
Processing dependencies for django
Finished processing dependencies for django
Searching for django-debug-toolbar
Reading http://pypi.python.org/simple/django-debug-toolbar/
Reading http://rob.cogit8.org/blog/2008/Sep/19/introducing-django-debug-toolbar/
Reading http://github.com/robhudson/django-debug-toolbar/downloads
Reading http://robhudson.github.com/django-debug-toolbar/
Reading https://github.com/django-debug-toolbar/django-debug-toolbar
Reading https://github.com/django-debug-toolbar/django-debug-toolbar/downloads
Best match: django-debug-toolbar 0.9.1
Downloading http://pypi.python.org/packages/source/d/django-debug-toolbar/django-debug-toolbar-0.9.1.tar.gz#md5=bd6a888e1ea147e59f021be4e8d149c3
Processing django-debug-toolbar-0.9.1.tar.gz
Running django-debug-toolbar-0.9.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-uezLfL/django-debug-toolbar-0.9.1/egg-dist-tmp-EVpX4Q
Adding django-debug-toolbar 0.9.1 to easy-install.pth file

Installed /usr/local/lib/python2.6/dist-packages/django_debug_toolbar-0.9.1-py2.6.egg
Processing dependencies for django-debug-toolbar
Finished processing dependencies for django-debug-toolbar
Searching for markdown
Reading http://pypi.python.org/simple/markdown/
Reading http://www.freewisdom.org/projects/python-markdown
Reading https://sourceforge.net/project/showfiles.php?group_id=153041
Reading http://www.freewisdom.org/projects/python-markdown/
Best match: Markdown 2.1.0
Downloading http://pypi.python.org/packages/source/M/Markdown/Markdown-2.1.0.zip#md5=22f580f3cbd7ed94321ef8ed1a51e784
Processing Markdown-2.1.0.zip
Running Markdown-2.1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-LJyFk7/Markdown-2.1.0/egg-dist-tmp-r3Vbuq
zip_safe flag not set; analyzing archive contents...
Adding Markdown 2.1.0 to easy-install.pth file
Installing markdown_py script to /usr/local/bin

Installed /usr/local/lib/python2.6/dist-packages/Markdown-2.1.0-py2.6.egg
Processing dependencies for markdown
Finished processing dependencies for markdown
Searching for html5lib
Reading http://pypi.python.org/simple/html5lib/
Reading http://code.google.com/p/html5lib/
Best match: html5lib 0.90
Downloading http://html5lib.googlecode.com/files/html5lib-0.90.zip
Processing html5lib-0.90.zip
Running html5lib-0.90/setup.py -q bdist_egg --dist-dir /tmp/easy_install-R4C5Tq/html5lib-0.90/egg-dist-tmp-89xM_m
zip_safe flag not set; analyzing archive contents...
Adding html5lib 0.90 to easy-install.pth file

Installed /usr/local/lib/python2.6/dist-packages/html5lib-0.90-py2.6.egg
Processing dependencies for html5lib
Finished processing dependencies for html5lib
Searching for python-openid
Reading http://pypi.python.org/simple/python-openid/
Reading http://www.openidenabled.com/openid/libraries/python/
Reading http://github.com/openid/python-openid
Reading http://github.com/openid/python-openid/tarball/2.2.5
Reading http://openidenabled.com/python-openid/
Reading http://github.com/openid/python-openid/tarball/2.2.4
Best match: python-openid 2.2.5
Downloading http://pypi.python.org/packages/source/p/python-openid/python-openid-2.2.5.zip#md5=f89d9d4f4dccfd33b5ce34eb4725f751
Processing python-openid-2.2.5.zip
Running python-openid-2.2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-IZRTUf/python-openid-2.2.5/egg-dist-tmp-WML6OE
warning: no files found matching 'CHANGELOG'
warning: no files found matching '*.css' under directory 'doc'
warning: no files found matching '*.html' under directory 'doc'
zip_safe flag not set; analyzing archive contents...
Adding python-openid 2.2.5 to easy-install.pth file

Installed /usr/local/lib/python2.6/dist-packages/python_openid-2.2.5-py2.6.egg
Processing dependencies for python-openid
Finished processing dependencies for python-openid

DBを確認

今回は、SQLiteを使うので、入っているかチェック。

root@OSQA:~# dpkg -l | grep sqlite
ii  libaprutil1-dbd-sqlite3             1.3.9+dfsg-5                 The Apache Portable Runtime Utility Library - SQLite3 Driver
ii  libsqlite3-0                        3.7.3-1                      SQLite 3 shared library

OSQA最新バージョンの確認

http://www.osqa.net/download/

SVNから落とせとある。

そーなのか...

まず、svnを入れないと。

root@OSQA:~# apt-get install subversion
The following NEW packages will be installed:
  libneon27-gnutls libserf-0-0 libsvn1 libxml2 sgml-base subversion xml-core

OSQAを、どこに入れるか。

/home/OSQAか。

パーミッションはどうしたらいいのかな。

めんどくさいので専用ユーザーでも作るか。

root@OSQA:~# adduser osqa
root@OSQA:~# su - osqa
osqa@OSQA:~$ 

OSQAをチェックアウト。

osqa@OSQA:~$ svn co http://svn.osqa.net/svnroot/osqa/trunk .
(snip)
Checked out revision 1218.

落ちたのは、こんな感じ。

osqa@OSQA:~$ ls
cron           INSTALL  manage.py       settings_local.py.dist
forum          LICENSE  osqa.iml        settings.py
forum_modules  locale   osqa.wsgi.dist  tmp
__init__.py    log      rmpyc           urls.py

キャッシュディレクトリを作成。

osqa@OSQA:~$ mkdir cache

settings_local.py.distファイルをコピーし、設定ファイルを作成する。

osqa@OSQA:~$ cp settings_local.py.dist settings_local.py
osqa@OSQA:~$ vi settings_local.py

フォーム形式が少し変わっている。

入っているdjangoは、1.2.3-3+squeeze2。

とりあえず、こんな感じで。

osqa@OSQA:~$ diff -Naur settings_local.py.dist settings_local.py
--- settings_local.py.dist	2012-01-05 17:02:38.578122409 +0900
+++ settings_local.py	2012-01-05 17:16:02.132614872 +0900
@@ -26,7 +26,7 @@
 
 DATABASES = {
     'default': {
-        'ENGINE': 'django.db.backends.mysql',
+        'ENGINE': 'django.db.backends.sqlite',
         'NAME': 'osqa',
         'USER': 'root',
         'PASSWORD': '',
@@ -45,14 +45,14 @@
 APP_URL = 'http://'
 
 #LOCALIZATIONS
-TIME_ZONE = 'America/New_York'
+TIME_ZONE = 'Asia/Tokyo'
 
 #OTHER SETTINGS
 
 USE_I18N = True
-LANGUAGE_CODE = 'en'
+LANGUAGE_CODE = 'ja'
 
-DJANGO_VERSION = 1.1
+DJANGO_VERSION = 1.2
 OSQA_DEFAULT_SKIN = 'default'
 
 DISABLED_MODULES = ['books', 'recaptcha', 'project_badges']

DBの初期化

あー、ここでsudoいるのね... orz

root@OSQA:~# apt-get install sudo
root@OSQA:~# visudo 
osqa	ALL=(ALL) ALL

初期化。

osqa@OSQA:~$ sudo python manage.py syncdb --all
Error was: No module named sqlite.base

ダメか。

適当に名前書いたしな(^^;。

これか?

        'ENGINE': 'django.db.backends.sqlite3',
osqa@OSQA:~$ sudo python manage.py syncdb --all
Traceback (most recent call last):
  File "/home/osqa/forum_modules/mysqlfulltext/__init__.py", line 8, in <module>
    import MySQLdb
ImportError: No module named MySQLdb
Traceback (most recent call last):
  File "/home/osqa/../osqa/forum_modules/mysqlfulltext/__init__.py", line 8, in <module>
    import MySQLdb
ImportError: No module named MySQLdb
Syncing...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table forum_keyvalue
Creating table forum_user
Creating table forum_userproperty
Creating table forum_subscriptionsettings
Creating table forum_validationhash
Creating table forum_authkeyuserassociation
Creating table forum_tag
Creating table forum_markedtag
Creating table forum_node_tags
Creating table forum_node
Creating table forum_noderevision
Creating table forum_nodestate
Creating table forum_action
Creating table forum_actionrepute
Creating table forum_questionsubscription
Creating table forum_vote
Creating table forum_flag
Creating table forum_badge
Creating table forum_award
Creating table forum_openidnonce
Creating table forum_openidassociation
Creating table south_migrationhistory

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): no

ここではnoを入れてファーストユーザーが管理者になるようにする。

以下、続き。

Installing index for auth.Permission model
Installing index for auth.Group_permissions model
Installing index for auth.User_user_permissions model
Installing index for auth.User_groups model
Installing index for auth.Message model
Installing index for admin.LogEntry model
Installing index for forum.UserProperty model
Installing index for forum.ValidationHash model
Installing index for forum.AuthKeyUserAssociation model
Installing index for forum.Tag model
Installing index for forum.MarkedTag model
Installing index for forum.Node_tags model
Installing index for forum.Node model
Installing index for forum.NodeRevision model
Installing index for forum.NodeState model
Installing index for forum.Action model
Installing index for forum.ActionRepute model
Installing index for forum.QuestionSubscription model
Installing index for forum.Vote model
Installing index for forum.Flag model
Installing index for forum.Award model
No fixtures found.

Synced:
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.admin
 > django.contrib.sitemaps
 > django.contrib.markup
 > forum
 > south

Not synced (use migrations):
 - 
(use ./manage.py migrate to migrate these)

データベースにデータを登録する。

osqa@OSQA:~$ sudo python manage.py migrate forum --fake

なんかエラーでてますけど、使ってないのになぁ... 放置してみる。

ImportError: No module named MySQLdb

念のため、osqaユーザーをsudoできないようにしておく。


起動してみる

ダメな予感はするけど(^^;。

osqa@OSQA:~$ django-admin runserver --settings=settings

Error: Could not import settings 'settings' (Is it on sys.path? Does it have syntax errors?): No module named settings

あらそう。

osqa@OSQA:~$ django-admin runserver --settings=./settings
Traceback (most recent call last):
  File "/usr/bin/django-admin", line 5, in <module>
    management.execute_from_command_line()
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 429, in execute_from_command_line
    utility.execute()
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 252, in fetch_command
    app_name = get_commands()[subcommand]
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 101, in get_commands
    apps = settings.INSTALLED_APPS
  File "/usr/lib/pymodules/python2.6/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line 40, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line 73, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 28, in import_module
    raise TypeError("relative imports require the 'package' argument")
TypeError: relative imports require the 'package' argument

あーあ、ダメだわ。

これはpython 2.7の問題だな。

django/utils/importlib.py

https://code.djangoproject.com/ticket/8193

https://code.djangoproject.com/browser/django/trunk/django/utils/importlib.py#L18

今の環境では無関係か。

なるほど、これかな?

osqa@OSQA:~$ cat osqa.wsgi.dist 
import os
import sys
sys.path.append('/path/to_dir_above')
sys.path.append('/path/to_dir_above/osqa')
# The first part of this module name should be identical to the directory name
# of the OSQA source.  For instance, if the full path to OSQA is
# /home/osqa/osqa-server, then the DJANGO_SETTINGS_MODULE should have a value
# of 'osqa-server.settings'.
os.environ['DJANGO_SETTINGS_MODULE'] = 'osqa.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

利用可能にして編集する。

osqa@OSQA:~$ cp osqa.wsgi.dist osqa.wsgi
osqa@OSQA:~$ vi osqa.wsgi

んでも、どう編集したらいいのだ?

これも古い書式だな。

http://wiki.osqa.net/display/docs/Installing+OSQA+on+WebFaction#InstallingOSQAonWebFaction-Step4%3ATheSettingsFile

osqa@OSQA:~$ diff -Naur osqa.wsgi.dist osqa.wsgi
--- osqa.wsgi.dist	2012-01-05 17:02:38.582120984 +0900
+++ osqa.wsgi	2012-01-05 18:09:33.665113729 +0900
@@ -1,7 +1,7 @@
 import os
 import sys
-sys.path.append('/path/to_dir_above')
-sys.path.append('/path/to_dir_above/osqa')
+sys.path.append('/home/osqa')
+#sys.path.append('/path/to_dir_above/osqa')
 # The first part of this module name should be identical to the directory name
 # of the OSQA source.  For instance, if the full path to OSQA is
 # /home/osqa/osqa-server, then the DJANGO_SETTINGS_MODULE should have a value

とりあえず、こんなんでどを?

+sys.path.append('/home/osqa/osqa')

これでは?

ダメだな。

これじゃないのか...


んなら、呼んで試すか。

osqa@OSQA:~$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import settings
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "settings.py", line 59, in <module>
    from settings_local import *
  File "settings_local.py", line 12, in <module>
    format='%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s',
  File "/usr/lib/python2.6/logging/__init__.py", line 1402, in basicConfig
    hdlr = FileHandler(filename, mode)
  File "/usr/lib/python2.6/logging/__init__.py", line 827, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python2.6/logging/__init__.py", line 846, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: '/home/osqa/log/django.osqa.log'

をや、まぢでこれ?

osqa@OSQA:~$ ls -al log/django.osqa.log 
-rw-r--r-- 1 root root 0 Jan  5 17:25 log/django.osqa.log

これか...

root@OSQA:~# chown osqa:osqa /home/osqa/log/django.osqa.log
osqa@OSQA:~$ ls -al log/django.osqa.log 
-rw-r--r-- 1 osqa osqa 0 Jan  5 17:25 log/django.osqa.log

違うな...


もっかい。

>>> import settings
Traceback (most recent call last):
  File "forum_modules/mysqlfulltext/__init__.py", line 8, in <module>
    import MySQLdb
ImportError: No module named MySQLdb

あ、これは前にも出てたな。


こっちかな?

osqa@OSQA:~$ PYTHONHOME=/home/osqa django-admin runserver --settings=settings
'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "/usr/bin/django-admin", line 2, in <module>
    from django.core import management
ImportError: No module named django.core

ダメか。

site.py編集しちゃおう。

root@OSQA:~# find / | grep site.py
/usr/share/pyshared/site.py
/usr/lib/python2.5/site-packages/site.py
/usr/lib/python2.6/site.py
/usr/lib/python2.6/site.pyc
/usr/lib/python2.6/dist-packages/site.py
/usr/lib/python2.6/dist-packages/site.pyc

有効なのは、どれだ?

/usr/lib/python2.6/dist-packages/site.py -> ../../../share/pyshared/site.py

なので、以下の2つか。

/usr/lib/python2.6/site.py

/usr/share/pyshared/site.py

ファイルの中を見ると、前者だということがわかる。

でも、マニュアルで追加するような部分はないね。

ここが無難か。

osqa@OSQA:~$ vi settings_local.py
import os.path
import sys
sys.path.append('/home/osqa')
sys.path.append('/home/osqa/osqa')

ImportError: No module named MySQLdbに戻っただけ。

起動はローカルディレクトリなんだから、参照はしているよな。

無駄足か。


観念して入れるか。

root@OSQA:~# apt-get install python-mysqldb
The following NEW packages will be installed:
  libmysqlclient16 mysql-common python-mysqldb

settingsのimportは通るようになった。

osqa@OSQA:~$ django-admin runserver --settings=./settings
(snip)
TypeError: relative imports require the 'package' argument

ダメだわ。

django/utils/importlib.pyで、import_module(name, package=None):するときに、packageが渡ってない?

入れたdjangoは2.7用に書き換えられていて、2.6だとダメなのかもしれないな。


djangoはちゃんと入っているのか?

>>> import django
>>> django.VERSION
(1, 2, 3, 'final', 0)

問題なさそう。


起動はする?

osqa@OSQA:~$ python manage.py runserver
Validating models...
0 errors found

Django version 1.2.3, using settings 'osqa.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

manage.py からの起動は大丈夫そうね。

django-adminからは、なんで動かないのかな...

[] OSQAの鯖を立ててみる(fantasy-island-0.9.0-beta3)

しょうがないので、trunkはやめて、リリースを使うことにする。

root@OSQA:~# mkdir /home/osqa_trunk
root@OSQA:~# mv /home/osqa/* /home/osqa_trunk/
root@OSQA:~# su - osqa
osqa@OSQA:~$ wget http://www.osqa.net/releases/fantasy-island-0.9.0-beta3.tar.gz
osqa@OSQA:~$ tar zxf fantasy-island-0.9.0-beta3.tar.gz 
osqa@OSQA:~$ ls -l fantasy-island-0.9.0-beta3/
total 64
drwxr-xr-x  2 osqa osqa 4096 Mar 22  2011 build
drwxr-xr-x  2 osqa osqa 4096 Jan  6 11:02 cron
drwxr-xr-x 19 osqa osqa 4096 Jan  6 11:02 forum
drwxr-xr-x 15 osqa osqa 4096 Jan  6 11:02 forum_modules
-rw-r--r--  1 osqa osqa    0 Apr 10  2010 __init__.py
-rw-r--r--  1 osqa osqa  159 Jun  3  2010 INSTALL
-rw-r--r--  1 osqa osqa  681 Apr 28  2010 LICENSE
drwxr-xr-x 10 osqa osqa 4096 Jan  6 11:02 locale
drwxr-xr-x  2 osqa osqa 4096 Jan  6 11:02 log
-rw-r--r--  1 osqa osqa  590 Jun  7  2010 manage.py
-rw-r--r--  1 osqa osqa  695 Apr 12  2010 osqa.iml
-rw-r--r--  1 osqa osqa  495 Nov 24  2010 osqa.wsgi.dist
-rw-r--r--  1 osqa osqa   26 Apr 10  2010 rmpyc
-rw-r--r--  1 osqa osqa 1413 Feb  1  2011 settings_local.py.dist
-rw-r--r--  1 osqa osqa 3801 Mar 15  2011 settings.py
drwxr-xr-x  2 osqa osqa 4096 Jan  6 11:02 tmp
-rw-r--r--  1 osqa osqa  406 Mar 12  2011 urls.py
osqa@OSQA:~$ mv fantasy-island-0.9.0-beta3/* ./
osqa@OSQA:~$ rm -r fantasy-island-0.9.0-beta3
osqa@OSQA:~$ cp osqa.wsgi.dist osqa.wsgi
osqa@OSQA:~$ vi osqa.wsgi
sys.path.append('/home/osqa')
#sys.path.append('/path/to_dir_above/osqa')
osqa@OSQA:~$ cp settings_local.py.dist settings_local.py
osqa@OSQA:~$ vi settings_local.py
DATABASE_NAME = 'osqa.db'
DATABASE_ENGINE = 'sqlite3'
APP_URL = 'http://192.168.2.104'
TIME_ZONE = 'Asia/Tokyo'
LANGUAGE_CODE = 'ja'
DJANGO_VERSION = 1.2
osqa@OSQA:~$ sudo python manage.py syncdb --all
[sudo] password for osqa: 
Syncing...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table forum_keyvalue
Creating table forum_user
Creating table forum_userproperty
Creating table forum_subscriptionsettings
Creating table forum_validationhash
Creating table forum_authkeyuserassociation
Creating table forum_tag
Creating table forum_markedtag
Creating table forum_node_tags
Creating table forum_node
Creating table forum_noderevision
Creating table forum_nodestate
Creating table forum_action
Creating table forum_actionrepute
Creating table forum_questionsubscription
Creating table forum_vote
Creating table forum_flag
Creating table forum_badge
Creating table forum_award
Creating table forum_openidnonce
Creating table forum_openidassociation
Creating table south_migrationhistory

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): no
Installing index for auth.Permission model
Installing index for auth.Group_permissions model
Installing index for auth.User_user_permissions model
Installing index for auth.User_groups model
Installing index for auth.Message model
Installing index for admin.LogEntry model
Installing index for forum.UserProperty model
Installing index for forum.ValidationHash model
Installing index for forum.AuthKeyUserAssociation model
Installing index for forum.Tag model
Installing index for forum.MarkedTag model
Installing index for forum.Node_tags model
Installing index for forum.Node model
Installing index for forum.NodeRevision model
Installing index for forum.NodeState model
Installing index for forum.Action model
Installing index for forum.ActionRepute model
Installing index for forum.QuestionSubscription model
Installing index for forum.Vote model
Installing index for forum.Flag model
Installing index for forum.Award model
No fixtures found.

Synced:
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.admin
 > django.contrib.sitemaps
 > django.contrib.markup
 > forum
 > south

Not synced (use migrations):
 - 
(use ./manage.py migrate to migrate these)
osqa@OSQA:~$ sudo python manage.py migrate forum --fake
Running migrations for forum:
 - Migrating forwards to 0048_zero_count_tags_fix.
 > forum:0001_initial
   (faked)
 > forum:0002_auto__add_likedcomment__del_field_repute_positive__del_field_repute_ne
   (faked)
 > forum:0003_repute_changes
   (faked)
 > forum:0004_auto__del_field_repute_negative__del_field_repute_positive__del_field_
   (faked)
 > forum:0005_fill_accepted_by_field
   (faked)
 > forum:0006_auto__add_node__add_field_vote_node__add_field_comment_node__add_field
   (faked)
 > forum:0007_q_and_a_to_node
   (faked)
 > forum:0008_auto__add_noderevision__del_field_vote_object_id__del_field_vote_conte
   (faked)
 > forum:0009_convert_revisions
   (faked)
 > forum:0010_auto__del_questionrevision__del_answerrevision__del_field_answer_vote_
   (faked)
 > forum:0011_auto__add_field_node_active_revision
   (faked)
 > forum:0012_set_active_revision
   (faked)
 > forum:0013_auto__del_anonymousquestion__del_anonymousanswer__add_anonymousnode
   (faked)
 > forum:0014_auto__add_field_question_accepted_answer
   (faked)
 > forum:0015_accepted_answer_changes
   (faked)
 > forum:0016_auto__del_field_question_answer_accepted__chg_field_question_node_ptr
   (faked)
 > forum:0017_auto__add_field_repute_node__add_field_repute_canceled
   (faked)
 > forum:0018_comments_to_node
   (faked)
 > forum:0019_auto__del_likedcomment__del_comment__add_field_node_abs_parent__chg_fi
   (faked)
 > forum:0020_create_absolute_parents
   (faked)
 > forum:0021_create_new_pg_fts_triggers
   (faked)
 > forum:0022_auto__add_actionrepute__add_action__add_favoritenode__del_field_node_v
   (faked)
 > forum:0023_flaten_node_inheritance_create_actions
   (faked)
 > forum:0024_auto__del_repute__del_vote__del_answer__del_flaggeditem__del_anonymous
   (faked)
 > forum:0025_auto__add_field_node_extra_action__add_field_node_deleted__add_field_n
   (faked)
 > forum:0026_reset_deleted_and_lastedited_flags
   (faked)
 > forum:0027_auto__del_activity
   (faked)
 > forum:0028_auto__add_field_action_canceled_ip__add_field_actionrepute_date
   (faked)
 > forum:0029_repute_dates
   (faked)
 > forum:0030_auto__chg_field_action_extra__chg_field_keyvalue_value
   (faked)
 > forum:0031_alter_pickle_storage
   (faked)
 > forum:0032_auto__del_field_user_hide_ignored_questions__del_field_user_questions_
   (faked)
 > forum:0033_auto__add_flag__add_vote__add_field_badge_cls__del_unique_badge_type_n
   (faked)
 > forum:0034_new_badge_and_award
   (faked)
 > forum:0035_auto__del_field_award_object_id__del_field_award_content_type__add_uni
   (faked)
 > forum:0036_auto__add_nodestate__chg_field_award_action__add_field_node_state_stri
   (faked)
 > forum:0037_fill_node_state
   (faked)
 > forum:0038_auto__del_field_node_wiki__del_field_node_deleted__del_field_node_extr
   (faked)
 > forum:0039_auto__del_field_tag_deleted__del_field_tag_deleted_by__del_field_tag_d
   (faked)
 > forum:0040_auto__chg_field_nodestate_action__add_field_node_extra
   (faked)
 > forum:0041_action_ip_fixes
   (faked)
 > forum:0042_auto__add_userproperty
   (faked)
 > forum:0043_auto__add_field_subscriptionsettings_send_digest__add_field_action_rea
   (faked)
 > forum:0044_markdown_cache_migration
   (faked)
 > forum:0045_auto__add_openidassociation__add_openidnonce__add_field_tag_created_at
   (faked)
 > forum:0046_set_tag_dates
   (faked)
 > forum:0047_auto__del_field_subscriptionsettings_questions_asked__del_field_subscr
   (faked)
 > forum:0048_zero_count_tags_fix
   (faked)
osqa@OSQA:~$ django-admin runserver --settings=./settings
Traceback (most recent call last):
  File "/usr/bin/django-admin", line 5, in <module>
    management.execute_from_command_line()
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 429, in execute_from_command_line
    utility.execute()
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 252, in fetch_command
    app_name = get_commands()[subcommand]
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 101, in get_commands
    apps = settings.INSTALLED_APPS
  File "/usr/lib/pymodules/python2.6/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line 40, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line 73, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 28, in import_module
    raise TypeError("relative imports require the 'package' argument")
TypeError: relative imports require the 'package' argument

trunkと同じエラーだな...

osqa@OSQA:~$ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 4, in <module>
    import settings # Assumed to be in the same directory.
  File "/home/osqa/settings.py", line 52, in <module>
    from settings_local import *
  File "/home/osqa/settings_local.py", line 12, in <module>
    format='%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s',
  File "/usr/lib/python2.6/logging/__init__.py", line 1402, in basicConfig
    hdlr = FileHandler(filename, mode)
  File "/usr/lib/python2.6/logging/__init__.py", line 827, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python2.6/logging/__init__.py", line 846, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: '/home/osqa/log/django.osqa.log'
osqa@OSQA:~$ sudo chown osqa:osqa log/django.osqa.log 

再度。

osqa@OSQA:~$ python manage.py runserver
Validating models...
0 errors found

Django version 1.2.3, using settings 'osqa.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

動きはするようだ。

この時点でLAN口からのアクセスはできない。

IPアドレスを指定して起動。

osqa@OSQA:~$ python manage.py runserver 192.168.2.104:8000
Validating models...
0 errors found

Django version 1.2.3, using settings 'osqa.settings'
Development server is running at http://192.168.2.104:8000/
Quit the server with CONTROL-C.

エラーが出る。

DBがreadonlyだそうだ。

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 280, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 674, in __call__
    return self.application(environ, start_response)
  File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line 230, in __call__
    self.load_middleware()
  File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 40, in load_middleware
    mod = import_module(mw_module)
  File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/osqa/forum/middleware/extended_user.py", line 4, in <module>
    from forum.views.auth import forward_suspended_user
  File "/home/osqa/forum/views/__init__.py", line 1, in <module>
    import readers
  File "/home/osqa/forum/views/readers.py", line 26, in <module>
    from forum.forms import *
  File "/home/osqa/forum/forms/__init__.py", line 1, in <module>
    from qanda import *
  File "/home/osqa/forum/forms/qanda.py", line 152, in <module>
    class AskForm(forms.Form):
  File "/home/osqa/forum/forms/qanda.py", line 154, in AskForm
    text   = QuestionEditorField()
  File "/home/osqa/forum/forms/qanda.py", line 44, in __init__
    self.required = not bool(settings.FORM_EMPTY_QUESTION_BODY)
  File "/home/osqa/forum/settings/base.py", line 22, in wrapper
    return self.value.__getattribute__(name)(*args, **kwargs)
  File "/home/osqa/forum/settings/base.py", line 63, in value
    self.save(self.default)
  File "/home/osqa/forum/settings/base.py", line 86, in save
    kv.save()
  File "/home/osqa/forum/models/base.py", line 169, in save
    super(BaseModel, self).save()
  File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 434, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 527, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
  File "/usr/lib/pymodules/python2.6/django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 1479, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 783, in execute_sql
    cursor = super(SQLInsertCompiler, self).execute_sql(None)
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 727, in execute_sql
    cursor.execute(sql, params)
  File "/usr/lib/pymodules/python2.6/django/db/backends/sqlite3/base.py", line 200, in execute
    return Database.Cursor.execute(self, query, params)
DatabaseError: attempt to write a readonly database

うーん、DB初期化をrootでやるので、権限がみんなおかしい。

このへん、ちゃんと書いておいてほしいなぁ...

妙なものをピックアップ。

drwxr-xr-x  2 root root    4096 Jan  6 11:18 cache
-rw-r--r--  1 root root     117 Jan  6 11:18 __init__.pyc
-rw-r--r--  1 root root  143360 Jan  6 11:19 osqa.db
-rw-r--r--  1 root root    1420 Jan  6 11:18 settings_local.pyc
-rw-r--r--  1 root root    4276 Jan  6 11:18 settings.pyc

pycは削除して、再生成させるとして、dbだけは変更しておく。

osqa@OSQA:~$ rm -rf *.pyc
osqa@OSQA:~$ sudo chown osqa:osqa osqa.db
osqa@OSQA:~$ sudo chown -R osqa:osqa cache

うまく表示できた。

でも、日本語化は反映されていないのね。

このままだと誰かに使わせるってわけにはいかないな...

[][] GoogleAppsアカウントでOpenID認証する

OSQAは標準でGoogleアカウントでのOpenID認証ができる。

しかし、GoogleAppsではできるのか?

Appsでは、そもそもアクセスする先が違う?

https://www.google.com/accounts/o8/site-xrds?hd=example.com

う、試してみたら、生Googleではなく、サイオスの外部認証を使っている。これはOAuth認証できなさそう。

製品名はGluegentか。

http://www.sios.com/products/cloud/service/sios_solutions.html

ブラウザで認証通った状態から、ANS-PROGにてテストしてみると、普通に認証できるみたい。

なーんだ。

[][] cacheの動作がおかしい

http://syo.cocolog-nifty.com/freely/2011/06/osqa-b56c.html

http://jira.osqa.net/browse/OSQA-677

rev.1059(2011/06/08commit)で修正。

ってことは、0.9b3では反映されていないのかな。

setup.pyの

from django.middleware.csrf import CsrfViewMiddleware

をコメントアウト。

[][] ユーザー認証を制限する

デフォルトで使えるのは以下のよう。

使用しないモジュール名をDISABLED_MODULESに書けば表示はしなくなる。

認証関係のモジュールは以下にありそう。

osqa@OSQA:~$ ls forum_modules/
akismet         facebookauth  localauth   pgfulltext      robotstxt
default_badges  __init__.py   oauthauth   project_badges  sphinxfulltext
exporter        __init__.pyc  openidauth  recaptcha       sximporter

まずは、関連しそうなものを全部消してみる。

osqa@OSQA:~$ vi settings_local.py
DISABLED_MODULES = ['facebookauth', 'oauthauth', 'openidauth', 'localauth', 'books', 'recaptcha', 'project_badges']

tempsigninが消えない。

あと、" Validate my email after I login."のチェックと、"External login services use OpenID technology, where your password always stays confidential between you and your login provider and you don't have to remember another one."のメッセージが消えない。


次にopenidauthだけ許可すると、ゾロゾロとアイコンが出てくる。

"Enter your OpenId Url"も出る。

きれいじゃないな。

openidauthをコピって書き換えるか。

osqa@OSQA:~/forum_modules$ mkdir googleaopenid
osqa@OSQA:~/forum_modules$ cp -a openidauth/* googleaopenid/
osqa@OSQA:~/forum_modules$ cd googleaopenid/
osqa@OSQA:~/forum_modules/googleaopenid$ rm *.pyc

authentication.pyの中に、各サービスに対応するクラスが並んでいる。

Google以外を削除。

DISABLED_MODULESにopenidauthを追加。

これで、とりあえず目的は達成した。


tempsigninが表示される問題は、いくつかさわってみたが、解決できていない。

[][] trunkに再挑戦

昨日から1つ上がっている。

osqa@OSQA:~$ rm -rf ./*
osqa@OSQA:~$ svn co http://svn.osqa.net/svnroot/osqa/trunk .
(snip)
Checked out revision 1219.
osqa@OSQA:~$ mkdir cache
osqa@OSQA:~$ cp settings_local.py.dist settings_local.py
osqa@OSQA:~$ vi settings_local.py
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'osqa.db',
APP_URL = 'http://192.168.2.104'
TIME_ZONE = 'Asia/Tokyo'
LANGUAGE_CODE = 'ja'
DJANGO_VERSION = 1.2
DISABLED_MODULES = ['facebookauth', 'oauthauth', 'openidauth', 'localauth', 'books', 'recaptcha', 'project_badges']
osqa@OSQA:~$ cp osqa.wsgi.dist osqa.wsgi
osqa@OSQA:~$ vi osqa.wsgi
sys.path.append('/home/osqa')
osqa@OSQA:~$ sudo python manage.py syncdb --all
osqa@OSQA:~$ sudo python manage.py migrate forum --fake
osqa@OSQA:~$ sudo chown osqa:osqa log/django.osqa.log 
osqa@OSQA:~$ rm -f *.pyc
osqa@OSQA:~$ sudo chown osqa:osqa osqa.db
osqa@OSQA:~$ django-admin runserver --settings=./settings
Traceback (most recent call last):
  File "/usr/bin/django-admin", line 5, in <module>
    management.execute_from_command_line()
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 429, in execute_from_command_line
    utility.execute()
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 252, in fetch_command
    app_name = get_commands()[subcommand]
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 101, in get_commands
    apps = settings.INSTALLED_APPS
  File "/usr/lib/pymodules/python2.6/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line 40, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line 73, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 28, in import_module
    raise TypeError("relative imports require the 'package' argument")
TypeError: relative imports require the 'package' argument

あいかわらず、エラーになるが、起動はできるの放置。

osqa@OSQA:~$ python manage.py runserver 192.168.2.104:8000
Validating models...
0 errors found

Django version 1.2.3, using settings 'osqa.settings'
Development server is running at http://192.168.2.104:8000/
Quit the server with CONTROL-C.

動いた。

日本語化されている。いしもとさん、ありがと〜!


ついでに、Google認証のみの制限も追加してみる。

osqa@OSQA:~$ mkdir forum_modules/googleaopenid
osqa@OSQA:~$ cp -a forum_modules/openidauth/* forum_modules/googleaopenid/
osqa@OSQA:~$ vi forum_modules/googleaopenid/authentication.py

GoogleAuthConsumer()とGoogleAuthContext()以外を削除。

表示は無事にできたけど、クリックしたらエラーになった... orz

[06/Jan/2012 16:11:28] "GET /account/google/signin/?validate_email=yes HTTP/1.1" 500 6502
DatabaseError: no such table: forum_openidassociation

sudo python manage.py migrate forum --fakeで、forumしか指定してないから?

easy_install python-openidしてないから?したような... したな。

もっかいsyncdb --allしたらいいとあった。

migrateはしてはいけないそう。

osqa@OSQA:~$ sudo python manage.py syncdb --all
[sudo] password for osqa: 
Syncing...
Creating table forum_openidnonce
Creating table forum_openidassociation
No fixtures found.

Synced:
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.admin
 > django.contrib.sitemaps
 > django.contrib.markup
 > forum
 > south

Not synced (use migrations):
 - 
(use ./manage.py migrate to migrate these)

できたできた。


あとやること。

  • apache経由での起動
  • トップに表示されるWebFactionの広告を削除する。
  • CCアイコンも削除する。
  • 「このサイトについて」を書き起こす。
  • 「よくある質問 」の和訳と追記。
  • 「プライバシー ポリシー」を書き起こす
  • 「最近の受賞」と「最近のタグ」を追加。
  • トップの解説を編集
  • メールの利用を可能にする:http://192.168.2.104:8000/admin/settings/email/ あたり。

[][] tempsignin問題の解決

osqa@OSQA:~$ cp forum/skins/default/templates/auth/signin.html forum/skins/default/templates/auth/signin.html.org
osqa@OSQA:~$ vi forum/skins/default/templates/auth/signin.html

103行あたりからの、このブロックを削除。

<h3 class="or_label">{% trans 'Or...' %}</h3>
<form name="signin_form" id="dummy_form_unused" class="signin_form" method="POST" action="">
    {% csrf_token %}
    <fieldset>
        {% trans 'Click' %} <a href="{% url auth_request_tempsignin %}">{% trans 'here' %}</a> {% trans "if you're having trouble signing in." %}
    </fieldset>
</form>

ANS-PROGで教えてもらった。

テンプレートは極力いじりたくなかったのだけど、これしか手がなさそう。

残念。

Save a file you edited in vim without the needed permissions

http://www.commandlinefu.com/commands/view/1204/save-a-file-you-edited-in-vim-without-the-needed-permissions

あー、これよくある。

:w !sudo tee %

[] Auto Settings

http://d.hatena.ne.jp/TAC/20120103/1325624924

アプリの起動を検出し,WifiやBluetoothなどの設定を自動で変更してくれるアプリです.

有料と無料の違いはなんだろう。

未来を開く新「はてなサービス」の作り方--危機感を持ちつつチャレンジ

http://japan.cnet.com/interview/35012688/

[][] Kindle FireのRootをとってAndroid Marketと日本語IMEを入れる

http://betageek.hatenablog.com/entry/2012/01/02/155655

How to make a Motherboard - A GIGABYTE Factory Tour Video

D

結構きれいな工場だと思うよ。

これよりヒドいとこたくさんあるもん。