So Tired !_! 逆水行舟, 不进则退!

24Sep/14

Starting synergy automatically

Posted by Nick Xu

Starting synergy automatically

 

You can configure synergy to start automatically when the computer starts or when you log in. The steps to do that are different on each platform. Note that changing these configurations doesn't actually start or stop synergy. The changes take effect the next time you start your computer or log in.

 

Windows

 

Start synergy and click the Configure... button by the text Automatic Startup. The Auto Start dialog will pop up. If an error occurs then correct the problem and click Configure again.

On the Auto Start dialog you'll configure synergy to start or not start automatically when the computer starts or when you log in. You need Administrator access rights to start synergy automatically when the computer starts. The dialog will let you know if you have sufficient permission.

If synergy is already configured to automatically start then there will be two Uninstall buttons, at most one of which is enabled. Click the enabled button, if any, to tell synergy to not start automatically.

If synergy is not configured to start automatically then there will be two Install buttons. If you have sufficient permission to have synergy start automatically when the computer does then the Install button in the When Computer Starts box will be enabled. Click it to have synergy start for all users when the computer starts. In this case, synergy will be available during the login screen. Otherwise, click the Install button in the When You Log In box to have synergy automatically start when you log in.

 

Unix

 

Synergy requires an X server. That means a server must be running and synergy must be authorized to connect to that server. It's best to have the display manager start synergy. You'll need the necessary (probably root) permission to modify the display manager configuration files. If you don't have that permission you can start synergy after logging in via the .xsession file.

Typically, you need to edit three script files. The first file will start synergy before a user logs in, the second will kill that copy of synergy, and the third will start it again after the user logs in.

The contents of the scripts varies greatly between systems so there's no one definite place where you should insert your edits. However, these scripts often exit before reaching the bottom so put the edits near the top of the script.

The location and names of these files depend on the operating system and display manager you're using. A good guess for the location is /etc/X11. If you use kdm then try looking in /etc/kde3 or /usr/kde/version/share/config. Typical file names are:

 

xdm kdm gdm
1 xdm/Xsetup kdm/Xsetup gdm/Init/Default (*)
2 xdm/Xstartup kdm/Xstartup gdm/PostLogin/Default (*)
3 xdm/Xsession kdm/Xsession gdm/Sessions/Default (*, **)

 

*) The Default file is used if no other suitable file is found. gdm will try displayname (e.g. :0) and hostname (e.g. somehost), in that order, before and instead of Default.
**) gdm may use gdm/Xsession, xdm/Xsession or dm/Xsession if gdm/Sessions/Default doesn't exist.

For a synergy client, add the following to the first file: /usr/bin/killall synergyc sleep 1 /usr/bin/synergyc [<options>] synergy-server-hostname Of course, the path to synergyc depends on where you installed it so adjust as necessary.

Add to the second file: /usr/bin/killall synergyc sleep 1

And to the third file: /usr/bin/killall synergyc sleep 1 /usr/bin/synergyc [<options>] synergy-server-hostname Note that <options> must not include -f or --no-daemon or the script will never exit and you won't be able to log in.

The changes are the same for the synergy server except replace synergyc with synergys and use the appropriate synergys command line options. Note that the first script is run as root so synergys will look for the configuration file in root's home directory then in /etc. Make sure it exists in one of those places or use the --config config-pathname option to specify its location.

Note that some display managers (xdm and kdm, but not gdm) grab the keyboard and do not release it until the user logs in for security reasons. This prevents a synergy server from sharing the mouse and keyboard until the user logs in. It doesn't prevent a synergy client from synthesizing mouse and keyboard input, though.

If you're configuring synergy to start only after you log in then edit your .xsession file. Add just what you would add to the third file above.

 

Mac OS X

 

[By Tor Slettnes]

There are three different ways to automatically start Synergy (client or server) on Mac OS X:

 

    1. The first method involves creating a StartupItem at the system level, which is executed when the machine starts up or shuts down. This script will run in the background, and relaunch synergy as needed. 
      Pros:
      Synergy is persistent, so this allows for a multi-user setup and interactive logins.
      Cons:
      The synergy process does not have access to the clipboard of the logged-in user.

 

 

    1. The second method will launch Synergy from the LoginWindow application, once a particular user has logged in. 
      Pros:
      The synergy process inherits the $SECURITYSESSIONID environment variable, and therefore copy/paste works.
      Cons:
      Once the user logs out, synergy dies, and no remote control is possible.

 

 

  1. The third method is to launch a startup script from the "Startup Items" tab under System Preferences -> Accounts. 
    Pros:
    Does not require root (Administrator) access
    Cons:
    Once the user logs out, synergy dies, and no remote control is possible.

 

The text below describes how to implement a Synergy client using the first two methods simultaneously. This way, Synergy is always running, and the clipboard is available when someone is logged in. A Mac OS X Synergy server setup will be quite similar.

1. Create a System Level Startup Item

 

  • Open a Terminal window, and become root: $ sudo su -
  • Create a folder for this item: # mkdir -p /Library/StartupItems/Synergy
  • In this folder, create a new script file by the same name as the directory itself, Synergy. This script should contain the following text:#!/bin/sh . /etc/rc.common   run=(/usr/local/bin/synergyc -n $(hostname -s) -1 -f synergy-server)   KeepAlive () { proc=${1##*/}   while [ -x "$1" ] do if ! ps axco command | grep -q "^${proc}\$" then "$@" fi   sleep 3 done }   StartService () { ConsoleMessage "Starting Synergy" KeepAlive "${run[@]}" & }   StopService () { return 0 }   RestartService () { return 0 }   RunService "$1"

    However, replace synergy-server with the actual name or IP address of your Synergy server.

    Note that this scripts takes care not to start Synergy if another instance is currently running. This allows it to run in the background even when synergy is also started independently, e.g. from the LoginWindow application as described below.

  • Make this script executable: # chmod 755 /Library/StartupItems/Synergy/Synergy
  • In the same folder, create a file named StartupParameters.plist containing:{ Description = "Synergy Client"; Provides = ("Synergy"); Requires = ("Network"); OrderPreference = "None"; }

 

That's it! If you want to test this setup, you can run the startup script as follows:

# /Library/StartupItems/Synergy/Synergy start

Any errors, as well as output from Synergy, will be shown in your terminal window.

Next time you reboot, Synergy should start automatically.

2. Run Synergy When a User Logs In

Each time a user successfully logs in via the console, the LoginWindow application creates a unique session cookie and stores it in the environment variable $SECURITYSESSIONID. For copy and paste operations to work, Synergy needs access to this environment variable. In other words, Synergy needs to be launched (directly or indirectly) via the LoginWindow application.

However, in order to kill any synergy processes started at the system level (as described above), we need root access. Thus, launching Synergy within the User's environment (e.g. via the Startup Items tab in System Preferences -> Accounts) is not an option that work in conjunction with the method above.

Fortunately, the LoginWindow application provides a "hook" for running a custom program (as root, with the username provided as the first and only argument) once a user has authenticated, but before the user is logged in.

Unfortunately, only one such hook is available. If you have already installed a Login Hook, you may need to add the text from below to your existing script, rather than creating a new one.

 

    • Launch a Terminal window, and become root: $ sudo su -

 

 

  • Find out if a LoginHook already exists: # defaults read com.apple.loginwindow LoginHook This will either show the full path to a script or executable file, or the text: The domain/default pair of (com.apple.loginwindow, LoginHook) does not exist In the former case, you need to modify your existing script, and/or create a "superscript" which in turn calls your existing script plus the one we will create here.The rest of this text assumes that this item did not already exist, and that we will create a new script.
  • Create a folder in which we will store our custom startup script: # mkdir -p /Library/LoginWindow
  • In this folder, create a new script file (let's name it LoginHook.sh), containing the following text:#!/bin/sh prog=(/usr/local/bin/synergyc -n $(hostname -s) ip-address-of-server)   ### Stop any currently running Synergy client killall ${prog[0]##*/}   ### Start the new client exec "${prog[@]}"
  • Make this script executable: # chmod 755 /Library/LoginWindow/LoginHook.sh
  • Create a login hook to call the script you just created: # defaults write com.apple.loginwindow LoginHook /Library/LoginWindow/LoginHook.sh

 

More information on setting up login hooks can be found at Apple.

When running the Synergy client, you may need to use the IP address of the Synergy server rather than its host name. Specifically, unless you have listed the server in your local /etc/hosts file or in your local NetInfo database, name services (i.e. DNS) may not yet be available by the time you log in after power-up.synergyc will quit if it cannot resolve the server name.

(This is not an issue with the previous method, because the StartupParameters.plist file specifies that this script should not be run until "network" is available).

3. Good Luck!

Remember to look in your system log on both your server and your client(s) for clues to any problems you may have (/var/log/system.log on your OS X box, typically /var/log/syslog on Linux boxes).

20Sep/14

在windows server 2003 IIS6下安装PHP 5.3x的心得

Posted by Nick Xu

本来不打算写这份心得的,这几天为了安装wordpress,得升级一下PHP的版本,于是乎去下了个PHP5.3.8,之前不知道5.3x跟5.2x有那么大的差距,按照老方法安装了一遍,木有作用。到网上找了很多传说中的高手写的文章,前前后后重装了10几次才折腾成功!废话就不说了,来点实际的。
我只说IIS 6 + PHP5.3 ,Apache那玩意还木有研究过。

1.下载一个FastCgi For IIS6 ,到这里去下载,http://www.iis.net/expand/fastcgi
反正我下载到的文件是这样的,应该都差不多,如下图

下载完毕之后就安装,安装成功后会在C:\WINDOWS\system32\inetsrv\目录下搞出了5个文件,如下图

这个时候在IIS 6的“WEB服务扩展”里就多出了一个FastCGI Handler

2.去下载一个php-5.3.8-nts-Win32-VC9-x86.zip(不好意思,这个我忘记是在哪里下载了),然后解压到D:\PHP目录(可以解压到任意目录,这里就按照我自己的习惯来讲吧),并给IIS启动帐户或用户赋予读取和运行权限。
接着将D:\PHP目录下的所有.dll复制到C:\WINDOWS\system32下,如果有提示覆盖的,就全部覆盖吧。注:网上很多人的文章里都没写这一点,不知道是他们太高估了我的智商还是他们给忘记了,这点蛮重要。
到命令行可以输入COPY D:\PHP\*.dll C:\WINDOWS\system32\  ,省得找的麻烦。

3.注册PHP 到 FastCGI
打开 C:\WINDOWS\system32\inetsrv\fcgiext.ini文件
在[Types]下面添加以下配置(网上大部分人都说了行号,让你到哪一行附近去找,这是个误区,直接到这个文件的末尾就是,前面是没有分号的)
[Types]
php=PHP
[PHP]
ExePath=D:\PHP\php-cgi.exe
如下图所示

接下来就是修改php.ini配置文件了,D:\PHP目录下是找不到这个文件的,可以把php.ini-development复制一份,然后重命名为php.ini
打开php.ini后Ctrl+F查找
extension_dir = "./" , 把这个修改成extension_dir = "D:/PHP"
在D:下建立文件夹,并命名为tmp
查找;upload_tmp_dir =
将;upload_tmp_dir = 最前面的";"去掉
upload_tmp_dir是用来定义上传文件存放的临时路径,这里可以修改并给它定义一个绝对路径,同时需要有读、写权限。
这里我的设置为upload_tmp_dir = "D:/tmp"  (这就是我前面建立的文件夹)
找到 ;fastcgi.impersonate = 1 ,记得把前面的";"去掉
找到 ;short_open_tag = Off ,把前面的";"去掉,并把"Off"改成"On"

搜索Windows Extensions,将以下这些常用扩展前面的分号去掉

; extension=php_curl.dll
; extension=php_gd2.dll
; extension=php_ldap.dll
; extension=php_mbstring.dll
; extension=php_exif.dll
; extension=php_mysql.dll
; extension=php_mysqli.dll
; extension=php_sockets.dll
; extension=php_xmlrpc.dll

继续!

搜索;date.timezone =
去掉前面的分号,将其设置为 date.timezone = Asia/Shanghai
传说还可以设置为PRC,这个我没试过,大家有兴趣,爱折腾的可以去试一下。
如果不修改date.timezone,打开网页的时候蛮有可能提示500错误
---------------------------------------------------------------------
需要说明一下的是把D:\PHP下的php.ini文件copy到C:\WINDOWS下,然后再把D:\PHP下的php.ini删除掉(我没删除,而是改了个后缀收藏起来了)

4.配置网站
打开IIS 6管理器,在"网站"上点右键-->属性-->主目录-->配置-->添加,,操作方式就不详写了,继续上图

可执行文件路径是: C:\WINDOWS\system32\inetsrv\fcgiext.dll
运行D:\PHP\php-cgi.exe,如果能进入命令窗口并且只有光标,说明FastCGI能正常调用php-cgi,否则会提示错误,如图

OK,基本上就这些了,把IIS重启一下,命令行输入IISRESET,传说这个步骤很重要!!!
这时候可以找个php文件测试一下,常用的最简单的方式就是

<?php
    phpinfo();
>

看到类似以下效果就说明成功了

1Sep/14

浅谈MongoDB中几种不同查询方法

Posted by Nick Xu

 1.find

MongoDB使用find来进行查询.查询就是返回一个集合中文档的子集,子集合的范围从0个文档到整个集合.find的第一个参数

决定了要返回哪些文档.其形式也是一个文档,说明要查询的细节.

空的查询文档{}会匹配集合的全部内容.要是不指定查询文档,默认是{}.

如:db.users.find()返回集合users中的所有内容.

向查询文档中添加键值对,就意味着添加了查询条件.对绝大多数类型来说,整数匹配整数,布尔类型匹配布尔类型,字符串匹配

字符串.

2.指定返回的键

有时并不需要返回文档中的所有键值对返回.可以通过find或findOne的第二个参数来指定要返回的键.这样做能节省传输的

数据量,又能节省客户端解码文档的时间和内存消耗.

  1. db.users.findOne({"name":"refactor"},{"age":1,"sex":1})

只会将键为_id,age,sex的数据返回.

"_id"键总是会被返回.

也可以用第二个参数来剔除查询结果中的某个键值对.

如:

键name不会显示在返回的结果中

  1. db.users.findOne({"name":"refactor"},{"name":0})

只会将键为age,sex的数据返回."_id"键是不会返回的

  1. db.users.findOne({"name":"refactor"},{"age":1,"sex":1,"_id":0})

 3.查询条件

"$lt","$lte","$gt","$gte"分别对应<,<=,>,>=

如:

查询age >=18  <=30

db.users.find({"age":{"$gte":18,"$lte":30}})

向文档增加键birthday

 

  1. db.users.update(
  2. {"name":"refactor"},
  3. {
  4. "$set":
  5. {
  6. "birthday":new Date("1989/10/26")
  7. }
  8. }
  9. )

查询birthday日期是1990-1-1之前的人

  1. db.users.find({"birthday":{"$lt":new Date("1990/01/01")}})

使用"$ne"

查出所有name不等refactor1的文档,注意 文档中不存在键name的文档也会被查出来

  1. db.users.find({"name":{"$ne":"refactor1"}})

使用or查询

MongoDB可以使用"$in","$or"

使用"$in"

查询出pageViews为10000,20000的数据

  1. db.users.find({pageViews:{"$in":[10000,20000]}})

"$in"可以指定不同类型的条件和值,如正在将用户的ID号迁移成用户名的过程中,要做到两者兼顾的查询:

  1. db.users.find({"user_id":{"$in":[12345,"refactor"]}})

这会匹配user_id为12345和"refactor"的文档.

要是 "$in"的数组只有一个值和直接匹配这个值效果是一样的.

 

  1. db.users.find({"pageViews":{"$in":[10000]}})
  2. db.users.find({"pageViews":10000})

使用"$nin"返回与数组中所有条件都不匹配的文档

如 查出所有pageViews不等10000,20000的文档,注意 文档中不存在键pageViews的文档也会被查出来

  1. db.users.find({"pageViews":{"$nin":[10000,20000]}})

"$in"能对单个键进行or查询.

使用"$or"

 

  1. db.users.find(
  2. {
  3. "$or":
  4. [
  5. {"pageViews":{"$in":[10000,20000]}},
  6. {"url":"http://www.cnblogs.com/refactor"}
  7. ]
  8. }
  9. )

这将查询出pageViews是10000,20000或url是http://www.cnblogs.com/refactor的文档.

注意:使用普通的and查询时,要尽量将最苛刻的条件放在前面.

使用"$not"

"$not"可以用在任何条件之上.

如:

 

  1. db.users.find(
  2. {"id_num":{"mod":[5,1]}}
  3. )

这会查询出id_num取模后值为1的文档.

 

  1. db.users.find(
  2. {"id_num":{"$not":{"mod":[1,5]}}}
  3. )

4.条件句的规则

在查询中,"$lt"在内层文档,在更新中"$inc" 是外层文档的键.

条件句是内层文档的键,修改器是外层文档的键.

可对一个键应用多个条件,但一个键不能对应多个更新修改器.

5.特定于类型的查询

null可以匹配自身,而且可以匹配"不存在的"

能查出url 是"http://www.cnblogs.com/refactor",pageViews为null的文档

 

  1. db.users.find({"url":"http://www.cnblogs.com/refactor","pageViews":null})

能查出pageViews为null的文档,不存在键pageViews的也能查出来

 

  1. db.users.find({"pageViews":null})

能查出url 是"http://www.cnblogs.com/refactor",pageViews为null的文档,但不能查出不存在键pageViews的的文档
db.users.find({"url":"http://www.cnblogs.com/refactor","pageViews":{"$in":[null],"$exists":true}})

MongoDB没有"$eq"操作符,但是只有一个元素的"$in"的操作效果是一样的

如果仅仅想要匹配键值为null的文档,既要检查该键的值是否为null,还要通过"$exists"条件判断该键是不是存在.

6.正则表达式

正则表达式能够灵活有效的匹配字符串.

查找所有名包含refact或Refact的用户,使用正则表达式执行忽略大小写的匹配

 

  1. db.users.find({"name":/refact/i})

系统可以接受正则表达式标识(i),但不是一定有.现在匹配了各种大小写形式的refact.

MongoDB可以为前缀型正则表达式(如:/^refactor/)查询创建索引.所以这种类型的查询非常高效.

正则表达式也可以匹配自身

 

  1. db.users.find({"name":/refact/})

可以查出name为/refact/的文档.

7.查询数组

数组很大多数情况下可以这样理解:每一个元素都是整个键的值.

db.users.findOne({"userName":"refactor","emails":"295240648@qq.com"})能匹配到

使用"$all"

如果需要多个元素来匹配数组,就要用"$all"

db.users.insert({"userName":"refactor",emails:["295240648@qq.com","295240648@163.com","295240648@126.com"]})
db.users.insert({"userName":"refactor",emails:["295240648@qq.com","295240648@126.com","295240648@111.com"]})
db.users.insert({"userName":"refactor",emails:["295240648@126.com","295240648@163.com","295240648@111.com"]})

要找到邮箱有"295240648@163.com"又有"295240648@126.com",顺序无关紧要的文档

  1. db.users.find(
  2. {
  3. "emails":
  4. {
  5. "$all":
  6. [
  7. "295240648@163.com",
  8. "295240648@126.com"
  9. ]
  10. }
  11. }
  12. )

要是只对一个元素的数组使用"$all"就和不用"$all"是一样的,如

 

  1. db.users.find({"emails":{"$all":["295240648@126.com"]}})
  2. db.users.find({"emails":"295240648@126.com"})

效果是一样的.

也可以精确的匹配数组

  1. db.users.find({"userName":"refactor",emails:["295240648@qq.com","295240648@163.com","295240648@126.com"]})

若想查询数组指定位置的元素,需要使用key.index语法指定下标

db.users.find({"emails.1":"295240648@163.com"})

使用"$size"

"$size"可以查询指定长度的数组

查询数组长度为3的数组

db.users.find({"emails":{"$size":3}})

常见的查询是数组长度范围的查询."$size"并不能与其他查询子句组合(如:"$gt"),但是这种查询可以通过

在文档中添加一个"size"键的方式来实现.这样每一次向指定数组添加元素的时候,同时增加"size"值.原来这样

的更新:

db.users.update({"$push":{"emails":"295240648@139.com"}})

变成这样的更新:
db.users.update({"$push":{"emails":"295240648@139.com"},"$inc":{"size":1}})

这样就可以这样查询了

db.users.find({"size":{"$gt":3}})

 

使用"$slice"查询

find的第二个参数是可选的,可以指定返回那些键,"$slice"返回数组的一个子集合

返回emails数组的前两个元素

 

  1. db.users.find({"userName":"refactor"},{"emails":{"$slice":2}})

返回emails数组的后两个元素

 

  1. db.users.find({"userName":"refactor"},{"emails":{"$slice":-2}})

返回emails数组的第2个和第11个元素.如果数组不够11个,则返回第2个后面的所有元素

 

  1. db.users.find({"userName":"refactor"},{"emails":{"$slice":[1,10]}})

"$slice"默认将返回文档中的所有键.

Tagged as: , , Comments Off
   
site
site