PTY allocation request failed on channel 0 [ssh|CentOS]

OpenVZやXen等のVPSでは掲題の問題が発生することがある。
原因は様々だがOpenVZやXenで発生する人が多い模様。

私の場合はOpenVZの環境で発生した。
ある日自分のblogを見てみると「データベースにアクセス出来ません」とエラーが出て表示されなくなっている。
mysqldが死んだかと思いVPSにログインすると

PTY allocation request failed on channel 0

上記のエラーが出てssh経由は何も出来ない悲惨な状態。
私の場合はどうやらCentOSのupdateで発生した模様。

以下のURLを見て解決策が分かったのはいいものの、
http://www.asteriosk.gr/blog/2009/02/20/pty-allocation-request-failed-on-channel-0/

ssh接続出来ないのでホスティングの管理画面からサポートに連絡。
私はNYNOCというホスティングを使っており、HyperVMという管理画面があります。
すると「Fix Centos Dev」という実行ボタンがあるからそれを使えと指示される。
実行するとあっさり解決。この機能が管理画面に組み込まれているってこと自体そんなに発生するのだろうか。

やっとssh接続できるようになったのでmysqldをrestartしようとするも、立ち上がらず。

ログを見てみると権限のようです。

/var/lib/mysqlの中のファイル所有者と/var/run/mysqldの権限が違う模様。

まったく心当たりがありませんが、NYNOCにしてから謎の問題が多発。。

[CakePHP]How to check SQL queries in Shell and Controller

[CakePHP1.3.3]

When you debug, within Controller and Model there is often something like SQL from the instant you’ve done $this->find().

At that time, either put the function below into vendor or if you read it in bootstrap you can confirm it in SQL any time.

Incidentally, within Shell things stripped of HTML are output so it’s very convenient.

When you set Configure::write(‘debug’, 2) or higher, it works.

function sql_dump($dbConfig = 'default', $exit = true) {
    ConnectionManager::getDataSource($dbConfig)->showLog();	
    if ($exit) { exit; } 
}

How to use it is as seen below.

class SampleShell extends Shell {
    public $uses = array('Sample');
    
    public function main() {
        $this->Sample->find('all');
        sql_dump();
    }
}

How to use ftp on Ubuntu (vsftp installation)

When you upload a website, ordinarily you use sftp, but the need to create a restricted user appears, so note that way to make it in ubuntu.

Now as an example, in order to use ftp, we will create a new user called “iwaking”.

Add user.

# useradd iwaking

Setup password.

# passwd iwaking

Set up to refuse users login via ssh, allow only ftp user’s access this time.

# vim /etc/ssh/sshd_config
DenyUsers iwaking

And the ftp server is famous for vsftp, so you will install it.

# yum install vsftpd

Next, setting vsftpd.

# vi /etc/vsftpd/vsftpd.conf

I will describe only the points that have changed.

#Turn off anonymous user
anonymous_enable=NO

#Allow ASCII mode when uploading and downloading
ascii_upload_enable=YES
ascii_download_enable=YES

#Turn on chroot_list, and restrict user scope
chroot_list_enable=YES
chroot_local_user=YES
chroot_list_file=/etc/vsftpd/chroot_list

#Specify a valid user account in the user_list file
userlist_enable=YES
userlist_deny=NO

Next, edit “user_list” file. This is the user permission list.
In this scenario, a user who is given permission is “iwaking”.

# vi /etc/vsftpd/user_list
#root
#bin
#daemon
#adm
#lp
#sync
#shutdown
#halt
#mail
#news
#uucp
#operator
#games
#nobody
iwaking

There is “ftpusers” file which is a rejection list.
In this scenario, it is OK if “iwaking” is not in the list. #

# vi /etc/vsftpd/ftpusers
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

There is “chroot_list” file which is rejection list for chroot.
I do not edit this file as chroot will be done.

start vsftpd

# /etc/init.d/vsftpd restart

Configure them to run with starting up.

# chkconfig --level 345 vsftpd on

Release port 20 and 21, if you are running a firewall.

Try to login from local machine as

# chkconfig --level 345 vsftpd on
# ftp host_name
Name : iwaking
331 Please specify the password.
Password:

If login is successful, then it is done.

[CakePHP]How to make random id in Model

[CakePHP1.3.3]

Sometimes, we want to save random unique id to database. Then, please add this method.

/**
 * generate random unique id
 * 
 * @return int random unique id
 * @access public
 */
    function randomUniqueId() {
        $rand = mt_rand(1, 99999999);

        // if rand value already exist, try again
        if ($this->find('count', array('conditions' => array('Model.field_name' => $rand))) > 0) {
            return $this->randomUniqueId();
        }
        return $rand;
    }

Do you know Strength Finder?

Have you ever heard about “Strength Finder”?
It is an assessment and, by answering questioners, you will reveal your own 5 strengths from predetermined 34 strengths.
Its test result was quite correct about me and I found it is interesting.

My result is at About Page, it’s below.
Restorative
Focus
Futuristic
Self-Assurance
Deliberative

You can try it only once on the web if you buy the book below.
http://www.amazon.com/dp/159562015X/

If you are interested, please try.

At the end, I introduce all strengths shown below.

Achiever
Activator
Adaptability
Analytical
Arranger
Belief
Command
Communication
Connectedness
Competition
Context
Deliberative
Developer
Discipline
Empathy
Fairness
Focus
Futuristic
Harmony
Ideation
Inclusiveness
Individualization
Input
Intellection
Learner
Maximizer
Positivity
Restorative
Relator
Responsibility
Self-assurance
Significance
Strategic
Woo