OSX: can't open X11 display

由于苹果公司果断放弃了自己维护 X11.app,只能用 XQuatz 来替代。但是在使用 XQuartz 的过程中经常遇到一些问题,比如环境变量的设置问题。今天遇到一个问题就是,自己点击安装的 XQuartz.app 是能正常运行的,但是在终端里面使用 xeys、GrADS 等软件的时候报错:“can’’t open display”。

大部分情况下,如果正确安装了 XQuartz 但是遇到这个问题的话,很可能是配置文件没能正确地起作用。

If XQuartz were installed and you can launch it, while can’t launch it in terminal, then you may solve it by:

1
2
3
launchctl unload -w /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
launchctl load -w /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
reboot

Then it should work!.

问题解决。

SFTP: Received message too long

After a slight modification to ~/.bashrc, my sftp connection always fails with FileZilla, XFTP, and commandline sftp, but Transmit in OS X works fine.

With verbose mode of command sftp, it tells ‘Received message too long’. Carefully checked ~/.bashrc, found that an echo was added for debugging, after remove the echo sentence, sftp works perfectly again.

So, if you want your sftp works fine, please be careful with shell config files like .bashrc or .cshrc or so, especially there are echo or other messages outputed.

su 出现 This account is currently not available

su 切换用户的时候出现 “This account is currently not available” 的提示,尤其是在 /etc/init.d/ 的文件里面,运行一些服务需要切换到特定的用户,如启动 tomcat 的脚本,需要切换到 www 用户,但是 www 用户在 /etc/passwd 里面的 shell 是 /sbin/nologin,那么在启动的脚本里面:

1
su www -c /opt/tomcat7/bin/startup.sh

这一句就会导致上述的报错。

解决的办法有几种,第一,运行 vipw 修改 passwd 文件,将其 shell 项改为 /bin/bash。第二种方法则是修改这条命令,改为:

1
su -s /bin/bash www -c /opt/tomcat7/bin/startup.sh

个人更喜欢第二种方案。第一种要修改系统的安全设置,不太建议。

Mavericks apache2 issue after Server 3 removed

After remove Server.app, my apache2 on Mac OS X 10.9.2 Mavericks couldn’t start normally while everything looks OK. After carefully studied the log file through Console.app and looked into the content of /usr/sbin/apachectl, I realized that the starting process of apache in OS X is quite different than that in Linux: it uses launchctl!

So, I searched the apache launchctl config file:/System/Library/LaunchDaemons/org.apache.httpd.plist. Aha! it said:

1
2
3
4
5
6
7
8
9
10
11
12
<key>SERVER_INSTALL_PATH_PREFIX</key>
<string>/Applications/Server.app/Contents/ServerRoot</string>
......
and
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/httpd</string>
<string>-D</string>
<string>FOREGROUND</string>
<string>-f</string>
<string>/Library/Server/Web/Config/apache2/httpd_server_app.conf</string>
</array>

The key SERVER_INSTALL_PATH_PREFIX and ProgramArguments were modified by Server.app aparently. Just recover them to /usr and /etc/apache2/http.conf, there, it works again!