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].

放在/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

 

相关文章
|
4月前
|
存储 算法框架/工具
Ceph提供nfs服务
Ceph提供nfs服务
65 6
|
应用服务中间件 nginx Docker
在 Docker 中部署 Nginx 并挂载配置文件
在 Docker 中部署 Nginx 并挂载配置文件
glusterfs常用命令
glusterfs常用命令
|
网络协议 应用服务中间件 API
CentOS7.5 手动部署Ceph RGW
目    录 1     设备列表... 1 2     Ceph RGW 部署... 1 2.1     使用civetweb配置... 2 2.2     使用nginx配置... 5   本文主要记录一下手动部署rgw的过程,环境是使用的之前手动部署的ceph环境,之前的环境部署可以参考以下链接https://yq.aliyun.com/articles/604372   Ceph RGW(即RADOS Gateway)是Ceph对象存储网关服务,是基于LIBRADOS接口封装实现的FastCGI服务,对外提供存储和管理对象数据的Restful API。
7801 0
|
关系型数据库 块存储 监控
|
存储 监控 网络协议
GlusterFS常用命令
1、启动/关闭/查看glusterd服务   # /etc/init.d/glusterd start   # /etc/init.d/glusterd stop    # /etc/init.d/glusterd status 2、 开机自动启动glusterd服务   # chkconfig glusterd on # Red Hat    # update-rc.
1567 0
|
存储 Prometheus 监控
使用cephadm安装ceph octopus
使用cephadm安装ceph octopus
使用cephadm安装ceph octopus
|
数据建模 应用服务中间件 nginx
Docker - 解决创建 nginx 容器尝试挂载 nginx.conf 文件时报错: mounting "/root/nginx.conf" to rootfs at "/etc/nginx/nginx.conf" caused: mount through procfd: not a directory:
Docker - 解决创建 nginx 容器尝试挂载 nginx.conf 文件时报错: mounting "/root/nginx.conf" to rootfs at "/etc/nginx/nginx.conf" caused: mount through procfd: not a directory:
3164 0
|
存储 关系型数据库 块存储
|
存储 测试技术 网络安全
ceph安装配置
简介 ceph是一个开源分布式存储系统,支持PB级别的存储,支持对象存储,块存储和文件存储,高性能,高可用,可扩展。 部署网络建议架构图 部署 部署架构图,本次实验部署jewel版本 实验环境的Vagrantfile lab1节点既作admin节点又作node节点,lab2,.
2631 0