2 # Start/stop ceph daemons
3 # chkconfig: 2345 60 80
7 # Default-Start: 2 3 4 5
9 # Required-Start: $remote_fs $named $network $time
10 # Required-Stop: $remote_fs $named $network $time
11 # Short-Description: Start Ceph distributed file system daemons at boot time
12 # Description: Enable Ceph distributed file system services.
15 # TODO: on FreeBSD/OSX, use equivalent script file
16 if [ -e /lib
/lsb
/init-functions
]; then
17 .
/lib
/lsb
/init-functions
20 [ -z "$BUILD_DIR" ] && BUILD_DIR
=build
22 if [ `dirname $0` = "." ] && [ $PWD != "/etc/init.d" ]; then
23 # looks like an autotools src dir build
30 if [ -e CMakeCache.txt
] && [ -e bin
/init-ceph
]; then
31 # looks like a cmake build directory
32 CEPH_ROOT
=`grep ceph_SOURCE_DIR CMakeCache.txt | cut -d "=" -f 2`
35 LIBEXECDIR
=$CEPH_ROOT/src
38 CEPH_LIB
=$CEPH_ROOT/${BUILD_DIR}/lib
39 echo "$PYTHONPATH" |
grep -q $CEPH_LIB ||
export PYTHONPATH
=$CEPH_LIB/cython_modules
/lib
.3:$PYTHONPATH
40 echo "$LD_LIBRARY_PATH" |
grep -q $CEPH_LIB ||
export LD_LIBRARY_PATH
=$CEPH_LIB:$LD_LIBRARY_PATH
41 echo "$DYLD_LIBRARY_PATH" |
grep -q $CEPH_LIB ||
export DYLD_LIBRARY_PATH
=$CEPH_LIB:$DYLD_LIBRARY_PATH
45 LIBEXECDIR
=@libexecdir@
/ceph
46 ETCDIR
=@sysconfdir@
/ceph
51 if [ -n "$CEPH_BIN" ] && [ -n "$CEPH_ROOT" ] && [ -n "$CEPH_BUILD_DIR" ]; then
53 SBINDIR
=$CEPH_ROOT/src
55 LIBEXECDIR
=$CEPH_ROOT/src
59 if [ `uname` = FreeBSD
]; then
60 GETOPT
=/usr
/local
/bin
/getopt
65 if id ceph
> /dev
/null
2>&1; then
66 SET_CEPHUSER_ARGS
=" --setuser ceph --setgroup ceph"
70 echo "usage: $0 [options] {start|stop|restart|condrestart} [mon|osd|mds]..."
71 printf "Core options:\n"
72 printf "\t--allhosts / -a execute (via ssh) on all hosts in conf file\n"
73 printf "\t--cluster [cluster name] define the cluster name\n"
74 printf "\t--conf / -c [conf file] use [conf file] instead of default\n"
75 printf "\t--help / -h show this usage message\n"
76 printf "\t--hostname [hostname] override hostname lookup\n"
77 printf "\t-m [mon addr] mon address\n"
79 printf "Other options:\n"
80 printf "\t--btrfs btrfs\n"
81 printf "\t--nobtrfs no btrfs\n"
82 printf "\t--btrfsumount btrfs umount\n"
83 printf "\t--fsmount fsmount\n"
84 printf "\t--nofsmount no fsmount\n"
85 printf "\t--fsumount fsumount\n"
86 printf "\t--restart restart on core dump\n"
87 printf "\t--norestart do not restart on core dump\n"
88 printf "\t--valgrind run via valgrind\n"
89 printf "\t--novalgrind do not run via valgrind\n"
90 printf "\t--verbose / -v be verbose\n"
94 # behave if we are not completely installed (e.g., Debian "removed,
95 # config remains" state)
96 test -f $LIBEXECDIR/ceph_common.sh ||
exit 0
98 .
$LIBEXECDIR/ceph_common.sh
108 [ -z "$action" ] && action
="Stopping"
109 printf "$action Ceph $name on $host..."
110 do_cmd
"if [ -e $pidfile ]; then
112 if ps -p \$pid -o args= | grep -q $daemon; then
113 cmd=\"kill $signal \$pid\"
121 daemon_is_running
() {
126 do_cmd
"[ -e $pidfile ] || exit 1 # no pid, presumably not running
128 ps -p \$pid -o args= | grep $daemon | grep -qwe -i.$daemon_id && exit 0 # running
129 exit 1 # pid is something else" "" "okfail"
138 [ -z "$action" ] && action
="Stopping"
139 printf "$action Ceph $name on $host..."
140 do_cmd
"if [ -e $pidfile ] ; then
142 while ps -p \$pid -o args= | grep -q $daemon; do
143 cmd=\"kill $signal \$pid\"
153 ## command line options
156 OPTS
=$
(${GETOPT} -n 'init-ceph' -o 'hvam:c:' -l 'help,verbose,valgrind,novalgrind,allhosts,restart,norestart,btrfs,nobtrfs,fsmount,nofsmount,btrfsumount,fsumount,conf:,cluster:,hostname:' -- "$@")
173 ## set variables like cluster or conf
174 [ -e /etc
/sysconfig
/ceph
] && .
/etc
/sysconfig
/ceph
175 [ -e /etc
/default
/ceph
] && .
/etc
/default
/ceph
178 while echo $1 |
grep -q '^-'; do # FIXME: why not '^-'?
202 [ -z "$2" ] && usage_exit
203 options
="$options $1"
210 --nobtrfs |
--nofsmount)
213 --btrfsumount |
--fsumount)
217 [ -z "$2" ] && usage_exit
218 options
="$options $1"
224 [ -z "$2" ] && usage_exit
225 options
="$options $1"
230 [ -z "$2" ] && usage_exit
231 options
="$options $1"
240 echo unrecognized option
\'$1\'
244 options
="$options $1"
248 # if `--cluster` was not passed in, fallback to looking at the config name
249 if [ -z "$cluster" ]; then
250 cluster
=`echo $conf | awk -F'/' '{print $(NF)}' | cut -d'.' -f 1`
252 # if we were told to use a given cluster name then $conf needs to be updated
253 # but just define it if `--conf` was not specified, otherwise we would be silently
254 # overriding $conf even if it was defined with `--conf`
255 if [ $use_default_conf -eq 1 ]; then
256 conf
="/etc/ceph/$cluster.conf"
269 # Reverse the order if we are stopping
271 if [ "$command" = "stop" -o "$command" = "onestop" ]; then
273 new_order
="$f $new_order"
278 for name
in $what; do
279 type=`echo $name | cut -c 1-3` # e.g. 'mon', if $item is 'mon1'
280 id
=`echo $name | cut -c 4- | sed 's/^\\.//'`
284 check_host
$cluster ||
continue
286 binary
="$BINDIR/ceph-$type"
288 if [ $ASSUME_DEV -eq 1 ]; then
289 cmd
="PATH=$PWD:$PATH $cmd"
292 get_conf run_dir
"/var/run/ceph" "run dir"
294 get_conf pid_file
"$run_dir/$type.$id.pid" "pid file"
296 if [ "$command" = "start" -o "$command" = "onestart" ]; then
297 if [ -n "$pid_file" ]; then
298 do_cmd
"mkdir -p "`dirname $pid_file`
299 cmd
="$cmd --pid-file $pid_file"
302 get_conf log_dir
"" "log dir"
303 [ -n "$log_dir" ] && do_cmd
"mkdir -p $log_dir"
305 get_conf auto_start
"" "auto start"
306 if [ "$auto_start" = "no" ] ||
[ "$auto_start" = "false" ] ||
[ "$auto_start" = "0" ]; then
308 echo "Skipping Ceph $name on $host... auto start is disabled"
313 if daemon_is_running
$name ceph-
$type $id $pid_file; then
314 echo "Starting Ceph $name on $host...already running"
318 get_conf copy_executable_to
"" "copy executable to"
319 if [ -n "$copy_executable_to" ]; then
320 scp
$binary "$host:$copy_executable_to"
321 binary
="$copy_executable_to"
328 if echo $name |
grep -q ^osd
; then
329 get_conf osd_data
"/var/lib/ceph/osd/$cluster-$id" "osd data"
330 get_conf fs_path
"$osd_data" "fs path" # mount point defaults so osd data
331 get_conf fs_devs
"" "devs"
332 if [ -z "$fs_devs" ]; then
333 # try to fallback to old keys
334 get_conf tmp_btrfs_devs
"" "btrfs devs"
335 if [ -n "$tmp_btrfs_devs" ]; then
336 fs_devs
="$tmp_btrfs_devs"
339 first_dev
=`echo $fs_devs | cut '-d ' -f 1`
343 get_conf lockfile
"/var/lock/subsys/ceph" "lock file"
344 lockdir
=`dirname $lockfile`
345 if [ ! -d "$lockdir" ]; then
349 get_conf asok
"$run_dir/$cluster-$type.$id.asok" "admin socket"
353 # Increase max_open_files, if the configuration calls for it.
354 get_conf max_open_files
"32768" "max open files"
356 # build final command
361 [ -z "$docrun" ] && get_conf_bool docrun
"0" "restart on core dump"
362 [ "$docrun" -eq 1 ] && wrap
="$BINDIR/ceph-run"
364 [ -z "$dovalgrind" ] && get_conf_bool valgrind
"" "valgrind"
365 [ -n "$valgrind" ] && wrap
="$wrap valgrind $valgrind"
367 [ -n "$wrap" ] && runmode
="-f &" && runarg
="-f"
368 [ -n "$max_open_files" ] && files
="ulimit -n $max_open_files;"
370 [ -n "$TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES" ] && tcmalloc
="TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=$TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES"
372 cmd
="$files $tcmalloc $wrap $cmd --cluster $cluster ${SET_CEPHUSER_ARGS} $runmode"
374 if [ $dofsmount -eq 1 ] && [ -n "$fs_devs" ]; then
375 get_conf pre_mount
"true" "pre mount command"
376 get_conf fs_type
"" "osd mkfs type"
378 if [ -z "$fs_type" ]; then
379 # try to fallback to old keys
380 get_conf tmp_devs
"" "btrfs devs"
381 if [ -n "$tmp_devs" ]; then
384 echo No filesystem
type defined
!
389 get_conf fs_opt
"" "osd mount options $fs_type"
390 if [ -z "$fs_opt" ]; then
391 if [ "$fs_type" = "btrfs" ]; then
392 #try to fallback to old keys
393 get_conf fs_opt
"" "btrfs options"
396 if [ -z "$fs_opt" ]; then
397 if [ "$fs_type" = "xfs" ]; then
398 fs_opt
="rw,noatime,inode64"
400 #fallback to use at least noatime
406 [ -n "$fs_opt" ] && fs_opt
="-o $fs_opt"
407 [ -n "$pre_mount" ] && do_cmd
"$pre_mount"
409 do_root_cmd_okfail
"mkdir -p $fs_path"
410 if [ "$fs_type" = "btrfs" ]; then
411 echo Mounting Btrfs on
$host:$fs_path
412 do_root_cmd_okfail
"modprobe btrfs ; btrfs device scan || btrfsctl -a ; egrep -q '^[^ ]+ $fs_path ' /proc/mounts && umount $fs_path ; mount -t btrfs $fs_opt $first_dev $fs_path"
414 echo Mounting
$fs_type on
$host:$fs_path
415 do_root_cmd_okfail
"modprobe $fs_type ; egrep -q '^[^ ]+ $fs_path ' /proc/mounts && umount $fs_path ; mount -t $fs_type $fs_opt $first_dev $fs_path"
417 if [ "$ERR" != "0" ]; then
423 echo Starting Ceph
$name on
$host...
424 if [ ! -d $run_dir ]; then
425 # assume /var/run exists
426 install -d -m0770 -o ceph
-g ceph
/var
/run
/ceph
428 get_conf pre_start_eval
"" "pre start eval"
429 [ -n "$pre_start_eval" ] && $pre_start_eval
430 get_conf pre_start
"" "pre start command"
431 get_conf post_start
"" "post start command"
432 [ -n "$pre_start" ] && do_cmd
"$pre_start"
433 do_cmd_okfail
"$cmd" $runarg
434 if [ "$ERR" != "0" ]; then
439 [ -n "$post_start" ] && do_cmd
"$post_start"
440 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && touch $lockfile
444 get_conf pre_stop
"" "pre stop command"
445 get_conf post_stop
"" "post stop command"
446 [ -n "$pre_stop" ] && do_cmd
"$pre_stop"
447 stop_daemon
$name ceph-
$type $pid_file
448 [ -n "$pidfile" ] && rm -f $pidfile
449 [ -n "$asok" ] && rm -f $asok
450 [ -n "$post_stop" ] && do_cmd
"$post_stop"
451 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
452 if [ $dofsumount -eq 1 ] && [ -n "$fs_devs" ]; then
453 echo Unmounting OSD volume on
$host:$fs_path
454 do_root_cmd
"umount $fs_path || true"
459 if daemon_is_running
$name ceph-
$type $id $pid_file; then
460 printf "$name: running "
461 do_cmd
"$BINDIR/ceph daemon $name version 2>/dev/null" ||
printf unknown
463 elif [ -e "$pid_file" ]; then
464 # daemon is dead, but pid file still exists
468 # daemon is dead, and pid file is gone
469 echo "$name: not running."
479 get_conf pre_forcestop
"" "pre forcestop command"
480 get_conf post_forcestop
"" "post forcestop command"
481 [ -n "$pre_forcestop" ] && do_cmd
"$pre_forcestop"
482 stop_daemon
$name ceph-
$type $pid_file -9
483 [ -n "$post_forcestop" ] && do_cmd
"$post_forcestop"
484 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
488 echo "killall ceph-$type on $host"
489 do_cmd
"pkill ^ceph-$type || true"
490 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
493 force-reload | reload
)
494 signal_daemon
$name ceph-
$type $pid_file -1 "Reloading"
498 $0 $options stop
$name
499 $0 $options start
$name
503 if daemon_is_running
$name ceph-
$type $id $pid_file; then
504 $0 $options stop
$name
505 $0 $options start
$name
507 echo "$name: not running."
513 [ -n "$log_dir" ] && do_cmd
"rm -f $log_dir/$type.$id.*"
517 echo removing all logs
518 [ -n "$log_dir" ] && do_cmd
"rm -f $log_dir/* || true"