京政办发[2003]29号

各区、县人民政府,市政府各委、办、局,各市属机构:
  为进一步优化首都人才发展环境,加快首都人才战略的实施,吸引并鼓励各类优秀人才来京创业和工作,经市政府同意,现将市人事局《关于实施北京市工作居住证制度的若干意见》转发给你们,请认真贯彻执行。

二○○三年六月十九日

关于实施北京市工作居住证制度的若干意见

(市人事局 二○○三年四月)

  为进一步优化首都人才发展环境,加快首都人才战略的实施,吸引并鼓励各类优秀人才来京创业和工作,提高城市综合竞争力,为首都率先基本实现现代化提供人才保证,现就实施北京市工作居住证制度提出以下意见:
  一、实行北京市工作居住证制度的原则是总量控制,市民待遇,柔性流动,依法管理。
  二、申请办理《北京市工作居住证》(以下简称《工作居住证》)的单位,应优先在本市行政辖区内吸纳所需各类人才。对于本市紧缺的人才,可申请办理《工作居住证》。
  三、符合城市功能定位和首都经济发展方向及产业规划要求的本市行政区域内具有法人资格的企事业单位、民办非企业单位、社会团体,外国(地区)、外埠在京设立的非法人分支机构,其聘用的人员在本市有固定住所且具备下列条件之一者,均可申请《工作居住证》:
  (一)具有2年以上工作经历并取得学士(含)以上学位的人才;
  (二)具有中级(含)以上专业技术职称或相当资格、资质的人才;
  (三)对首都经济和社会发展做出突出贡献及特殊领域、特殊行业的紧缺急需人才。
  四、持《工作居住证》在以下方面享受本市市民待遇:
  (一)其子女在京入托、入中小学就读,免收借读管理费;
  (二)可在本市行政区域内购买商品房、批准上市的已购公房和存量房,按有关规定购买经济适用住房;
  (三)按照公安部的有关规定,对符合条件的,可在本市办理因私出国商务手续;
  (四)可申请办理驾驶证或临时驾驶证以及机动车注册登记手续;
  (五)可在本市创办企业,可以企业法定代表人身份申请认定高新技术成果转化项目和科技项目资助;
  (六)可列入本市人才培养计划,并可参加本市有关人才、专家奖励项目的评选;
  (七)可参加本市专业技术职务的任职资格评定(考试)、执业(职业)资格考试、执业(职业)资格注册登记;
  (八)可参加本市基本养老保险、城镇职工基本医疗保险,并可按有关规定在本市缴存和使用住房公积金。
  五、申请办理《工作居住证》由聘用单位向其注册地所在区县人事局提出申请,报市人事局审定核发。《工作居住证》有效期为3年,有效期满可办理延期手续。
  六、《工作居住证》遗失或需变更聘用单位、居住地址等内容的,应及时向所在区县人事局申请办理挂失、补发或变更手续,并报市人事局备案。
  七、持《工作居住证》满3年的,经聘用单位考核推荐,根据其能力、业绩情况,对于符合年度人才开发目录要求的,可申请办理人才引进手续。
  八、本意见执行中的问题由市人事局会同有关部门协调解决。
  九、本意见自2003年6月30日起施行。

转自: http://zhengce.beijing.gov.cn/library/192/33/50/46/438657/79178/index.html

启动脚本的样例位于 “/usr/share/doc/initscripts-9.03.40/sysvinitfiles” in CentOS 6.5

#!/bin/sh
#
#  
#
# chkconfig:     
# description: 

### BEGIN INIT INFO
# Provides: 
# Required-Start: 
# Required-Stop: 
# Should-Start: 
# Should-Stop: 
# Default-Start: 
# Default-Stop: 
# Short-Description: 
# Description:      
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

exec="/path/to/"
prog=""
config=""

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    echo -n $"Starting $prog: "
    # if not running, start it up here, usually something like "daemon $exec"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    # stop it here, often "killproc $prog"
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?

让我们来设置一些变量:

#path to our backup script
exec="/path/to/backup"
#name of our script
prog="backup"

The file etc/init.d/functions has a set of functions like daemon and killproc which we will use in our case statement to start and stop our script.

You need to define your start and stop functions, which will basically start your script(here you can use the daemon function) and kill it (killproc). A status function is already available, all you need to do is call the function with the name of your script ($prog).

#!/bin/bash
#Author Leo G
# backup daemon

# chkconfig: 2345 20 80
#The above indicates that the script should be started in levels 2, 3, 4, and 5, #that its start priority should be 20, and that its stop priority should be 80. 
# description: syncs two files
# Source function library.
. /etc/rc.d/init.d/functions
#Define variables
exec="/path/to/backup"
prog="backup"

start() {
    [ -x $exec ] || exit 5
    echo -n $"Starting $prog: "
    # use daemon to start the service 
        daemon $exec &
    retval=$?
    echo
     return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    # use kill proc to stop the service
        killproc $prog -TERM
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        #Only if not running,  start
        rh_status_q && echo "process already started" && exit 0
        $1
        ;;
    stop)
        # Only if service is running stopt
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2

esac
exit $?

测试脚本:

[leo@linux-vps]$ ./initscript.bash start
Starting backup:  OK

测试后台运行:

[leo@linux-vps]$ ./initscript.bash status
backup (pid 2023) is running...

测试关闭

[leo@linux-vps]$ ./initscript.bash stop
Stopping backup:    OK

你可以把脚本放在 /etc/ini.d/yourscriptname, 并使它成为一个服务.

Systemd 是一个更好的方案, Systemd 从 CentOS 7 之后引入.

你可以增加脚本到 “/etc/systemd/system/backup.service”

[Unit]
Description=Backup daemon


[Service]
Type=simple
ExecStart=/path/to/backup

[Install]
WantedBy=multi-user.target

In the Unit section, I have added the description for the script.

In the service section, I have defined the executable i want to run with “ExecStart” and used “type=simple” since my process does not fork another service.

In the install section I added “WantedBy=multi-user.target”, This indicates the runlevel, multi-user.target is runlevel 3.

I recommend you read http://0pointer.de/blog/projects/systemd-for-admins-3.html for a more detailed information, and any suggestions are welcome.

Reload systemd

[leo@linux-vps]$ systemctl daemon-reload

Activate the service

[leo@linux-vps]$ systemctl start backup.service

Check the status

[leo@linux-vps]$systemctl status backup.service.

stop the service via systemctl

[leo@linux-vps]$ systemctl stop backup.service.

Enable service at boot

[leo@linux-vps]$systemctl enable backup.service.

I have also used trap as follows in the backup script itself to ensure that all child processes are killed. You may want to modify your script accordingly.

trap 'kill -HUP 0' EXIT

If you are a system administrator then I recommend you to read the Devops Wiki at https://github.com/Leo-G/DevopsWiki for a list of Linux programming and system administration guides.

Another good article that will help you on CentOS is How to Build an RPM.

As always feedback and suggestions are welcome.

source http://fedoraproject.org/wiki/Packaging:SysVInitScript
http://0pointer.de/blog/projects/systemd-for-admins-3.html

What is inotify-tools?

Inotify tools are a set of command line programs based on inotify a Linux kernel (2.6.13 or later) feature which can be used to monitor filesystem events.

Installing inotify-tools
Software versions :

inotify-tools.x86_64 3.14-1.el6
CentOS 6.5
Linux kernel 2.6.32-042stab085.20

Add the epel repo

[leo@linux-vps ~]$sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

Install inotify-tools

[leo_g@vps ~]$ sudo yum install inotify-tools

Inotify-tools has two commands

Inotifywait
This command simply blocks for inotify events, making it appropriate for use in shell scripts. It can watch any set of files and directories, and can recursively watch entire directory trees.

inotifywatch
inotifywatch collects filesystem usage statistics and outputs counts of each inotify event.

We will use inotifywait, since we do not need statistics.

inotifywait syntax

inotifywait filename

inotifywait example

[leo@linux-vps ~]$ inotifywait /tmp
Setting up watches.
Watches established.
/tmp/ MODIFY test

As you can see in the above example an event (in this case a “modify action” was performed on a file named “test” inside /tmp) triggered the output.

Now “inotifywait” by default checks for all events including if a file was opened but not written to, Since we only want “rsync” to trigger on change events like when a file is modified, we will need to specify the “-e” flag along with the list of events we want to be notified about.

[leo@linux-vps ~]$ inotifywait -m -r -e modify,attrib,close_write,move,create,delete /tmp
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
/tmp/ MODIFY a
/tmp/ CLOSE_WRITE,CLOSE a

The -m flag is for continuous monitoring as by default inotifywait will exit on the first event and -r means recursively or check through sub-directories as well.

List of inotifywait events
access
A watched file or a file within a watched directory was read from.
modify
A watched file or a file within a watched directory was written to.
attrib
The metadata of a watched file or a file within a watched directory was modified. This includes timestamps, file permissions, extended attributes etc.
close_write
A watched file or a file within a watched directory was closed, after being opened in writeable mode. This does not necessarily imply the file was written to.
close_nowrite
A watched file or a file within a watched directory was closed, after being opened in read-only mode.
close
A watched file or a file within a watched directory was closed, regardless of how it was opened. Note that this is actually implemented simply by listening for both close_write and close_nowrite, hence all close events received will be output as one of these, not CLOSE.
open
A watched file or a file within a watched directory was opened.
moved_to
A file or directory was moved into a watched directory. This event occurs even if the file is simply moved from and to the same directory.
moved_from
A file or directory was moved from a watched directory. This event occurs even if the file is simply moved from and to the same directory.
move
A file or directory was moved from or to a watched directory. Note that this is actually implemented simply by listening for both moved_to and moved_from, hence all close events received will be output as one or both of these, not MOVE.
move_self
A watched file or directory was moved. After this event, the file or directory is no longer being watched.
create
A file or directory was created within a watched directory.
delete
A file or directory within a watched directory was deleted.
delete_self
A watched file or directory was deleted. After this event the file or directory is no longer being watched. Note that this event can occur even if it is not explicitly being listened for.
unmount
The filesystem on which a watched file or directory resides was unmounted. After this event the file or directory is no longer being watched. Note that this event can occur even if it is not explicitly being listened to.

Now let’s use inotifywait with our script.

[leo@linux-vps~]$ vim inotify-example
while true #run indefinitely
do
inotifywait -r -e modify,attrib,close_write,move,create,delete /dir && /bin/bash backup-script
done

Since we want to continuously monitor changes, we use an infinite while loop and the Logic “&&” operator will ensure that our backup script is only triggered on a successful completion of the inotifywait event

转自: https://techarena51.com/index.php/inotify-tools-example/

项目中需要构建一个图片裁切服务, 使用 thumbor + openresty 进行构建, 之前使用 ubuntu 构建的时候一切都挺顺利的,这次使用的是 centos, 遇到一些问题。

最主要的问题是 openresty 嵌入的 lua 脚本需要用到 magick 库,而这个库官方没有说明如何在 centos 下进行安装, 后台一番折腾终于搞定,具体的过程如下:

安装 imageMagick 库环境(重点)

官方在说明中提到, imageMagick 库依赖 luaJit 和 imageMagick 库 或者 GraphicsMagick 库,因为要使用 wand 接口,所以需要安装 devel 包。

yum install ImageMagick ImageMagick-devel  # imagemagick c 库
yum install GraphicsMagick-devel           # GraphicsMagick c 库

yum install luarocks
luarocks install magick
ln -sf luajit-2.1.0-beta2 /usr/local/bin/luajit

建立类库连接

关键的问题在这里, 通过 luarocks 安装好 magick 类库后, openresty 目录下的 luaJit 无法找到这个包, leafo 专门写了一篇文章将这个事情: http://leafo.net/guides/customizing-the-luarocks-tree.html, 参考这篇文章,我为openresy 做了两个软连接。

首先,找一下这两个库:

find / -name "magick.so"  # magick c 库
find / -name "magick.lua" # magick lua module

其次,建立软连接:(我是根据 nginx 的报错信息, 知道 openresty 的默认类库加载路径的)

cd /opt/verynginx/openresty/luajit/share/lua/5.1
ln -s /usr/share/lua/5.1/magick  
cd /opt/verynginx/openresty/lualib
ln -s /usr/lib64/ImageMagick-6.7.2/modules-Q16/coders/magick.so 

openresty 目前使用 opm 安装组件, 很可惜 magick 这个库并不在其中。

参考