ceph启动脚本

放在/etc/init.d/目录下,用法如下:

1 root@u253:~# /etc/init.d/ceph
2 === mon.a ===
3 usage: /etc/init.d/ceph [options] {start|stop|restart} [mon|osd|mds]...
4     -c ceph.conf
5     --valgrind    run via valgrind
6     --hostname [hostname]    override hostname lookup

源码如下:

  1 文件名:ceph
  2 #!/bin/sh
  3 # Start/stop ceph daemons
  4 # chkconfig: 2345 60 80
  5
  6 ### BEGIN INIT INFO
  7 # Provides:          ceph
  8 # Default-Start:     2 3 5
  9 # Default-Stop:      0 1 6
 10 # Required-Start:    $remote_fs $named $network $time
 11 # Required-Stop:     $remote_fs $named $network $time
 12 # Short-Description: Start Ceph distributed file system daemons at boot time
 13 # Description:       Enable Ceph distributed file system services.
 14 ### END INIT INFO
 15
 16 # if we start up as ./mkcephfs, assume everything else is in the
 17 # current directory too.
 18 if [ `dirname $0` = "." ] && [ $PWD != "/etc/init.d" ]; then
 19     BINDIR=.
 20     LIBDIR=.
 21     ETCDIR=.
 22 else
 23     BINDIR=/usr/bin
 24     LIBDIR=/usr/lib/ceph
 25     ETCDIR=/etc/ceph
 26 fi
 27
 28 usage_exit() {
 29     echo "usage: $0 [options] {start|stop|restart} [mon|osd|mds]..."
 30     printf "\t-c ceph.conf\n"
 31     printf "\t--valgrind\trun via valgrind\n"
 32     printf "\t--hostname [hostname]\toverride hostname lookup\n"
 33     exit
 34 }
 35
 36 . $LIBDIR/ceph_common.sh
 37
 38 EXIT_STATUS=0
 39
 40 signal_daemon() {
 41     name=$1
 42     daemon=$2
 43     pidfile=$3
 44     signal=$4
 45     action=$5
 46     [ -z "$action" ] && action="Stopping"
 47     echo -n "$action Ceph $name on $host..."
 48     do_cmd "if [ -e $pidfile ]; then
 49         pid=`cat $pidfile`
 50         if [ -e /proc/\$pid ] && grep -q $daemon /proc/\$pid/cmdline ; then
 51         cmd=\"kill $signal \$pid\"
 52         echo -n \$cmd...
 53         \$cmd
 54         fi
 55     fi"
 56     echo done
 57 }
 58
 59 daemon_is_running() {
 60     name=$1
 61     daemon=$2
 62     daemon_id=$3
 63     pidfile=$4
 64     do_cmd "[ -e $pidfile ] || exit 1   # no pid, presumably not running
 65     pid=\`cat $pidfile\`
 66     [ -e /proc/\$pid ] && grep -q $daemon /proc/\$pid/cmdline && grep -qwe -i.$daemon_id /proc/\$pid/cmdline && exit 0 # running
 67         exit 1  # pid is something else" "" "okfail"
 68 }
 69
 70 stop_daemon() {
 71     name=$1
 72     daemon=$2
 73     pidfile=$3
 74     signal=$4
 75     action=$5
 76     [ -z "$action" ] && action="Stopping"
 77     echo -n "$action Ceph $name on $host..."
 78     do_cmd "while [ 1 ]; do
 79     [ -e $pidfile ] || break
 80     pid=\`cat $pidfile\`
 81     while [ -e /proc/\$pid ] && grep -q $daemon /proc/\$pid/cmdline ; do
 82         cmd=\"kill $signal \$pid\"
 83         echo -n \$cmd...
 84         \$cmd
 85         sleep 1
 86         continue
 87     done
 88     break
 89     done"
 90     echo done
 91 }
 92
 93 ## command line options
 94 options=
 95
 96 version=0
 97 dovalgrind=
 98 docrun=
 99 allhosts=0
100 debug=0
101 monaddr=
102 dobtrfs=1
103 dobtrfsumount=0
104 verbose=0
105
106 while echo $1 | grep -q '^-'; do     # FIXME: why not '^-'?
107 case $1 in
108     -v | --verbose)
109         verbose=1
110         ;;
111     --valgrind)
112         dovalgrind=1
113         ;;
114     --novalgrind)
115         dovalgrind=0
116         ;;
117     --allhosts | -a)
118         allhosts=1;
119         ;;
120     --restart)
121         docrun=1
122         ;;
123     --norestart)
124         docrun=0
125         ;;
126     -m )
127         [ -z "$2" ] && usage_exit
128         options="$options $1"
129         shift
130         MON_ADDR=$1
131         ;;
132     --btrfs)
133         dobtrfs=1
134         ;;
135     --nobtrfs)
136         dobtrfs=0
137         ;;
138     --btrfsumount)
139         dobtrfsumount=1
140         ;;
141     --conf | -c)
142         [ -z "$2" ] && usage_exit
143         options="$options $1"
144         shift
145         conf=$1
146         ;;
147     --hostname )
148         [ -z "$2" ] && usage_exit
149         options="$options $1"
150         shift
151         hostname=$1
152             ;;
153     *)
154         echo unrecognized option \'$1\'
155         usage_exit
156         ;;
157 esac
158 options="$options $1"
159 shift
160 done
161
162 verify_conf
163
164 command=$1
165 [ -n "$*" ] && shift
166
167 get_name_list "$@"
168
169 for name in $what; do
170     type=`echo $name | cut -c 1-3`   # e.g. 'mon', if $item is 'mon1'
171     id=`echo $name | cut -c 4- | sed 's/^\\.//'`
172     num=$id
173     name="$type.$id"
174
175     get_conf auto_start "" "auto start"
176     if [ -z "$@" ] || [ "$@" = "mds" ]; then
177     if [ "$auto_start" = "no" ] || [ "$auto_start" = "false" ] || [ "$auto_start" = "0" ]; then
178         continue
179     fi
180     fi
181
182     check_host || continue
183
184     get_conf pid_file "/var/run/ceph/$type.$id.pid" "pid file"
185     [ -n "$pid_file" ] && do_cmd "mkdir -p "`dirname $pid_file`
186
187     get_conf log_dir "" "log dir"
188     get_conf log_sym_dir "" "log sym dir"
189     [ -n "$log_dir" ] && do_cmd "mkdir -p $log_dir"
190     [ -n "$log_sym_dir" ] && do_cmd "mkdir -p $log_sym_dir"
191
192     # start, and already running?  (do this check early to avoid unnecessary work!)
193     if [ "$command" = "start" ]; then
194     if daemon_is_running $name ceph-$type $id $pid_file; then
195         echo "Starting Ceph $name on $host...already running"
196         continue
197     fi
198     fi
199
200     # binary?
201     binary="$BINDIR/ceph-$type"
202     if [ "$command" = "start" ]; then
203     get_conf copy_executable_to "" "copy executable to"
204     if [ -n "$copy_executable_to" ]; then
205         scp $binary "$host:$copy_executable_to"
206         binary="$copy_executable_to"
207     fi
208     fi
209
210     cmd="$binary -i $id"
211
212     # conf file
213     if [ "$host" = "$hostname" ]; then
214     cur_conf=$conf
215     else
216     if echo $pushed_to | grep -v -q " $host "; then
217         scp -q $conf $host:/tmp/ceph.conf.$$
218         pushed_to="$pushed_to $host "
219     fi
220     cur_conf="/tmp/ceph.conf.$$"
221     fi
222     cmd="$cmd -c $cur_conf"
223
224     if echo $name | grep -q ^osd; then
225     get_conf osd_data "" "osd data"
226     get_conf btrfs_path "$osd_data" "btrfs path"  # mount point defaults so osd data
227     get_conf btrfs_devs "" "btrfs devs"
228     first_dev=`echo $btrfs_devs | cut '-d ' -f 1`
229     fi
230
231     # do lockfile, if RH
232     get_conf lockfile "/var/lock/subsys/ceph" "lock file"
233     lockdir=`dirname $lockfile`
234     if [ ! -d "$lockdir" ]; then
235     lockfile=""
236     fi
237
238     case "$command" in
239     start)
240             # Increase max_open_files, if the configuration calls for it.
241             get_conf max_open_files "0" "max open files"
242             if [ $max_open_files != "0" ]; then
243                 # Note: Don't try to do math with these numbers, because POSIX shells
244                 # can't do 64-bit math (natively). Just treat them as strings.
245                 cur=`ulimit -n`
246                 if [ "x$max_open_files" != "x$cur" ]; then
247                     ulimit -n $max_open_files
248                 fi
249             fi
250
251             # build final command
252         wrap=""
253         runmode=""
254         runarg=""
255
256         [ -z "$crun" ] && get_conf_bool crun "0" "restart on core dump"
257         [ "$crun" -eq 1 ] && wrap="$BINDIR/ceph-run"
258
259         [ -z "$dovalgrind" ] && get_conf_bool valgrind "" "valgrind"
260         [ -n "$valgrind" ] && wrap="$wrap valgrind $valgrind"
261
262         [ -n "$wrap" ] && runmode="-f &" && runarg="-f"
263
264         cmd="$wrap $cmd $runmode"
265
266         if [ $dobtrfs -eq 1 ] && [ -n "$btrfs_devs" ]; then
267         get_conf pre_mount "true" "pre mount command"
268         get_conf btrfs_opt "noatime" "btrfs options"
269         [ -n "$btrfs_opt" ] && btrfs_opt="-o $btrfs_opt"
270         [ -n "$pre_mount" ] && do_cmd "$pre_mount"
271         echo Mounting Btrfs on $host:$btrfs_path
272         do_root_cmd "modprobe btrfs ; btrfsctl -a ; egrep -q '^[^ ]+ $btrfs_path' /proc/mounts || mount -t btrfs $btrfs_opt $first_dev $btrfs_path"
273         fi
274         echo Starting Ceph $name on $host...
275         get_conf pre_start_eval "" "pre start eval"
276         [ -n "$pre_start_eval" ] && $pre_start_eval
277         get_conf pre_start "" "pre start command"
278         get_conf post_start "" "post start command"
279         [ -n "$pre_start" ] && do_cmd "$pre_start"
280         do_cmd "$cmd" $runarg
281         [ -n "$post_start" ] && do_cmd "$post_start"
282         [ -n "$lockfile" ] && [ "$?" -eq 0 ] && touch $lockfile
283         ;;
284
285     stop)
286         get_conf pre_stop "" "pre stop command"
287         get_conf post_stop "" "post stop command"
288         [ -n "$pre_stop" ] && do_cmd "$pre_stop"
289         stop_daemon $name ceph-$type $pid_file
290         [ -n "$post_stop" ] && do_cmd "$post_stop"
291         [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
292         if [ $dobtrfsumount -eq 1 ] && [ -n "$btrfs_devs" ]; then
293         echo Unmounting Btrfs on $host:$btrfs_path
294         do_root_cmd "umount $btrfs_path || true"
295         fi
296         ;;
297
298     status)
299         if daemon_is_running $name ceph-$type $id $pid_file; then
300                 echo "$name: running..."
301             elif [ -e "$pid_file" ]; then
302                 # daemon is dead, but pid file still exists
303                 echo "$name: dead."
304                 EXIT_STATUS=1
305             else
306                 # daemon is dead, and pid file is gone
307                 echo "$name: not running."
308                 EXIT_STATUS=3
309             fi
310         ;;
311
312     ssh)
313         $ssh
314         ;;
315
316     forcestop)
317         get_conf pre_forcestop "" "pre forcestop command"
318         get_conf post_forcestop "" "post forcestop command"
319         [ -n "$pre_forcestop" ] && do_cmd "$pre_forcestop"
320         stop_daemon $name ceph-$type $pid_file -9
321         [ -n "$post_forcestop" ] && do_cmd "$post_forcestop"
322         [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
323         ;;
324
325     killall)
326         echo "killall ceph-$type on $host"
327         do_cmd "pkill ^ceph-$type || true"
328         [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
329         ;;
330
331     force-reload | reload)
332         signal_daemon $name ceph-$type $pid_file -1 "Reloading"
333         ;;
334
335     restart)
336         $0 $options stop $name
337         $0 $options start $name
338         ;;
339
340     cleanlogs)
341         echo removing logs
342         if [ -n "$log_sym_dir" ]; then
343         do_cmd "for f in $log_sym_dir/$type.$id.*; do rm -f \`readlink \$f\` ; rm -f \$f ; done ; rm -f $log_dir/$type.$id.*"
344         fi
345         [ -n "$log_dir" ] && do_cmd "rm -f $log_dir/$type.$id.*"
346         ;;
347
348     cleanalllogs)
349         echo removing all logs
350         [ -n "$log_sym_dir" ] && do_cmd "rm -f $log_sym_dir/* || true"
351         [ -n "$log_dir" ] && do_cmd "rm -f $log_dir/* || true"
352         ;;
353
354     *)
355         usage_exit
356         ;;
357     esac
358 done
359
360 exit $EXIT_STATUS

 

时间: 2024-07-30 11:52:54

ceph启动脚本的相关文章

RedHat Linux下Oracle启动脚本的建立 dbstart oracle8.1.6

oracle|脚本 RedHat Linux下Oracle启动脚本的建立 2001-06-05 8:25发布者:Crystal 阅读次数:102 一.修改$ORACLE_HOME/bin/dbstart脚本 首先测试你的$ORACLE/bin/dbstart脚本,如果能正常启动Oracle,请跳到第二部分. 本人运行环境为RedHat7.1+Oracle8.1.6,发现dbstart脚本有问题,不能得到当前运行的Oracle的版本号.编辑dbstart,找到 STATUS=1 if [ "$VE

用Windows XP启动脚本恢复系统的用户密码

用一种不用第三方软件的方法来恢复管理员密码,大家可以看看这招技巧如何. Windows XP启动脚本(startup scripts)是计算机在登录屏幕出现之前运行的批处理文件,它的功能类似于Windows 9×和DOS中的自动执行批处理文件autoexec.bat.利用这个特性,可以编写一个批处理文件重新设置用户密码,并将它加入启动脚本中,这样就达到了目的.以下是具体步骤(假设系统目录为C:\Windows). 1.使用Windows98启动盘启动电脑.编写一个能恢复密码的批处理文件a.bat

Slackware启动脚本与System V启动脚本的区别

Slackware版本:Slackware 7.0及以上 Slackware 使用BSD风格的init脚本,而很多别的发行版使用System V风格的init脚本.SysV和BSD脚本都是能让人读懂的,即它们都是shell脚本,而不是已编译的程序.主要的区别在于脚本是如何设计的. SysV脚本倾向于接受诸如start.stop.restart之类的参数,依它所启动的程序而定.所以你可以用 /etc/init.d/bind start 这样的命令来启动BIND,并用 /etc/init.d/bin

squid源码安装的服务启动脚本

#!/bin/bash # squid This shell script takes care of starting and stopping # Squid Internet Object Cache # # chkconfig: - 90 25 # description: Squid - Internet Object Cache. Internet object caching is \ # a way to store requested Internet objects (i.e

liunx-求助。。。ubuntu重新安装tools后启动脚本出错

问题描述 求助...ubuntu重新安装tools后启动脚本出错 本来想给虚拟机共享文件,进入ubuntu以后没有挂载上文件,网上说是tools的问题,我重装后提示启动脚本有错误而且不能自适应屏幕,在win7复制到虚拟机下也不能粘贴,tools重装过好多次都是这样.求解决呀 虚拟机里有好多东西我不想重做系统 解决方案 为了能在VMware中Ubuntu系统中看到Windows下的共享文件夹,必须安装VMware Tools工具. 第一种方法(适用于一般情况): 1.安装编译环境: 打开"终端&q

vmware tool-求助。。。ubuntu重新安装tools后启动脚本出错

问题描述 求助...ubuntu重新安装tools后启动脚本出错 本来想给虚拟机共享文件,进入ubuntu以后没有挂载上文件,网上说是tools的问题,我重装后提示启动脚本有错误而且不能自适应屏幕,在win7复制到虚拟机下也不能粘贴,tools重装过好多次都是这样.求解决呀 虚拟机里有好多东西我不想重做系统 解决方案 为了能在VMware中Ubuntu系统中看到Windows下的共享文件夹,必须安装VMware Tools工具. 第一种方法(适用于一般情况): 1.安装编译环境: 打开"终端&q

linux下Shell编程--标准的守护进程的启动脚本

一个标准的守护进程的启动脚本: #! /bin/sh WHOAMI=`whoami` PID=`ps -u $WHOAMI | gerp mydaemond | awk '{print $1}'` if (test "$1" = "") then echo "mydaemond [start][stop][version]" exit 0 fi if ( test "$1" = "status") then

Linux_自制系统服务启动脚本

目录 目录 前言 Case语句 Apache 启动脚本 Postfix service 启停脚本 前言 在Linux的某些系统服务中,需要自己定制启动服务的脚本.通常会使用Cash语句来实现. Case语句 一般用于程序启动脚本 Syntax: case $1 in Param1) Commands ;; Param2) Commands ;; *) Commands esac Example: #!/bin/bash -e #/bin/bash -e 表示系统发生第一个错误时就中止脚本执行 #

Redis 在Centos Linux 上的启动脚本

Redis管理脚本基于Ubuntu 的发行版上的,Ubuntu的可以看这篇文章ubuntu安装启动redis,在Centos linux 上并不能用,下面的脚本可以用于CentOS: 用这个脚本管理之前,需要先配置下面的内核参数,否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上: # vi /etc/sysctl.conf vm.overcommit_memory = 1 然后应用生效: # sysctl –p 建立redis启动脚本: # vim