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 # mgr shells out to radosgw-admin; give it a proper path
40 export PATH
=$BINDIR:$PATH
41 echo "$PYTHONPATH" |
grep -q $CEPH_LIB ||
export PYTHONPATH
=$CEPH_ROOT/src
/pybind
:$CEPH_LIB/cython_modules
/lib
.3:$CEPH_ROOT/src
/python-common
:$PYTHONPATH
42 echo "$LD_LIBRARY_PATH" |
grep -q $CEPH_LIB ||
export LD_LIBRARY_PATH
=$CEPH_LIB:$CEPH_ROOT/${BUILD_DIR}/external
/lib
:$LD_LIBRARY_PATH
43 echo "$DYLD_LIBRARY_PATH" |
grep -q $CEPH_LIB ||
export DYLD_LIBRARY_PATH
=$CEPH_LIB:$CEPH_ROOT/${BUILD_DIR}/external
/lib
:$DYLD_LIBRARY_PATH
47 LIBEXECDIR
=@libexecdir@
/ceph
48 ETCDIR
=@sysconfdir@
/ceph
53 if [ -n "$CEPH_BIN" ] && [ -n "$CEPH_ROOT" ] && [ -n "$CEPH_BUILD_DIR" ]; then
55 SBINDIR
=$CEPH_ROOT/src
57 LIBEXECDIR
=$CEPH_ROOT/src
61 if [ `uname` = FreeBSD
]; then
62 GETOPT
=/usr
/local
/bin
/getopt
67 if id ceph
> /dev
/null
2>&1; then
68 SET_CEPHUSER_ARGS
=" --setuser ceph --setgroup ceph"
72 echo "usage: $0 [options] {start|stop|restart|condrestart} [mon|osd|mds]..."
73 printf "Core options:\n"
74 printf "\t--allhosts / -a execute (via ssh) on all hosts in conf file\n"
75 printf "\t--cluster [cluster name] define the cluster name\n"
76 printf "\t--conf / -c [conf file] use [conf file] instead of default\n"
77 printf "\t--help / -h show this usage message\n"
78 printf "\t--hostname [hostname] override hostname lookup\n"
79 printf "\t-m [mon addr] mon address\n"
81 printf "Other options:\n"
82 printf "\t--btrfs btrfs\n"
83 printf "\t--nobtrfs no btrfs\n"
84 printf "\t--btrfsumount btrfs umount\n"
85 printf "\t--fsmount fsmount\n"
86 printf "\t--nofsmount no fsmount\n"
87 printf "\t--fsumount fsumount\n"
88 printf "\t--restart restart on core dump\n"
89 printf "\t--norestart do not restart on core dump\n"
90 printf "\t--valgrind run via valgrind\n"
91 printf "\t--novalgrind do not run via valgrind\n"
92 printf "\t--verbose / -v be verbose\n"
96 # behave if we are not completely installed (e.g., Debian "removed,
97 # config remains" state)
98 test -f $LIBEXECDIR/ceph_common.sh ||
exit 0
100 .
$LIBEXECDIR/ceph_common.sh
110 [ -z "$action" ] && action
="Stopping"
111 printf "$action Ceph $name on $host..."
112 do_cmd
"if [ -e $pidfile ]; then
114 if ps -p \$pid -o args= | grep -q $daemon; then
115 cmd=\"kill $signal \$pid\"
123 daemon_is_running
() {
128 do_cmd
"[ -e $pidfile ] || exit 1 # no pid, presumably not running
130 ps -p \$pid -o args= | grep $daemon | grep -qwe -i.$daemon_id && exit 0 # running
131 exit 1 # pid is something else" "" "okfail"
140 [ -z "$action" ] && action
="Stopping"
141 printf "$action Ceph $name on $host..."
142 do_cmd
"if [ -e $pidfile ] ; then
144 while ps -p \$pid -o args= | grep -q $daemon; do
145 cmd=\"kill $signal \$pid\"
155 ## command line options
158 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:' -- "$@")
175 ## set variables like cluster or conf
176 [ -e /etc
/sysconfig
/ceph
] && .
/etc
/sysconfig
/ceph
177 [ -e /etc
/default
/ceph
] && .
/etc
/default
/ceph
180 while echo $1 |
grep -q '^-'; do # FIXME: why not '^-'?
204 [ -z "$2" ] && usage_exit
205 options
="$options $1"
212 --nobtrfs |
--nofsmount)
215 --btrfsumount |
--fsumount)
219 [ -z "$2" ] && usage_exit
220 options
="$options $1"
226 [ -z "$2" ] && usage_exit
227 options
="$options $1"
232 [ -z "$2" ] && usage_exit
233 options
="$options $1"
242 echo unrecognized option
\'$1\'
246 options
="$options $1"
250 # if `--cluster` was not passed in, fallback to looking at the config name
251 if [ -z "$cluster" ]; then
252 cluster
=`echo $conf | awk -F'/' '{print $(NF)}' | cut -d'.' -f 1`
254 # if we were told to use a given cluster name then $conf needs to be updated
255 # but just define it if `--conf` was not specified, otherwise we would be silently
256 # overriding $conf even if it was defined with `--conf`
257 if [ $use_default_conf -eq 1 ]; then
258 conf
="/etc/ceph/$cluster.conf"
271 # Reverse the order if we are stopping
273 if [ "$command" = "stop" -o "$command" = "onestop" ]; then
275 new_order
="$f $new_order"
280 for name
in $what; do
281 type=`echo $name | cut -c 1-3` # e.g. 'mon', if $item is 'mon1'
282 id
=`echo $name | cut -c 4- | sed 's/^\\.//'`
286 check_host
$cluster ||
continue
288 binary
="$BINDIR/ceph-$type"
290 if [ $ASSUME_DEV -eq 1 ]; then
291 cmd
="PATH=$PWD:$PATH $cmd"
294 get_conf run_dir
"/var/run/ceph" "run dir"
296 get_conf pid_file
"$run_dir/$type.$id.pid" "pid file"
298 if [ ! -d $run_dir ]; then
299 install -d -m0770 -o ceph
-g ceph
/var
/run
/ceph
302 if [ "$command" = "start" -o "$command" = "onestart" ]; then
303 if [ -n "$pid_file" ]; then
304 cmd
="$cmd --pid-file $pid_file"
307 get_conf log_dir
"" "log dir"
308 [ -n "$log_dir" ] && do_cmd
"mkdir -p $log_dir"
310 get_conf auto_start
"" "auto start"
311 if [ "$auto_start" = "no" ] ||
[ "$auto_start" = "false" ] ||
[ "$auto_start" = "0" ]; then
313 echo "Skipping Ceph $name on $host... auto start is disabled"
318 if daemon_is_running
$name ceph-
$type $id $pid_file; then
319 echo "Starting Ceph $name on $host...already running"
323 get_conf copy_executable_to
"" "copy executable to"
324 if [ -n "$copy_executable_to" ]; then
325 scp
$binary "$host:$copy_executable_to"
326 binary
="$copy_executable_to"
333 if echo $name |
grep -q ^osd
; then
334 get_conf osd_data
"/var/lib/ceph/osd/$cluster-$id" "osd data"
335 get_conf fs_path
"$osd_data" "fs path" # mount point defaults so osd data
336 get_conf fs_devs
"" "devs"
337 if [ -z "$fs_devs" ]; then
338 # try to fallback to old keys
339 get_conf tmp_btrfs_devs
"" "btrfs devs"
340 if [ -n "$tmp_btrfs_devs" ]; then
341 fs_devs
="$tmp_btrfs_devs"
344 first_dev
=`echo $fs_devs | cut '-d ' -f 1`
348 get_conf lockfile
"/var/lock/subsys/ceph" "lock file"
349 lockdir
=`dirname $lockfile`
350 if [ ! -d "$lockdir" ]; then
354 get_conf asok
"$run_dir/$cluster-$type.$id.asok" "admin socket"
358 # Increase max_open_files, if the configuration calls for it.
359 get_conf max_open_files
"32768" "max open files"
361 # build final command
366 [ -z "$docrun" ] && get_conf_bool docrun
"0" "restart on core dump"
367 [ "$docrun" -eq 1 ] && wrap
="$BINDIR/ceph-run"
369 [ -z "$dovalgrind" ] && get_conf_bool valgrind
"" "valgrind"
370 [ -n "$valgrind" ] && wrap
="$wrap valgrind $valgrind"
372 [ -n "$wrap" ] && runmode
="-f &" && runarg
="-f"
373 [ -n "$max_open_files" ] && files
="ulimit -n $max_open_files;"
375 [ -n "$TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES" ] && tcmalloc
="TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=$TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES"
377 cmd
="$files $tcmalloc $wrap $cmd --cluster $cluster ${SET_CEPHUSER_ARGS} $runmode"
379 if [ $dofsmount -eq 1 ] && [ -n "$fs_devs" ]; then
380 get_conf pre_mount
"true" "pre mount command"
381 get_conf fs_type
"" "osd mkfs type"
383 if [ -z "$fs_type" ]; then
384 # try to fallback to old keys
385 get_conf tmp_devs
"" "btrfs devs"
386 if [ -n "$tmp_devs" ]; then
389 echo No filesystem
type defined
!
394 get_conf fs_opt
"" "osd mount options $fs_type"
395 if [ -z "$fs_opt" ]; then
396 if [ "$fs_type" = "btrfs" ]; then
397 #try to fallback to old keys
398 get_conf fs_opt
"" "btrfs options"
401 if [ -z "$fs_opt" ]; then
402 if [ "$fs_type" = "xfs" ]; then
403 fs_opt
="rw,noatime,inode64"
405 #fallback to use at least noatime
411 [ -n "$fs_opt" ] && fs_opt
="-o $fs_opt"
412 [ -n "$pre_mount" ] && do_cmd
"$pre_mount"
414 do_root_cmd_okfail
"mkdir -p $fs_path"
415 if [ "$fs_type" = "btrfs" ]; then
416 echo Mounting Btrfs on
$host:$fs_path
417 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"
419 echo Mounting
$fs_type on
$host:$fs_path
420 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"
422 if [ "$ERR" != "0" ]; then
428 echo Starting Ceph
$name on
$host...
429 get_conf pre_start_eval
"" "pre start eval"
430 [ -n "$pre_start_eval" ] && $pre_start_eval
431 get_conf pre_start
"" "pre start command"
432 get_conf post_start
"" "post start command"
433 [ -n "$pre_start" ] && do_cmd
"$pre_start"
434 do_cmd_okfail
"$cmd" $runarg
435 if [ "$ERR" != "0" ]; then
440 [ -n "$post_start" ] && do_cmd
"$post_start"
441 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && touch $lockfile
445 get_conf pre_stop
"" "pre stop command"
446 get_conf post_stop
"" "post stop command"
447 [ -n "$pre_stop" ] && do_cmd
"$pre_stop"
448 stop_daemon
$name ceph-
$type $pid_file
449 [ -n "$pidfile" ] && rm -f $pidfile
450 [ -n "$asok" ] && rm -f $asok
451 [ -n "$post_stop" ] && do_cmd
"$post_stop"
452 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
453 if [ $dofsumount -eq 1 ] && [ -n "$fs_devs" ]; then
454 echo Unmounting OSD volume on
$host:$fs_path
455 do_root_cmd
"umount $fs_path || true"
460 if daemon_is_running
$name ceph-
$type $id $pid_file; then
461 printf "$name: running "
462 do_cmd
"$BINDIR/ceph daemon $name version 2>/dev/null" ||
printf unknown
464 elif [ -e "$pid_file" ]; then
465 # daemon is dead, but pid file still exists
469 # daemon is dead, and pid file is gone
470 echo "$name: not running."
480 get_conf pre_forcestop
"" "pre forcestop command"
481 get_conf post_forcestop
"" "post forcestop command"
482 [ -n "$pre_forcestop" ] && do_cmd
"$pre_forcestop"
483 stop_daemon
$name ceph-
$type $pid_file -9
484 [ -n "$post_forcestop" ] && do_cmd
"$post_forcestop"
485 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
489 echo "killall ceph-$type on $host"
490 do_cmd
"pkill ^ceph-$type || true"
491 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
494 force-reload | reload
)
495 signal_daemon
$name ceph-
$type $pid_file -1 "Reloading"
499 $0 $options stop
$name
500 $0 $options start
$name
504 if daemon_is_running
$name ceph-
$type $id $pid_file; then
505 $0 $options stop
$name
506 $0 $options start
$name
508 echo "$name: not running."
514 [ -n "$log_dir" ] && do_cmd
"rm -f $log_dir/$type.$id.*"
518 echo removing all logs
519 [ -n "$log_dir" ] && do_cmd
"rm -f $log_dir/* || true"