├── .gitignore ├── LICENSE ├── README.md ├── application └── ImageResizer.lua ├── backup └── mysql.sh ├── release ├── mvn-release ├── release └── release_static_demo.sh └── service ├── gearman ├── gerrit ├── httpd ├── icomet ├── kafka ├── memcached ├── mongod ├── nginx ├── redis ├── slapd ├── ssdb └── zkServer /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .classpath 3 | *.class 4 | *.log 5 | .DS_Store 6 | ._* 7 | *.iml 8 | .settings/ 9 | .idea/ 10 | build/ 11 | target/ 12 | log/ 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright @ 2013 Yong.Teng(http://www.buession.com/) 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | shell 2 | ===== 3 | 4 | linux 常用脚本 5 | -------------------------------------------------------------------------------- /application/ImageResizer.lua: -------------------------------------------------------------------------------- 1 | local command = "/usr/local/GraphicsMagick/bin/gm convert " .. ngx.var.request_filepath .. " -thumbnail \"" .. ngx.var.width .. "x" .. ngx.var.height .. ">\" +profile \"*\" " .. ngx.var.request_filepath .. "_" .. ngx.var.width .. "x" .. ngx.var.height .. "." .. ngx.var.ext; 2 | os.execute(command); 3 | ngx.req.set_uri(ngx.var.request_uri, true); -------------------------------------------------------------------------------- /backup/mysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | USER="backup" 6 | PASSWORD="backup" 7 | # 数据库数据目录 # 8 | DATA_DIR="/data/mysql" 9 | BIN_INDEX=$DATA_DIR"/mysql-bin.index" 10 | # 备份目录 # 11 | BACKUP_DIR="/data/backup/mysql" 12 | BACKUP_LOG="/var/log/mysql/backup.log" 13 | 14 | DATE=`date +"%Y%m%d"` 15 | TIME=`date +"%Y%m%d%H"` 16 | 17 | LOG_TIME=`date +"%Y-%m-%d %H:%M:%S"` 18 | DELETE_BINLOG_TIME="7 day" 19 | INCREMENT_INTERVAL="3 hour" 20 | 21 | note() { 22 | printf "[$LOG_TIME] note: $*\n" >> $BACKUP_LOG; 23 | } 24 | 25 | warning() { 26 | printf "[$LOG_TIME] warning: $*\n" >> $BACKUP_LOG; 27 | } 28 | 29 | error() { 30 | printf "[$LOG_TIME] error: $*\n" >> $BACKUP_LOG; 31 | exit 1; 32 | } 33 | 34 | full_backup() { 35 | local dbs=`ls -l $DATA_DIR | grep "^d" | awk -F " " '{print $9}'` 36 | 37 | for db in $dbs 38 | do 39 | local backup_dir=$BACKUP_DIR"/full/"$db 40 | local filename=$db"."$DATE 41 | local backup_file=$backup_dir"/"$filename".sql" 42 | 43 | if [ ! -d $backup_dir ] 44 | then 45 | mkdir -p $backup_dir || { error "创建数据库 $db 全量备份目录 $backup_dir 失败"; continue; } 46 | note "数据库 $db 全量备份目录 $backup_dir 不存在,创建完成"; 47 | fi 48 | 49 | note "full backup $db start ..." 50 | mysqldump --user=${USER} --password=${PASSWORD} --flush-logs --skip-lock-tables --quick $db > $backup_file || { warning "数据库 $db 备份失败"; continue; } 51 | 52 | cd $backup_dir 53 | tar -cPzf $filename".tar.gz" $filename".sql" 54 | rm -f $backup_file 55 | chown -fR mysql:mysql $backup_dir 56 | 57 | note "数据库 $db 备份成功"; 58 | note "full backup $db end." 59 | done 60 | } 61 | 62 | increment_backup() { 63 | local StartTime=`date "-d $INCREMENT_INTERVAL ago" +"%Y-%m-%d %H:%M:%S"` 64 | local DELETE_BINLOG_END_TIME=`date "-d $DELETE_BINLOG_TIME ago" +"%Y-%m-%d %H:%M:%S"` 65 | local dbs=`ls -l $DATA_DIR | grep "^d" | awk -F " " '{print $9}'` 66 | 67 | mysql -u$USER -p$PASSWORD -e "purge master logs before '$DELETE_BINLOG_END_TIME'" && note "delete $DELETE_BINLOG_TIME days before log"; 68 | 69 | filename=`cat $BIN_INDEX | awk -F "/" '{print $2}'` 70 | for i in $filename 71 | do 72 | for db in $dbs 73 | do 74 | local backup_dir=$BACKUP_DIR"/increment/"$db 75 | local filename=$db"."$TIME 76 | local backup_file=$backup_dir"/"$filename".sql" 77 | 78 | if [ ! -d $backup_dir ] 79 | then 80 | mkdir -p $backup_dir || { error "创建数据库 $db 增量备份目录 $backup_dir 失败"; continue; } 81 | note "数据库 $db 增量备份目录 $backup_dir 不存在,创建完成"; 82 | fi 83 | 84 | note "increment backup $db form time $StartTime start ..." 85 | 86 | mysqlbinlog -d $db --start-datetime="$StartTime" $DATA_DIR/$i >> $backup_file || { warning "数据库 $db 备份失败"; continue; } 87 | 88 | note "increment backup $db end." 89 | done 90 | done 91 | 92 | for db in $dbs 93 | do 94 | local backup_dir=$BACKUP_DIR"/increment/"$db 95 | local filename=$db"."$TIME 96 | local backup_file=$backup_dir"/"$filename".sql" 97 | 98 | cd $backup_dir 99 | tar -cPzf $filename".tar.gz" $filename".sql" 100 | rm -f $backup_file 101 | 102 | note "数据库 $db 备份成功"; 103 | done 104 | } 105 | 106 | case "$1" in 107 | full) 108 | full_backup 109 | ;; 110 | increment) 111 | increment_backup 112 | ;; 113 | *) 114 | exit 2 115 | ;; 116 | esac 117 | 118 | exit 1 -------------------------------------------------------------------------------- /release/mvn-release: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # description: 该文件是基于 Git 为版本管理系统的前端自动化发布脚本,也实用与如 PHP、Python 等脚本语言系统。 4 | # 该脚本主要是为了实现 javascript、css 文件的在发布时自动压缩。 5 | # 该脚本是基于 YUI Compressor (http://yui.github.io/yuicompressor/) 来实现 javascript、css 文件的压缩。 6 | # 所以,运行该脚本,需要 Java 环境支持。 7 | # 由于,在 javascript 代码书写不规范的情况下,容易导致压缩后的 javascript 不可用;所以,在生产环境发布之前,一定要经过严格的测试. 8 | # 9 | # 执行流程:(1)如果是第一次发布时,会从 Git 仓库 clone 一份代码到 PROJECT_DIR;或非第一次发布时,会切换到 PROJECT_DIR 执行 git pull 命令; 10 | # (2)将当次更新的文件,记录到 UPDATE_LIST_FILE 文件中; 11 | # (3)将 javascript 和 css 文件,压缩输出到 WEB_ROOT,非 javascript 和 css 文件或在压缩文件时出错,则 copy 到 WEB_ROOT; 12 | # (4)从 WEB_ROOT 下删除已经从 Git 仓库中删除了的文件和目录; 13 | # (5)发布完成。 14 | # 15 | # PROJECT_DIR:项目源目录,WEB_ROOT:网站根目录。之所以,不直接在 WEB_ROOT 下压缩,是为了,避免压缩后的文件与 Git 仓库中更新下来的文件产生冲突。 16 | # 17 | 18 | source /etc/profile 19 | 20 | PROJECT_NAME="" 21 | MODULE_NAME="" 22 | PROJECT_DIR="" 23 | PROJECT_TYPE="standard" 24 | WEB_ROOT="" 25 | LOG_DIR="/var/log/" 26 | 27 | RELEASE_DIR=$(cd "$(dirname "$0")"; pwd) 28 | 29 | CHARSET="UTF-8" 30 | GIT_CHAESET="UTF-8" 31 | 32 | GIT_PROTOCOL=${GIT_PROTOCOL-"ssh"} 33 | GIT_HOST=${GIT_HOST-""} 34 | GIT_PORT=${GIT_PORT-0} 35 | GIT_USER=${GIT_USER-""} 36 | BRANCH=${BRANCH-"master"} 37 | # WEB_ROOT 所属用户组 38 | GROUP=${GROUP-"nobody"} 39 | # WEB_ROOT 所属用户 40 | USER=${USER-"nobody"} 41 | 42 | OPTIONS="" 43 | 44 | note() { 45 | printf "$*\n" 1>&2; 46 | } 47 | 48 | warning() { 49 | printf "warning: $*\n" 1>&2; 50 | } 51 | 52 | error() { 53 | printf "error: $*\n" 1>&2; 54 | exit 1 55 | } 56 | 57 | git_config() { 58 | # 设置编码和文件名允许中文等字符 59 | git config --global core.quotepath false # 设置文件名允许中文等字符 60 | git config --global i18n.logoutputencoding ${GIT_CHAESET} # 设置 git log 输出时编码 61 | export LESSCHARSET=${GIT_CHAESET} 62 | } 63 | 64 | usage() { 65 | me=`basename "$0"` 66 | 67 | echo "Usage: $me {release|rollback|start|stop|restart|status|h|help} [options]" 68 | echo " -p, --project-name=项目名称 Git 项目名称" 69 | echo " -m, --module-name=模块名称 模块名称" 70 | echo " --type=类型 standard|springboot,默认值:standard" 71 | echo " --profile=profile profile" 72 | echo " --project-dir=项目路径 项目项目源码存放路径" 73 | echo " --web-root=WEB ROOT 项目关联网站根目录" 74 | echo " --charset=项目字符集 项目文件字符集" 75 | echo " --git-charset=Git 字符集 Git 终端显示字符集" 76 | echo " --git-protocol=Git 协议 Git 请求协议" 77 | echo " --git-host=Git 主机名称 Git 主机名称" 78 | echo " --git-port=Git 主机端口 Git 主机端口" 79 | echo " --git-user=Git 用户名 Git 用户名" 80 | echo " -b, --branch=分支名称 当前使用分支" 81 | echo " -g, --group=文件所属组 WEB ROOT 文件所属用户组" 82 | echo " -u, --user=文件所说用户 WEB ROOT 文件所属用户" 83 | echo " --log-dir=日志目录 log direetory" 84 | 85 | exit 1 86 | } 87 | 88 | check() { 89 | if [ -z "$PROJECT_NAME" ]; then 90 | error "project name could not be empty" 91 | fi 92 | 93 | if [ -z "$PROJECT_DIR" ]; then 94 | error "project direetory could not be empty" 95 | fi 96 | 97 | if [ -z "$WEB_ROOT" ]; then 98 | error "project web root could not be empty" 99 | fi 100 | } 101 | 102 | release() { 103 | note "Release project $PROJECT_NAME"; 104 | 105 | git_config; 106 | check; 107 | 108 | local git_dir=$PROJECT_DIR"/.git" 109 | if [ ! -d $git_dir ]; then 110 | if [ -z "$GIT_PROTOCOL" ]; then 111 | error "project git protocol could not be empty" 112 | fi 113 | 114 | if [ -z "$GIT_HOST" ]; then 115 | error "project git host could not be empty" 116 | fi 117 | 118 | if [ -z "$GIT_PORT" ]; then 119 | error "project git port could not be empty" 120 | fi 121 | 122 | if [ -z "$GIT_USER" ]; then 123 | error "project git username could not be empty" 124 | fi 125 | 126 | note "initialize project $PROJECT_NAME with source direetory $PROJECT_DIR and WEB ROOT $WEB_ROOT"; 127 | fi 128 | 129 | mkdir -p $LOG_DIR || { error "create log directory $LOG_DIR failure"; } 130 | 131 | if [ -d $PROJECT_DIR ] 132 | then 133 | cd $PROJECT_DIR 134 | git pull origin ${BRANCH} > $RELEASE_LOG || { error "git pull code failure"; } 135 | 136 | local temp=`grep 'Already up-to-date' $RELEASE_LOG` 137 | if [ "$temp" == "" ]; then 138 | sleep 1 139 | else 140 | warning "Already up-to-date"; 141 | exit 1; 142 | fi 143 | else 144 | cd `dirname "$PROJECT_DIR"` 145 | 146 | local project_git_url="$GIT_PROTOCOL://$GIT_USER@$GIT_HOST:$GIT_PORT/$PROJECT_NAME" 147 | git clone ${project_git_url} $PROJECT_DIR > $RELEASE_LOG || { error "git clone $PROJECT_NAME form $GIT_URL error"; } 148 | 149 | cd $PROJECT_DIR 150 | fi 151 | 152 | note "checkout $BRANCH branch" 153 | git checkout ${BRANCH} 154 | 155 | sleep 1 156 | 157 | chown ${USER}:${GROUP} "$WEB_ROOT" 158 | } 159 | 160 | rollback() { 161 | note "Rollback project $PROJECT_NAME"; 162 | 163 | git_config; 164 | check; 165 | 166 | if [ "$OPTIONS" == "" ]; then 167 | error "rollback options could not be empty"; 168 | else 169 | cd $PROJECT_DIR 170 | 171 | note "Checkout $BRANCH branch" 172 | git checkout ${BRANCH} 173 | 174 | sleep 1 175 | 176 | git reset --hard $OPTIONS 177 | fi 178 | } 179 | 180 | start() { 181 | echo "Starting ..." 182 | 183 | if [ ! -d "$PROJECT_DIR" ]; then 184 | error "Project directory ${PROJECT_DIR} is not exists"; 185 | fi 186 | 187 | MODULE_DIR="${PROJECT_DIR}/${MODULE_NAME}" 188 | if [ ! -d "$MODULE_DIR" ]; then 189 | error "Project module directory ${MODULE_DIR} is not exists"; 190 | fi 191 | 192 | if [ "$PROJECT_TYPE" == "standard" ]; then 193 | echo "standard" 194 | else 195 | if [ "$PROJECT_TYPE" == "springboot" ]; then 196 | cd $MODULE_DIR 197 | 198 | if [ "$profile" == "" ]; then 199 | nohup mvn spring-boot:run -Dmaven.test.skip=true > "${LOG_DIR}/runtime.log" & 200 | else 201 | nohup mvn spring-boot:run -Dmaven.test.skip=true -Dpackage.environment=$profile > "${LOG_DIR}/runtime.log" & 202 | fi 203 | 204 | tail -f "${LOG_DIR}/runtime.log" 205 | else 206 | error "Unknown project type: ${PROJECT_TYPE}" 207 | fi 208 | fi 209 | } 210 | 211 | stop() { 212 | echo "Stoping ..." 213 | 214 | pids=`getpid` 215 | echo "["$pids"]" 216 | if [ "$pids" == "" ]; then 217 | echo "Program not running."; 218 | else 219 | retval=`kill -9 ${pids}`; 220 | 221 | while [ "1" = "1" ] 222 | do 223 | echo "..."; 224 | 225 | pids=`getpid` 226 | if [ "$pids" == "" ]; then 227 | echo ""; 228 | echo "${MODULE_NAME} stoped."; 229 | 230 | return 0; 231 | fi 232 | done 233 | fi 234 | } 235 | 236 | restart() { 237 | stop 238 | 239 | sleep 1 240 | 241 | start 242 | } 243 | 244 | status() { 245 | pids=`getpid` 246 | if [ "$pids" == "" ]; then 247 | echo "Program not running."; 248 | else 249 | echo "The module ${MODULE_NAME} (pid: ${pids}) of project ${PROJECT_NAME} running."; 250 | fi 251 | } 252 | 253 | getpid() { 254 | PIDS=`ps -ef | grep 'java' | grep "${PROJECT_NAME}" | grep "${MODULE_NAME}" | grep -v '$0' | grep -v 'grep' | awk '{print $2}'`; 255 | pids=`echo ${PIDS} | sed 's/\\r/ /'`; 256 | 257 | echo "${pids}"; 258 | } 259 | 260 | ACTION=$1 261 | shift 262 | 263 | args_count=$# 264 | args_count=`expr $args_count - 1` 265 | i=0 266 | 267 | while test $i -le $args_count ; 268 | do 269 | case "$1" in 270 | -p=*) 271 | PROJECT_NAME=${1##-p=} 272 | shift 273 | i=`expr $i + 1` 274 | ;; 275 | --project-name=*) 276 | PROJECT_NAME=${1##--project-name=} 277 | shift 278 | i=`expr $i + 1` 279 | ;; 280 | -m=*) 281 | MODULE_NAME=${1##-m=} 282 | shift 283 | i=`expr $i + 1` 284 | ;; 285 | --module-name=*) 286 | MODULE_NAME=${1##--module-name=} 287 | shift 288 | i=`expr $i + 1` 289 | ;; 290 | --project-dir=*) 291 | PROJECT_DIR=${1##--project-dir=} 292 | shift 293 | i=`expr $i + 1` 294 | ;; 295 | --web-root=*) 296 | WEB_ROOT=${1##--web-root=} 297 | shift 298 | i=`expr $i + 1` 299 | ;; 300 | --type=*) 301 | PROJECT_TYPE=${1##--type=} 302 | shift 303 | i=`expr $i + 1` 304 | ;; 305 | --profile=*) 306 | PROFILE=${1##--profile=} 307 | shift 308 | i=`expr $i + 1` 309 | ;; 310 | --charset=*) 311 | CHARSET=${1##--charset=} 312 | shift 313 | i=`expr $i + 1` 314 | ;; 315 | --git-charset=*) 316 | GIT_CHAESET=${1##--git-charset=} 317 | shift 318 | i=`expr $i + 1` 319 | ;; 320 | --git-protocol=*) 321 | GIT_PROTOCOL=${1##--git-protocol=} 322 | shift 323 | i=`expr $i + 1` 324 | ;; 325 | --git-host=*) 326 | GIT_HOST=${1##--git-host=} 327 | shift 328 | i=`expr $i + 1` 329 | ;; 330 | --git-port=*) 331 | GIT_PORT=${1##--git-port=} 332 | shift 333 | i=`expr $i + 1` 334 | ;; 335 | --git-user=*) 336 | GIT_USER=${1##--git-user=} 337 | shift 338 | i=`expr $i + 1` 339 | ;; 340 | -b=*) 341 | BRANCH=${1##-b=} 342 | shift 343 | i=`expr $i + 1` 344 | ;; 345 | --branch=*) 346 | BRANCH=${1##--branch=} 347 | shift 348 | i=`expr $i + 1` 349 | ;; 350 | -g=*) 351 | GROUP=${1##-g=} 352 | shift 353 | i=`expr $i + 1` 354 | ;; 355 | --group=*) 356 | GROUP=${1##--group=} 357 | shift 358 | i=`expr $i + 1` 359 | ;; 360 | -u=*) 361 | USER=${1##-u=} 362 | shift 363 | i=`expr $i + 1` 364 | ;; 365 | --user=*) 366 | USER=${1##--user=} 367 | shift 368 | i=`expr $i + 1` 369 | ;; 370 | --log-dir=*) 371 | LOG_DIR=${1##--log-dir=} 372 | shift 373 | i=`expr $i + 1` 374 | ;; 375 | -h|--help) 376 | usage 377 | exit 0 378 | ;; 379 | *) 380 | case "$ACTION" in 381 | rollback) 382 | OPTIONS=$OPTIONS" "$1 383 | shift 384 | i=`expr $i + 1` 385 | ;; 386 | *) 387 | usage 388 | exit 0 389 | ;; 390 | esac 391 | esac 392 | done 393 | 394 | RELEASE_LOG=$LOG_DIR"/release.log" 395 | UPDATE_LIST_FILE=$LOG_DIR"/update_list.txt" 396 | ROLLBACK_LIST_FILE=$LOG_DIR"/rollback_list.txt" 397 | 398 | case "$ACTION" in 399 | release|rollback|start|stop|restart) 400 | $ACTION 401 | ;; 402 | status) 403 | $ACTION 404 | exit 0; 405 | ;; 406 | *) 407 | echo "Usage: $0 {release|rollback|start|stop|restart|status}" 408 | ;; 409 | esac 410 | 411 | exit 0 412 | -------------------------------------------------------------------------------- /release/release: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # description: 该文件是基于 Git 为版本管理系统的前端自动化发布脚本,也实用与如 PHP、Python 等脚本语言系统。 4 | # 该脚本主要是为了实现 javascript、css 文件的在发布时自动压缩。 5 | # 该脚本是基于 YUI Compressor (http://yui.github.io/yuicompressor/) 来实现 javascript、css 文件的压缩。 6 | # 所以,运行该脚本,需要 Java 环境支持。 7 | # 由于,在 javascript 代码书写不规范的情况下,容易导致压缩后的 javascript 不可用;所以,在生产环境发布之前,一定要经过严格的测试. 8 | # 9 | # 执行流程:(1)如果是第一次发布时,会从 Git 仓库 clone 一份代码到 PROJECT_DIR;或非第一次发布时,会切换到 PROJECT_DIR 执行 git pull 命令; 10 | # (2)将当次更新的文件,记录到 UPDATE_LIST_FILE 文件中; 11 | # (3)将 javascript 和 css 文件,压缩输出到 WEB_ROOT,非 javascript 和 css 文件或在压缩文件时出错,则 copy 到 WEB_ROOT; 12 | # (4)从 WEB_ROOT 下删除已经从 Git 仓库中删除了的文件和目录; 13 | # (5)发布完成。 14 | # 15 | # PROJECT_DIR:项目源目录,WEB_ROOT:网站根目录。之所以,不直接在 WEB_ROOT 下压缩,是为了,避免压缩后的文件与 Git 仓库中更新下来的文件产生冲突。 16 | # 17 | 18 | source /etc/profile 19 | 20 | PROJECT_NAME="" 21 | PROJECT_DIR="" 22 | WEB_ROOT="" 23 | LOG_DIR="/var/log/" 24 | 25 | RELEASE_DIR=$(cd "$(dirname "$0")"; pwd) 26 | YUICOMPRESSOR_JAR=${RELEASE_DIR}"/lib/yuicompressor.jar" 27 | 28 | CHARSET="UTF-8" 29 | GIT_CHAESET="UTF-8" 30 | 31 | GIT_PROTOCOL=${GIT_PROTOCOL-"ssh"} 32 | GIT_HOST=${GIT_HOST-""} 33 | GIT_PORT=${GIT_PORT-0} 34 | GIT_USER=${GIT_USER-""} 35 | BRANCH=${BRANCH-"master"} 36 | # WEB_ROOT 所属用户组 37 | GROUP=${GROUP-"nobody"} 38 | # WEB_ROOT 所属用户 39 | USER=${USER-"nobody"} 40 | 41 | OPTIONS="" 42 | 43 | note() { 44 | printf "$*\n" 1>&2; 45 | } 46 | 47 | warning() { 48 | printf "warning: $*\n" 1>&2; 49 | } 50 | 51 | error() { 52 | printf "error: $*\n" 1>&2; 53 | exit 1 54 | } 55 | 56 | usage() { 57 | me=`basename "$0"` 58 | 59 | echo "Usage: $me {release|rollback|h|help} [options]" 60 | echo " -p, --project-name=项目名称 Git 项目名称" 61 | echo " --project-dir=项目路径 项目项目源码存放路径" 62 | echo " --web-root=WEB ROOT 项目关联网站根目录" 63 | echo " --charset=项目字符集 项目文件字符集" 64 | echo " --git-charset=Git 字符集 Git 终端显示字符集" 65 | echo " --git-protocol=Git 协议 Git 请求协议" 66 | echo " --git-host=Git 主机名称 Git 主机名称" 67 | echo " --git-port=Git 主机端口 Git 主机端口" 68 | echo " --git-user=Git 用户名 Git 用户名" 69 | echo " -b, --branch=分支名称 当前使用分支" 70 | echo " -g, --group=文件所属组 WEB ROOT 文件所属用户组" 71 | echo " -u, --user=文件所说用户 WEB ROOT 文件所属用户" 72 | echo " --log-dir=日志目录 log direetory" 73 | 74 | exit 1 75 | } 76 | 77 | check() { 78 | if [ -z "$PROJECT_NAME" ]; then 79 | error "project name could not be empty" 80 | fi 81 | 82 | if [ -z "$PROJECT_DIR" ]; then 83 | error "project direetory could not be empty" 84 | fi 85 | 86 | if [ -z "$WEB_ROOT" ]; then 87 | error "project web root could not be empty" 88 | fi 89 | } 90 | 91 | update_files_init() { 92 | local arg=$1 93 | local path="$PROJECT_DIR/$arg" 94 | 95 | if [ -d "$path" ]; then 96 | local files=`ls "$path"` 97 | 98 | for file in $files 99 | do 100 | local _path="$path/$file" 101 | local temp="$file" 102 | 103 | if [ ! "$arg" == "" ]; then 104 | temp="$arg/$temp" 105 | fi 106 | 107 | if [ -d "$_path" ]; then 108 | update_files_init "$temp" 109 | else 110 | echo "$temp" >> $UPDATE_LIST_FILE 111 | fi 112 | done 113 | elif [ -f "$path" ]; then 114 | echo "$arg" >> $UPDATE_LIST_FILE 115 | else 116 | warning "$path is not exists"; 117 | fi 118 | 119 | return 0 120 | } 121 | 122 | condense() { 123 | local type=$1 124 | local source_file=$2 125 | local target_file=$3 126 | local MSG="Compression " 127 | 128 | if [ "$type" == "js" ]; then 129 | MSG=$MSG"javascript" 130 | else 131 | MSG=$MSG"css" 132 | fi 133 | MSG=$MSG" file $source_file to $target_file" 134 | 135 | command -v java >/dev/null 2>&1 136 | if [ $? == 0 ]; then 137 | java -jar ${YUICOMPRESSOR_JAR} --type ${type} --charset ${CHARSET} "$source_file" -o "$target_file" >/dev/null 2>&1 138 | if [ $? == 0 ]; then 139 | note $MSG" success" 140 | chown ${USER}:${GROUP} "$target_file" 141 | else 142 | warning "$MSG failure" 143 | note "so copy $source_file to $target_file" 144 | \cp $source_file $target_file 145 | fi 146 | else 147 | warning 'could not find command "java"' 148 | \cp $source_file $target_file 149 | fi 150 | } 151 | 152 | operate() { 153 | local file=$1 154 | 155 | if [ ! -z "$file" ]; then 156 | local source_file="$PROJECT_DIR/$file" 157 | local target_file="$WEB_ROOT/$file" 158 | local target_dir=`dirname "$target_file"` 159 | 160 | if [ -f "$source_file" ]; then 161 | chown ${USER}:${GROUP} "$source_file" 162 | 163 | mkdir -p "$target_dir" >/dev/null 2>&1 164 | if [ $? == 0 ]; then 165 | chown ${USER}:${GROUP} "$target_dir" 166 | else 167 | warning "create target directory $target_dir failure" 168 | fi 169 | 170 | if [[ "$source_file" =~ .js$ ]]; then 171 | condense "js" "$source_file" "$target_file" 172 | elif [[ "$source_file" =~ .css$ ]]; then 173 | condense "css" "$source_file" "$target_file" 174 | else 175 | note $"Copy file $source_file to $target_file" 176 | \cp "$source_file" "$target_file" 177 | fi 178 | fi 179 | fi 180 | } 181 | 182 | delete_file() { 183 | local file=$1 184 | 185 | if [ ! -z "$file" ]; then 186 | local source_dir=`dirname "$PROJECT_DIR/$file"` 187 | local target_file="$WEB_ROOT/$file" 188 | local target_dir=`dirname "$target_file"` 189 | 190 | if [ ! -d "$source_dir" ]; then 191 | if [ "`ls -A $target_dir`" = "" ]; then 192 | note "clear directory $target_dir" 193 | rm -fR "$target_dir" 194 | else 195 | warning "$target_dir contains files, so do could not delete" 196 | fi 197 | else 198 | note "Delete file $target_file" 199 | rm -f "$target_file" 200 | fi 201 | fi 202 | } 203 | 204 | release() { 205 | note "Release project $PROJECT_NAME"; 206 | 207 | check 208 | 209 | local git_dir=$PROJECT_DIR"/.git" 210 | if [ ! -d $git_dir ]; then 211 | if [ -z "$GIT_PROTOCOL" ]; then 212 | error "project git protocol could not be empty" 213 | fi 214 | 215 | if [ -z "$GIT_HOST" ]; then 216 | error "project git host could not be empty" 217 | fi 218 | 219 | if [ -z "$GIT_PORT" ]; then 220 | error "project git port could not be empty" 221 | fi 222 | 223 | if [ -z "$GIT_USER" ]; then 224 | error "project git username could not be empty" 225 | fi 226 | 227 | note "initialize project $PROJECT_NAME with source direetory $PROJECT_DIR and WEB ROOT $WEB_ROOT"; 228 | fi 229 | 230 | mkdir -p $LOG_DIR || { error "create log directory $LOG_DIR failure"; } 231 | 232 | if [ -f $UPDATE_LIST_FILE ]; then 233 | rm $UPDATE_LIST_FILE || { error "Remove $UPDATE_LIST_FILE failure"; } 234 | fi 235 | 236 | if [ -d $PROJECT_DIR ] 237 | then 238 | cd $PROJECT_DIR 239 | git pull origin ${BRANCH} > $RELEASE_LOG || { error "git pull code failure"; } 240 | 241 | local temp=`grep 'Already up-to-date' $RELEASE_LOG` 242 | if [ "$temp" == "" ]; then 243 | note "List update files"; 244 | else 245 | warning "Already up-to-date"; 246 | exit 1; 247 | fi 248 | 249 | note "checkout $BRANCH branch" 250 | git checkout ${BRANCH} 251 | sleep 1 252 | git diff-tree -r --name-status --no-commit-id ORIG_HEAD HEAD > $UPDATE_LIST_FILE 253 | 254 | while read i; 255 | do 256 | temp=`echo $i|awk -F '^A' '{gsub("\"", "", $2); gsub(/^ *| *$/, "", $2); print $2;}'`; 257 | operate "$temp"; 258 | done < $UPDATE_LIST_FILE 259 | 260 | while read i; 261 | do 262 | temp=`echo $i|awk -F '^M' '{gsub("\"", "", $2); gsub(/^ *| *$/, "", $2); print $2;}'`; 263 | operate "$temp"; 264 | done < $UPDATE_LIST_FILE 265 | 266 | while read i; 267 | do 268 | temp=`echo $i|awk -F '^D' '{gsub("\"", "", $2); gsub(/^ *| *$/, "", $2); print $2;}'`; 269 | delete_file "$temp"; 270 | done < $UPDATE_LIST_FILE 271 | else 272 | cd `dirname "$PROJECT_DIR"` 273 | 274 | local project_git_url="$GIT_PROTOCOL://$GIT_USER@$GIT_HOST:$GIT_PORT/$PROJECT_NAME" 275 | git clone ${project_git_url} $PROJECT_DIR > $RELEASE_LOG || { error "git clone $PROJECT_NAME form $GIT_URL error"; } 276 | 277 | cd $PROJECT_DIR 278 | 279 | note "Checkout $BRANCH branch" 280 | git checkout ${BRANCH} 281 | sleep 1 282 | 283 | note "List update files" 284 | 285 | update_files_init "" || { error "update files init failure"; } 286 | 287 | local files=`cat $UPDATE_LIST_FILE` 288 | 289 | for file in $files 290 | do 291 | operate "$file" 292 | done 293 | 294 | chown ${USER}:${GROUP} "$WEB_ROOT" 295 | fi 296 | } 297 | 298 | rollback() { 299 | note "Rollback project $PROJECT_NAME"; 300 | 301 | check 302 | 303 | if [ "$OPTIONS" == "" ]; then 304 | error "rollback options could not be empty"; 305 | else 306 | cd $PROJECT_DIR 307 | 308 | note "Checkout $BRANCH branch" 309 | git checkout ${BRANCH} 310 | 311 | sleep 1 312 | 313 | git reset --hard $OPTIONS 314 | git diff-tree HEAD HEAD^ -r --name-status > $ROLLBACK_LIST_FILE 315 | 316 | while read i; 317 | do 318 | temp=`echo $i|awk -F '^A' '{gsub("\"", "", $2); gsub(/^ *| *$/, "", $2); print $2;}'`; 319 | delete_file "$temp"; 320 | done < $ROLLBACK_LIST_FILE 321 | 322 | while read i; 323 | do 324 | temp=`echo $i|awk -F '^M' '{gsub("\"", "", $2); gsub(/^ *| *$/, "", $2); print $2;}'`; 325 | operate "$temp"; 326 | done < $ROLLBACK_LIST_FILE 327 | 328 | while read i; 329 | do 330 | temp=`echo $i|awk -F '^D' '{gsub("\"", "", $2); gsub(/^ *| *$/, "", $2); print $2;}'`; 331 | operate "$temp"; 332 | done < $ROLLBACK_LIST_FILE 333 | fi 334 | } 335 | 336 | ACTION=$1 337 | shift 338 | 339 | args_count=$# 340 | args_count=`expr $args_count - 1` 341 | i=0 342 | 343 | while test $i -le $args_count ; 344 | do 345 | case "$1" in 346 | -p=*) 347 | PROJECT_NAME=${1##-p=} 348 | shift 349 | i=`expr $i + 1` 350 | ;; 351 | --project-name=*) 352 | PROJECT_NAME=${1##--project-name=} 353 | shift 354 | i=`expr $i + 1` 355 | ;; 356 | --project-dir=*) 357 | PROJECT_DIR=${1##--project-dir=} 358 | shift 359 | i=`expr $i + 1` 360 | ;; 361 | --web-root=*) 362 | WEB_ROOT=${1##--web-root=} 363 | shift 364 | i=`expr $i + 1` 365 | ;; 366 | --charset=*) 367 | CHARSET=${1##--charset=} 368 | shift 369 | i=`expr $i + 1` 370 | ;; 371 | --git-charset=*) 372 | GIT_CHAESET=${1##--git-charset=} 373 | shift 374 | i=`expr $i + 1` 375 | ;; 376 | --git-protocol=*) 377 | GIT_PROTOCOL=${1##--git-protocol=} 378 | shift 379 | i=`expr $i + 1` 380 | ;; 381 | --git-host=*) 382 | GIT_HOST=${1##--git-host=} 383 | shift 384 | i=`expr $i + 1` 385 | ;; 386 | --git-port=*) 387 | GIT_PORT=${1##--git-port=} 388 | shift 389 | i=`expr $i + 1` 390 | ;; 391 | --git-user=*) 392 | GIT_USER=${1##--git-user=} 393 | shift 394 | i=`expr $i + 1` 395 | ;; 396 | -b=*) 397 | BRANCH=${1##-b=} 398 | shift 399 | i=`expr $i + 1` 400 | ;; 401 | --branch=*) 402 | BRANCH=${1##--branch=} 403 | shift 404 | i=`expr $i + 1` 405 | ;; 406 | -g=*) 407 | GROUP=${1##-g=} 408 | shift 409 | i=`expr $i + 1` 410 | ;; 411 | --group=*) 412 | GROUP=${1##--group=} 413 | shift 414 | i=`expr $i + 1` 415 | ;; 416 | -u=*) 417 | USER=${1##-u=} 418 | shift 419 | i=`expr $i + 1` 420 | ;; 421 | --user=*) 422 | USER=${1##--user=} 423 | shift 424 | i=`expr $i + 1` 425 | ;; 426 | --log-dir=*) 427 | LOG_DIR=${1##--log-dir=} 428 | shift 429 | i=`expr $i + 1` 430 | ;; 431 | -h|--help) 432 | usage 433 | exit 0 434 | ;; 435 | *) 436 | case "$ACTION" in 437 | rollback) 438 | OPTIONS=$OPTIONS" "$1 439 | shift 440 | i=`expr $i + 1` 441 | ;; 442 | *) 443 | usage 444 | exit 0 445 | ;; 446 | esac 447 | esac 448 | done 449 | 450 | # 设置编码和文件名允许中文等字符 451 | git config --global core.quotepath false # 设置文件名允许中文等字符 452 | git config --global i18n.logoutputencoding ${GIT_CHAESET} # 设置 git log 输出时编码 453 | export LESSCHARSET=${GIT_CHAESET} 454 | 455 | RELEASE_LOG=$LOG_DIR"/release.log" 456 | UPDATE_LIST_FILE=$LOG_DIR"/update_list.txt" 457 | ROLLBACK_LIST_FILE=$LOG_DIR"/rollback_list.txt" 458 | 459 | case "$ACTION" in 460 | release|rollback) 461 | $ACTION 462 | ;; 463 | *) 464 | echo "Usage: $0 {release|rollback}" 465 | ;; 466 | esac 467 | 468 | exit 0 469 | -------------------------------------------------------------------------------- /release/release_static_demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROJECT_NAME="project" 4 | DOMAIN="www.example.com" 5 | HOME_ROOT="/data/projects" 6 | SOURCE_DIR=$HOME_ROOT"/source" 7 | PROJECT_DIR=$SOURCE_DIR"/"$PROJECT_NAME 8 | WEB_ROOT="/data/htdocs/"$DOMAIN 9 | LOG_DIR=$HOME_ROOT"/logs/"$PROJECT_NAME 10 | 11 | GIT_HOST=${GIT_HOST-"git host"} 12 | GIT_PORT=${GIT_PORT-git port} 13 | GIT_USER=${GIT_USER-"git user"} 14 | BRANCH="master" 15 | 16 | CHARSET="UTF-8" 17 | GIT_CHARSET="UTF-8" 18 | 19 | GROUP="www" 20 | USER="www" 21 | 22 | RELEASE_EXCE=$(cd "$(dirname "$0")"; pwd) 23 | RELEASE_EXCE=$RELEASE_EXCE"/release" 24 | 25 | ACTION=$1 26 | shift 27 | 28 | args_count=$# 29 | args_count=`expr $args_count - 1` 30 | OPTION="" 31 | i=0 32 | 33 | while test $i -le $args_count ; 34 | do 35 | OPTION=$OPTION" "$1 36 | shift 37 | i=`expr $i + 1` 38 | done 39 | 40 | case "$ACTION" in 41 | release) 42 | bash ${RELEASE_EXCE} release -p="$PROJECT_NAME" --project-dir="$PROJECT_DIR" --branch="$BRANCH" --web-root="$WEB_ROOT" --git-protocol="ssh" --git-host="$GIT_HOST" --git-port=$GIT_PORT --git-user="$GIT_USER" --group="$GROUP" --user="$USER" --charset="$CHARSET" --git-charset="$GIT_CHARSET" --log-dir="$LOG_DIR" 43 | ;; 44 | rollback) 45 | bash ${RELEASE_EXCE} rollback -p="$PROJECT_NAME" --project-dir="$PROJECT_DIR" --branch="$BRANCH" --web-root="$WEB_ROOT" --group="$GROUP" --user="$USER" --charset="$CHARSET" --git-charset="$GIT_CHARSET" --log-dir="$LOG_DIR" $OPTION 46 | ;; 47 | *) 48 | bash ${RELEASE_EXCE} --help 49 | ;; 50 | esac 51 | 52 | exit 0 53 | -------------------------------------------------------------------------------- /service/gearman: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # gearman - this script starts and stops the gearman daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. 7 | # It allows you to do work in parallel, to load balance processing, and to call functions between languages. 8 | # It can be used in a variety of applications, from high-availability web sites to the transport of database replication events. 9 | # In other words, it is the nervous system for how distributed processing communicates. 10 | # processname: gearmand 11 | # config: /etc/sysconfig/gearmand 12 | # pidfile: /var/run/gearmand.pid 13 | 14 | # Source function library. 15 | . /etc/rc.d/init.d/functions 16 | 17 | if [ -f /etc/sysconfig/gearmand ]; then 18 | . /etc/sysconfig/gearmand 19 | fi 20 | 21 | GEARMAND_HOME="/usr/local/gearmand" 22 | gearmand=$GEARMAND_HOME"/sbin/gearmand" 23 | PROG=$(basename $gearmand) 24 | pidfile=${PIDFILE-/var/run/gearmand.pid} 25 | lockfile=${LOCKFILE-/var/lock/subsys/gearmand} 26 | logfile=${LOGFILE-/var/log/gearmand/gearmand.log} 27 | USER="daemon" 28 | PORT=4730 29 | 30 | RETVAL=0 31 | 32 | start() { 33 | [ -x $gearmand ] || exit 5 34 | echo -n $"Starting $PROG: " 35 | ${gearmand} --user ${USER} --port ${PORT} --pid-file ${pidfile} --log-file=${logfile} -d 36 | RETVAL=$? 37 | echo 38 | [ $RETVAL -eq 0 ] && touch $lockfile 39 | return $RETVAL 40 | } 41 | 42 | stop() { 43 | echo -n $"Stopping $PROG: " 44 | killproc -p ${pidfile} -d $gearmand 45 | RETVAL=$? 46 | echo 47 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 48 | } 49 | 50 | case "$1" in 51 | start) 52 | start 53 | ;; 54 | reload|restart) 55 | stop 56 | start 57 | ;; 58 | stop) 59 | stop 60 | ;; 61 | condrestart|try-restart) 62 | if status >&/dev/null; then 63 | stop 64 | start 65 | fi 66 | ;; 67 | status) 68 | status -p ${pidfile} $gearmand 69 | RETVAL=$? 70 | ;; 71 | help) 72 | $gearmand --help 73 | RETVAL=$? 74 | ;; 75 | *) 76 | echo "Usage: $0 {start|reload|restart|condrestart|try-restart|stop|status|help}" 77 | RETVAL=2 78 | ;; 79 | esac 80 | 81 | exit $RETVAL -------------------------------------------------------------------------------- /service/gerrit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # gerrit - this script starts and stops the Gerrit Code Review daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: Gerrit is a web based code review system, facilitating online code reviews for projects using the Git version control system. 7 | # processname: Gerrit Code Review 8 | # config: GERRIT_HOME/etc/gerrit.config 9 | # config: /etc/sysconfig/gerrit 10 | # pidfile: /var/run/gerrit.pid 11 | 12 | # Source function library. 13 | . /etc/rc.d/init.d/functions 14 | 15 | if [ -f /etc/sysconfig/gerrit ]; then 16 | . /etc/sysconfig/gerrit 17 | fi 18 | 19 | # Source networking configuration. 20 | . /etc/sysconfig/network 21 | 22 | # Check that networking is up. 23 | [ "$NETWORKING" = "no" ] && exit 0 24 | 25 | GERRIT_HOME="GERRIT HOME" 26 | gerrit=${GERRIT_HOME}"/bin/gerrit.sh" 27 | PROG="Gerrit Code Review" 28 | configfile=${GERRIT_HOME}"/etc/gerrit.config" 29 | pidfile=/var/run/gerrit.pid 30 | lockfile=/var/lock/subsys/gerrit 31 | 32 | RETVAL=0 33 | 34 | start() { 35 | [ -x $gerrit ] || exit 5 36 | [ -f $configfile ] || exit 6 37 | echo -n $"Starting $PROG: " 38 | ${gerrit} start 39 | RETVAL=$? 40 | echo 41 | [ $RETVAL -eq 0 ] && touch $lockfile 42 | return $RETVAL 43 | } 44 | 45 | restart() { 46 | [ -x $gerrit ] || exit 5 47 | [ -f $configfile ] || exit 6 48 | $gerrit restart 49 | echo -n $"Starting $PROG: " 50 | RETVAL=$? 51 | echo 52 | [ $RETVAL -eq 0 ] && touch $lockfile 53 | return $RETVAL 54 | } 55 | 56 | stop() { 57 | echo -n $"Stopping $PROG: " 58 | killproc -p ${pidfile} -d $gerrit 59 | RETVAL=$? 60 | echo 61 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 62 | } 63 | 64 | case "$1" in 65 | configtest) 66 | $gerrit check 67 | RETVAL=$? 68 | ;; 69 | start) 70 | start 71 | ;; 72 | reload|restart) 73 | restart 74 | ;; 75 | stop) 76 | stop 77 | ;; 78 | condrestart|try-restart) 79 | if status >&/dev/null; then 80 | stop 81 | start 82 | fi 83 | ;; 84 | status|run|supervise) 85 | $gerrit $1 86 | RETVAL=$? 87 | ;; 88 | help) 89 | $gerrit 90 | RETVAL=$? 91 | ;; 92 | *) 93 | echo "Usage: $0 {start|reload|restart|condrestart|try-restart|stop|status|help}" 94 | RETVAL=2 95 | ;; 96 | esac 97 | 98 | exit $RETVAL -------------------------------------------------------------------------------- /service/httpd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # httpd Startup script for the Apache HTTP Server 4 | # 5 | # chkconfig: - 85 15 6 | # description: The Apache HTTP Server is an efficient and extensible 7 | # server implementing the current HTTP standards. 8 | # processname: httpd 9 | # config: /usr/local/apache/conf/httpd.conf 10 | # config: /etc/sysconfig/httpd 11 | # pidfile: /var/run/httpd.pid 12 | # 13 | ### BEGIN INIT INFO 14 | # Provides: httpd 15 | # Required-Start: $local_fs $remote_fs $network $named 16 | # Required-Stop: $local_fs $remote_fs $network 17 | # Should-Start: distcache 18 | # Short-Description: start and stop Apache HTTP Server 19 | # Description: The Apache HTTP Server is an extensible server 20 | # implementing the current HTTP standards. 21 | ### END INIT INFO 22 | 23 | # Source function library. 24 | . /etc/rc.d/init.d/functions 25 | 26 | if [ -f /etc/sysconfig/httpd ]; then 27 | . /etc/sysconfig/httpd 28 | fi 29 | 30 | # Start httpd in the C locale by default. 31 | HTTPD_LANG=${HTTPD_LANG-"C"} 32 | 33 | # This will prevent initlog from swallowing up a pass-phrase prompt if 34 | # mod_ssl needs a pass-phrase from the user. 35 | INITLOG_ARGS="" 36 | 37 | # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server 38 | # with the thread-based "worker" MPM; BE WARNED that some modules may not 39 | # work correctly with a thread-based MPM; notably PHP will refuse to start. 40 | 41 | # Path to the apachectl script, server binary, and short-form for messages. 42 | APACHE_HOME="/usr/local/apache" 43 | apachectl=${APACHE_HOME}"/bin/apachectl" 44 | httpd=${HTTPD-${APACHE_HOME}"/bin/httpd"} 45 | PROG="Apache HTTP Server" 46 | pidfile=${PIDFILE-/var/run/httpd.pid} 47 | lockfile=${LOCKFILE-/var/lock/subsys/httpd} 48 | 49 | STOP_TIMEOUT=${STOP_TIMEOUT-10} 50 | RETVAL=0 51 | 52 | # The semantics of these two functions differ from the way apachectl does 53 | # things -- attempting to start while running is a failure, and shutdown 54 | # when not running is also a failure. So we just do it the way init scripts 55 | # are expected to behave here. 56 | start() { 57 | echo -n $"Starting $PROG: " 58 | LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS 59 | RETVAL=$? 60 | echo 61 | [ $RETVAL = 0 ] && touch ${lockfile} 62 | return $RETVAL 63 | } 64 | 65 | reload() { 66 | echo -n $"Reloading $PROG: " 67 | if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then 68 | RETVAL=6 69 | echo $"not reloading due to configuration syntax error" 70 | failure $"not reloading $httpd due to configuration syntax error" 71 | else 72 | # Force LSB behaviour from killproc 73 | LSB=1 killproc -p ${pidfile} $httpd -HUP 74 | RETVAL=$? 75 | if [ $RETVAL -eq 7 ]; then 76 | failure $"httpd shutdown" 77 | fi 78 | fi 79 | return $RETVAL 80 | } 81 | 82 | configtest() { 83 | $apachectl configtest 84 | RETVAL=$? 85 | return $RETVAL 86 | } 87 | 88 | # When stopping httpd, a delay (of default 10 second) is required 89 | # before SIGKILLing the httpd parent; this gives enough time for the 90 | # httpd parent to SIGKILL any errant children. 91 | stop() { 92 | echo -n $"Stopping $PROG: " 93 | killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd 94 | RETVAL=$? 95 | echo 96 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 97 | } 98 | 99 | rh_status() { 100 | status -p ${pidfile} $httpd 101 | RETVAL=$? 102 | return $RETVAL 103 | } 104 | 105 | case "$1" in 106 | start) 107 | start 108 | ;; 109 | force-reload|reload) 110 | configtest || exit 0 111 | reload 112 | ;; 113 | restart) 114 | configtest || exit 0 115 | stop 116 | start 117 | ;; 118 | stop) 119 | stop 120 | ;; 121 | status) 122 | rh_status 123 | ;; 124 | condrestart|try-restart) 125 | if rh_status >&/dev/null; then 126 | stop 127 | start 128 | fi 129 | ;; 130 | configtest) 131 | configtest 132 | ;; 133 | graceful|configtest|fullstatus|help) 134 | $apachectl $@ 135 | RETVAL=$? 136 | ;; 137 | *) 138 | echo $"Usage: $PROG {start|reload|force-reload|restart|condrestart|try-restart|stop|status|fullstatus|graceful|configtest|help}" 139 | RETVAL=2 140 | ;; 141 | esac 142 | 143 | exit $RETVAL -------------------------------------------------------------------------------- /service/icomet: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # icomet - this script starts and stops the iComet Server daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: iComet is powerfull, can be used as the messaging server of many applications, such as web chat, mobile application, desktop application etc. 7 | # processname: iComet Server 8 | # config: /usr/local/icomet/etc/icomet.conf 9 | # config: /etc/sysconfig/icomet 10 | # pidfile: /var/run/icomet.pid 11 | 12 | # Source function library. 13 | . /etc/rc.d/init.d/functions 14 | 15 | if [ -f /etc/sysconfig/icomet ]; then 16 | . /etc/sysconfig/icomet 17 | fi 18 | 19 | # Source networking configuration. 20 | . /etc/sysconfig/network 21 | 22 | # Check that networking is up. 23 | [ "$NETWORKING" = "no" ] && exit 0 24 | 25 | ICOMET_HOME="/usr/local/icomet" 26 | icomet=$ICOMET_HOME"/bin/icomet-server" 27 | PROG="iComet Server" 28 | configfile=$ICOMET_HOME"/etc/icomet.conf" 29 | pidfile=${PIDFILE-/var/run/icomet.pid} 30 | lockfile=${LOCKFILE-/var/lock/subsys/icomet} 31 | 32 | RETVAL=0 33 | 34 | start() { 35 | [ -x $icomet ] || exit 5 36 | [ -f $configfile ] || exit 6 37 | echo -n $"Starting $PROG: " 38 | ${icomet} -d ${configfile} 39 | RETVAL=$? 40 | echo 41 | [ $RETVAL -eq 0 ] && touch $lockfile 42 | return $RETVAL 43 | } 44 | 45 | stop() { 46 | echo -n $"Stopping $PROG: " 47 | killproc $icomet -QUIT 48 | RETVAL=$? 49 | echo 50 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 51 | } 52 | 53 | rh_status() { 54 | status -p ${pidfile} $icomet 55 | RETVAL=$? 56 | return $RETVAL 57 | } 58 | 59 | case "$1" in 60 | start) 61 | start 62 | ;; 63 | reload|restart) 64 | stop 65 | start 66 | ;; 67 | stop) 68 | stop 69 | ;; 70 | condrestart|try-restart) 71 | if rh_status >&/dev/null; then 72 | stop 73 | start 74 | fi 75 | ;; 76 | status) 77 | rh_status 78 | ;; 79 | help) 80 | $icomet 81 | RETVAL=$? 82 | ;; 83 | *) 84 | echo "Usage: $0 {start|reload|restart|condrestart|try-restart|stop|status|help}" 85 | RETVAL=2 86 | ;; 87 | esac 88 | 89 | exit $RETVAL 90 | -------------------------------------------------------------------------------- /service/kafka: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # kafka - this script starts and stops the Apache Kafka daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: Apache Kafka: A Distributed Streaming Platform. 7 | # processname: kafka 8 | # config: /etc/sysconfig/kafka 9 | # pidfile: /var/run/kafka.pid 10 | 11 | # Source function library. 12 | . /etc/rc.d/init.d/functions 13 | 14 | if [ -f /etc/sysconfig/kafka ]; then 15 | . /etc/sysconfig/kafka 16 | fi 17 | 18 | # Source networking configuration. 19 | . /etc/sysconfig/network 20 | 21 | # Check that networking is up. 22 | [ "$NETWORKING" = "no" ] && exit 0 23 | 24 | KAFKA_HOME="/usr/local/kafka" 25 | PROG="Apache Kafka" 26 | configfile=${KAFKA_HOME}"/config/server.properties" 27 | pidfile="/var/run/kafka.pid" 28 | lockfile="/var/lock/subsys/kafka" 29 | USER="daemon" 30 | 31 | STOP_TIMEOUT=${STOP_TIMEOUT-30} 32 | RETVAL=0 33 | 34 | start() { 35 | startShell=${KAFKA_HOME}"/bin/kafka-server-start.sh" 36 | [ -x $startShell ] || exit 5 37 | [ -f $configfile ] || exit 6 38 | 39 | echo -n $"Starting $PROG: " 40 | source /etc/profile 41 | ${startShell} -daemon ${configfile} 42 | RETVAL=$? 43 | 44 | echo 45 | [ $RETVAL -eq 0 ] && touch $lockfile 46 | return $RETVAL 47 | } 48 | 49 | status() { 50 | pid=`ps aux|grep "${KAFKA_HOME}"|grep -v 'grep'|awk '{print $2}'` 51 | 52 | if [ "$pid" == "" ]; then 53 | echo -n $"$PROG not running" 54 | else 55 | echo -n $"$PROG (pid $pid) running" 56 | fi 57 | RETVAL=$? 58 | echo "" 59 | return $RETVAL 60 | } 61 | 62 | stop() { 63 | stopShell=${KAFKA_HOME}"/bin/kafka-server-stop.sh" 64 | [ -x $startShell ] || exit 5 65 | echo -n $"Stopping $PROG: " 66 | ${stopShell} 67 | RETVAL=$? 68 | echo 69 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 70 | } 71 | 72 | case "$1" in 73 | start) 74 | start 75 | ;; 76 | reload|restart) 77 | stop 78 | start 79 | ;; 80 | stop) 81 | stop 82 | ;; 83 | condrestart|try-restart) 84 | if status >&/dev/null; then 85 | stop 86 | start 87 | fi 88 | ;; 89 | status) 90 | status 91 | RETVAL=$? 92 | ;; 93 | help) 94 | $mongod --help 95 | RETVAL=$? 96 | ;; 97 | *) 98 | echo "Usage: $0 {start|reload|restart|condrestart|try-restart|stop|status|help}" 99 | RETVAL=2 100 | ;; 101 | esac 102 | 103 | exit $RETVAL -------------------------------------------------------------------------------- /service/memcached: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # memcached - this script starts and stops the memcached daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, 7 | # API calls, or page rendering. 8 | # processname: memcached 9 | # config: /etc/sysconfig/memcached 10 | # pidfile: /var/run/memcached.pid 11 | 12 | # Source function library. 13 | . /etc/rc.d/init.d/functions 14 | 15 | if [ -f /etc/sysconfig/memcached ]; then 16 | . /etc/sysconfig/memcached 17 | fi 18 | 19 | # Source networking configuration. 20 | . /etc/sysconfig/network 21 | 22 | # Check that networking is up. 23 | [ "$NETWORKING" = "no" ] && exit 0 24 | 25 | MEMCACHED_HOME="/usr/local/memcached" 26 | memcached=$MEMCACHED_HOME"/bin/memcached" 27 | PROG=$(basename $memcached) 28 | pidfile=${PIDFILE-/var/run/memcached.pid} 29 | lockfile=${LOCKFILE-/var/lock/subsys/memcached} 30 | USER="daemon" 31 | PORT=11211 32 | MAX_MEMORY=1024 33 | MAX_CONNEXTIONS=1024 34 | MAX_REQUESTS=100 35 | 36 | RETVAL=0 37 | 38 | start() { 39 | [ -x $memcached ] || exit 5 40 | echo -n $"Starting $PROG: " 41 | ${memcached} -p ${PORT} -u ${USER} -m ${MAX_MEMORY} -c ${MAX_CONNEXTIONS} -R ${MAX_REQUESTS} -P ${pidfile} -d start 42 | RETVAL=$? 43 | echo 44 | [ $RETVAL -eq 0 ] && touch $lockfile 45 | return $RETVAL 46 | } 47 | 48 | stop() { 49 | echo -n $"Stopping $PROG: " 50 | killproc $memcached -QUIT 51 | RETVAL=$? 52 | echo 53 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 54 | } 55 | 56 | case "$1" in 57 | start) 58 | start 59 | ;; 60 | reload|restart) 61 | stop 62 | start 63 | ;; 64 | stop) 65 | stop 66 | ;; 67 | condrestart|try-restart) 68 | if status >&/dev/null; then 69 | stop 70 | start 71 | fi 72 | ;; 73 | status) 74 | status -p ${pidfile} $memcached 75 | RETVAL=$? 76 | ;; 77 | help) 78 | $memcached --help 79 | RETVAL=$? 80 | ;; 81 | *) 82 | echo $"Usage: $PROG {start|reload|restart|condrestart|try-restart|stop|status|help}" 83 | RETVAL=2 84 | ;; 85 | esac 86 | 87 | exit $RETVAL -------------------------------------------------------------------------------- /service/mongod: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # mongod - this script starts and stops the MongoDB daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: MongoDB (from "humongous") is an open-source document database, and the leading NoSQL database. 7 | # processname: mongod 8 | # config: /etc/sysconfig/mongod 9 | # pidfile: /var/run/mongod.pid 10 | 11 | # Source function library. 12 | . /etc/rc.d/init.d/functions 13 | 14 | if [ -f /etc/sysconfig/mongod ]; then 15 | . /etc/sysconfig/mongod 16 | fi 17 | 18 | # Source networking configuration. 19 | . /etc/sysconfig/network 20 | 21 | # Check that networking is up. 22 | [ "$NETWORKING" = "no" ] && exit 0 23 | 24 | MONGODB_HOME="/usr/local/MongoDB" 25 | mongod=${MONGODB_HOME}"/bin/mongod" 26 | PROG="MongoDB" 27 | configfile=${MONGODB_HOME}"/etc/mongod.conf" 28 | pidfile="/var/run/mongod.pid" 29 | lockfile="/var/lock/subsys/mongod" 30 | USER="daemon" 31 | 32 | STOP_TIMEOUT=${STOP_TIMEOUT-30} 33 | RETVAL=0 34 | 35 | # Handle NUMA access to CPUs (SERVER-3574) 36 | # This verifies the existence of numactl as well as testing that the command works 37 | NUMACTL_ARGS="--interleave=all" 38 | if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null 39 | then 40 | NUMACTL="numactl $NUMACTL_ARGS" 41 | else 42 | NUMACTL="" 43 | fi 44 | 45 | start() { 46 | [ -x $mongod ] || exit 5 47 | [ -f $configfile ] || exit 6 48 | echo -n $"Starting $PROG: " 49 | daemon --user ${USER} ${NUMACTL} ${mongod} -f ${configfile} 50 | RETVAL=$? 51 | echo 52 | [ $RETVAL -eq 0 ] && touch $lockfile 53 | return $RETVAL 54 | } 55 | 56 | stop() { 57 | echo -n $"Stopping $PROG: " 58 | killproc -p ${pidfile} -d ${STOP_TIMEOUT} $mongod 59 | RETVAL=$? 60 | echo 61 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 62 | } 63 | 64 | case "$1" in 65 | start) 66 | start 67 | ;; 68 | reload|restart) 69 | stop 70 | start 71 | ;; 72 | stop) 73 | stop 74 | ;; 75 | condrestart|try-restart) 76 | if status >&/dev/null; then 77 | stop 78 | start 79 | fi 80 | ;; 81 | status) 82 | status -p ${pidfile} $mongod 83 | RETVAL=$? 84 | ;; 85 | help) 86 | $mongod --help 87 | RETVAL=$? 88 | ;; 89 | *) 90 | echo "Usage: $0 {start|reload|restart|condrestart|try-restart|stop|status|help}" 91 | RETVAL=2 92 | ;; 93 | esac 94 | 95 | exit $RETVAL -------------------------------------------------------------------------------- /service/nginx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # nginx - this script starts and stops the nginx daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: Nginx is an HTTP(S) server, HTTP(S) reverse 7 | # proxy and IMAP/POP3 proxy server 8 | # processname: nginx 9 | # config: /usr/local/Tengine/config/nginx.conf 10 | # config: /etc/sysconfig/nginx 11 | # pidfile: /var/run/nginx.pid 12 | 13 | # Source function library. 14 | . /etc/rc.d/init.d/functions 15 | 16 | if [ -f /etc/sysconfig/nginx ]; then 17 | . /etc/sysconfig/nginx 18 | fi 19 | 20 | # Source networking configuration. 21 | . /etc/sysconfig/network 22 | 23 | # Check that networking is up. 24 | [ "$NETWORKING" = "no" ] && exit 0 25 | 26 | NGINX_HOME="/usr/local/Tengine" 27 | nginx=$NGINX_HOME"/sbin/nginx" 28 | PROG=$(basename $NGINX_HOME) 29 | configfile=$NGINX_HOME"/conf/nginx.conf" 30 | pidfile=${PIDFILE-/var/run/nginx.pid} 31 | lockfile=${LOCKFILE-/var/lock/subsys/nginx} 32 | 33 | RETVAL=0 34 | 35 | start() { 36 | [ -x $nginx ] || exit 5 37 | [ -f $configfile ] || exit 6 38 | echo -n $"Starting $PROG: " 39 | daemon $nginx -c $configfile 40 | RETVAL=$? 41 | echo 42 | [ $RETVAL -eq 0 ] && touch $lockfile 43 | return $RETVAL 44 | } 45 | 46 | reload() { 47 | configtest || return $? 48 | echo -n $"Reloading $PROG: " 49 | killproc $nginx -HUP 50 | RETVAL=$? 51 | return $RETVAL 52 | } 53 | 54 | force_reload() { 55 | restart 56 | RETVAL=$? 57 | return $RETVAL 58 | } 59 | 60 | restart() { 61 | configtest || return $? 62 | stop 63 | start 64 | } 65 | 66 | stop() { 67 | echo -n $"Stopping $PROG: " 68 | killproc $PROG -QUIT 69 | RETVAL=$? 70 | echo 71 | [ $RETVAL -eq 0 ] && rm -f $lockfile 72 | return $RETVAL 73 | killall -9 nginx 74 | } 75 | 76 | configtest() { 77 | $nginx -t -c $configfile 78 | RETVAL=$? 79 | return $RETVAL 80 | } 81 | 82 | rh_status() { 83 | status -p ${pidfile} $nginx 84 | RETVAL=$? 85 | return $RETVAL 86 | } 87 | 88 | rh_status_q() { 89 | rh_status >/dev/null 2>&1 90 | RETVAL=$? 91 | return $RETVAL 92 | } 93 | 94 | case "$1" in 95 | configtest) 96 | configtest 97 | ;; 98 | start) 99 | rh_status_q && exit 0 100 | start 101 | ;; 102 | reload) 103 | rh_status_q || exit 7 104 | reload 105 | ;; 106 | force-reload) 107 | force_reload 108 | ;; 109 | restart) 110 | restart 111 | ;; 112 | condrestart|try-restart) 113 | rh_status_q || exit 0 114 | ;; 115 | stop) 116 | rh_status_q || exit 0 117 | stop 118 | ;; 119 | status) 120 | rh_status 121 | ;; 122 | help) 123 | $nginx -h 124 | RETVAL=$? 125 | ;; 126 | *) 127 | echo $"Usage: $0 {start|reload|force-reload|restart|condrestart|try-restart|stop|status|configtest|help}" 128 | RETVAL=2 129 | ;; 130 | esac 131 | 132 | exit $RETVAL -------------------------------------------------------------------------------- /service/redis: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Redis - this script starts and stops the redis server daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: Redis is an open source, BSD licensed, advanced key-value cache and store. 7 | # It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs. 8 | # processname: Redis Server 9 | # config: /etc/sysconfig/redis 10 | # pidfile: /var/run/redis.pid 11 | 12 | # Source function library. 13 | . /etc/rc.d/init.d/functions 14 | 15 | if [ -f /etc/sysconfig/redisd ]; then 16 | . /etc/sysconfig/redisd 17 | fi 18 | 19 | # Source networking configuration. 20 | . /etc/sysconfig/network 21 | 22 | # Check that networking is up. 23 | [ "$NETWORKING" = "no" ] && exit 0 24 | 25 | REDIS_HOME="/usr/local/Redis" 26 | redisd=$REDIS_HOME"/bin/redis-server" 27 | PROG="Redis Server" 28 | configfile=${REDIS_HOME}"/etc/redis.conf" 29 | pidfile=${PIDFILE-/var/run/redis.pid} 30 | lockfile=${LOCKFILE-/var/lock/subsys/redis} 31 | 32 | RETVAL=0 33 | 34 | start() { 35 | [ -x $redisd ] || exit 5 36 | [ -f $configfile ] || exit 6 37 | echo -n $"Starting $PROG: " 38 | daemon $redisd $configfile 39 | RETVAL=$? 40 | echo 41 | [ $RETVAL -eq 0 ] && touch $lockfile 42 | return $RETVAL 43 | } 44 | 45 | stop() { 46 | echo -n $"Stopping $PROG: " 47 | killproc $redisd -QUIT 48 | RETVAL=$? 49 | echo 50 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 51 | } 52 | 53 | case "$1" in 54 | start) 55 | start 56 | ;; 57 | reload|restart) 58 | stop 59 | start 60 | ;; 61 | stop) 62 | stop 63 | ;; 64 | condrestart|try-restart) 65 | if status >&/dev/null; then 66 | stop 67 | start 68 | fi 69 | ;; 70 | status) 71 | status -p ${pidfile} $redisd 72 | RETVAL=$? 73 | ;; 74 | help) 75 | $redisd --help 76 | RETVAL=$? 77 | ;; 78 | *) 79 | echo $"Usage: $PROG {start|reload|restart|condrestart|try-restart|stop|status|help}" 80 | RETVAL=2 81 | ;; 82 | esac 83 | 84 | exit $RETVAL 85 | -------------------------------------------------------------------------------- /service/slapd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # slapd - this script starts and stops the LDAP daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: OpenLDAP Software is an open source implementation of the Lightweight Directory Access Protocol 7 | # processname: slapd 8 | # config: /usr/local/OpenLDAP/etc/openldap/slapd.conf 9 | # config: /etc/sysconfig/slapd 10 | # pidfile: /var/run/slapd.pid 11 | 12 | # Source function library. 13 | . /etc/rc.d/init.d/functions 14 | 15 | if [ -f /etc/sysconfig/slapd ]; then 16 | . /etc/sysconfig/slapd 17 | fi 18 | 19 | LDAP_HOME="/usr/local/OpenLDAP" 20 | slapd=$LDAP_HOME"/libexec/slapd" 21 | PROG=$(basename $LDAP_HOME) 22 | configfile=$LDAP_HOME"/etc/openldap/slapd.conf" 23 | pidfile=${PIDFILE-/var/run/slapd.pid} 24 | lockfile=${LOCKFILE-/var/lock/subsys/slapd} 25 | 26 | SERVICE_NAME="OpenLDAP Serever" 27 | GROUP="root" 28 | USER="root" 29 | 30 | RETVAL=0 31 | 32 | configtest() { 33 | [ -x $slapd ] || exit 5 34 | $slapd -T test 35 | RETVAL=$? 36 | return $RETVAL 37 | } 38 | 39 | start() { 40 | [ -x $slapd ] || exit 5 41 | [ -f $configfile ] || exit 6 42 | configtest || return $? 43 | echo -n $"Starting $PROG: " 44 | $slapd -4 -n "${SERVICE_NAME}" -g ${GROUP} -u ${USER} -f ${configfile} 45 | RETVAL=$? 46 | echo 47 | [ $RETVAL -eq 0 ] && touch $lockfile 48 | return $RETVAL 49 | } 50 | 51 | restart() { 52 | stop 53 | start 54 | } 55 | 56 | rh_status() { 57 | status -p ${pidfile} $slapd 58 | RETVAL=$? 59 | return $RETVAL 60 | } 61 | 62 | rh_status_q() { 63 | rh_status >/dev/null 2>&1 64 | RETVAL=$? 65 | return $RETVAL 66 | } 67 | 68 | stop() { 69 | echo -n $"Stopping $PROG: " 70 | killproc $slapd -QUIT 71 | RETVAL=$? 72 | echo 73 | [ $RETVAL -eq 0 ] && rm -f $lockfile 74 | return $RETVAL 75 | } 76 | 77 | case "$1" in 78 | configtest) 79 | configtest && exit 0 80 | ;; 81 | start) 82 | rh_status_q && exit 0 83 | start 84 | ;; 85 | reload|restart) 86 | rh_status_q || exit 7 87 | restart 88 | ;; 89 | stop) 90 | rh_status_q || exit 0 91 | stop 92 | ;; 93 | status) 94 | rh_status 95 | ;; 96 | *) 97 | echo $"Usage: $0 {start|reload|restart|stop|status}" 98 | RETVAL=2 99 | ;; 100 | esac 101 | 102 | exit $RETVAL -------------------------------------------------------------------------------- /service/ssdb: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # ssdb - this script starts and stops the SSDB Server daemon 4 | # 5 | # chkconfig: - 85 15 6 | # description: SSDB is a high performace key-value(key-string, key-zset, key-hashmap) NoSQL database, an alternative to Redis. 7 | # processname: SSDB Server 8 | # config: /usr/local/ssdb/etc/ssdb.conf 9 | # config: /etc/sysconfig/ssdb 10 | # pidfile: /var/run/mongod.pid 11 | 12 | # Source function library. 13 | . /etc/rc.d/init.d/functions 14 | 15 | if [ -f /etc/sysconfig/mongod ]; then 16 | . /etc/sysconfig/mongod 17 | fi 18 | 19 | # Source networking configuration. 20 | . /etc/sysconfig/network 21 | 22 | # Check that networking is up. 23 | [ "$NETWORKING" = "no" ] && exit 0 24 | 25 | SSDB_HOME="/usr/local/ssdb" 26 | ssdb=${SSDB_HOME}"/ssdb-server" 27 | PROG="SSDB" 28 | configfile=${SSDB_HOME}"/etc/ssdb.conf" 29 | pidfile=/var/run/ssdb.pid 30 | lockfile=/var/lock/subsys/ssdb 31 | 32 | RETVAL=0 33 | 34 | start() { 35 | [ -x $ssdb ] || exit 5 36 | [ -f $configfile ] || exit 6 37 | echo -n $"Starting $PROG: " 38 | ${ssdb} -d ${configfile} 39 | RETVAL=$? 40 | echo 41 | [ $RETVAL -eq 0 ] && touch $lockfile 42 | return $RETVAL 43 | } 44 | 45 | stop() { 46 | echo -n $"Stopping $PROG: " 47 | killproc -p ${pidfile} -d $ssdb 48 | RETVAL=$? 49 | echo 50 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 51 | } 52 | 53 | case "$1" in 54 | start) 55 | start 56 | ;; 57 | reload|restart) 58 | stop 59 | start 60 | ;; 61 | stop) 62 | stop 63 | ;; 64 | condrestart|try-restart) 65 | if status >&/dev/null; then 66 | stop 67 | start 68 | fi 69 | ;; 70 | status) 71 | status -p ${pidfile} $ssdb 72 | RETVAL=$? 73 | ;; 74 | help) 75 | $ssdb 76 | RETVAL=$? 77 | ;; 78 | *) 79 | echo "Usage: $0 {start|reload|restart|condrestart|try-restart|stop|status|help}" 80 | RETVAL=2 81 | ;; 82 | esac 83 | 84 | exit $RETVAL -------------------------------------------------------------------------------- /service/zkServer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # httpd Startup script for the Apache ZooKeeper 4 | # 5 | # chkconfig: - 85 15 6 | # description: The Apache ZooKeeper is a centralized service for maintaining configuration information, 7 | # naming, providing distributed synchronization, and providing group services. 8 | # processname: Apache ZooKeeper 9 | # config: /usr/local/ZooKeeper/conf/zoo.cfg 10 | # config: /etc/sysconfig/zkServer 11 | # pidfile: /var/run/zkServer.pid 12 | # 13 | 14 | # Source function library. 15 | . /etc/rc.d/init.d/functions 16 | 17 | if [ -f /etc/sysconfig/zkServer ]; then 18 | . /etc/sysconfig/zkServer 19 | fi 20 | 21 | ZOOKEEPER_HOME="/usr/local/ZooKeeper" 22 | zookeeper=${ZOOKEEPER_HOME}"/bin/zkServer.sh" 23 | ZOO_DATA_DIR=${ZOO_DATA_DIR-/data/zookeeper/data} 24 | ZOO_LOG_DIR=${ZOO_LOG_DIR-/data/zookeeper/log} 25 | PROG="Apache ZooKeeper" 26 | pidfile=${PIDFILE-/var/run/zkServer.pid} 27 | lockfile=${LOCKFILE-/var/lock/subsys/zkServer} 28 | 29 | source /etc/profile 30 | export ZOO_LOG_DIR 31 | 32 | RETVAL=0 33 | 34 | start() { 35 | echo -n $"Starting $PROG: " 36 | $zookeeper start 37 | RETVAL=$? 38 | echo 39 | [ $RETVAL = 0 ] && touch ${lockfile} 40 | return $RETVAL 41 | } 42 | 43 | start-foreground() { 44 | echo -n $"Starting $PROG: " 45 | $zookeeper start-foreground 46 | echo 47 | [ $RETVAL = 0 ] && touch ${lockfile} 48 | return $RETVAL 49 | } 50 | 51 | restart() { 52 | echo -n $"Restarting $PROG: " 53 | $zookeeper restart 54 | RETVAL=$? 55 | echo 56 | [ $RETVAL = 0 ] && touch ${lockfile} 57 | return $RETVAL 58 | } 59 | 60 | stop() { 61 | echo -n $"Stopping $PROG: " 62 | $zookeeper stop 63 | RETVAL=$? 64 | echo 65 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 66 | } 67 | 68 | upgrade() { 69 | echo -n $"Upgrade $PROG: " 70 | $zookeeper upgrade 71 | RETVAL=$? 72 | } 73 | 74 | print-cmd() { 75 | echo -n $"$PROG running with: " 76 | $zookeeper print-cmd 77 | RETVAL=$? 78 | } 79 | 80 | status() { 81 | $zookeeper status 82 | RETVAL=$? 83 | return $RETVAL 84 | } 85 | 86 | case "$1" in 87 | start) 88 | start 89 | ;; 90 | restart|reload) 91 | restart 92 | ;; 93 | stop) 94 | stop 95 | ;; 96 | status) 97 | status 98 | ;; 99 | -h|help) 100 | $zookeeper $@ 101 | RETVAL=$? 102 | ;; 103 | *) 104 | echo $"Usage: $PROG {start|start-foreground|reload|restart|stop|upgrade|print-cmd|status|help}" 105 | RETVAL=2 106 | ;; 107 | esac 108 | 109 | exit $RETVAL 110 | --------------------------------------------------------------------------------