]> git.proxmox.com Git - ceph.git/blob - ceph/src/init-ceph.in
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / init-ceph.in
1 #!/bin/sh
2 # Start/stop ceph daemons
3 # chkconfig: 2345 60 80
4
5 ### BEGIN INIT INFO
6 # Provides: ceph
7 # Default-Start: 2 3 4 5
8 # Default-Stop: 0 1 6
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.
13 ### END INIT INFO
14
15 # TODO: on FreeBSD/OSX, use equivalent script file
16 if [ -e /lib/lsb/init-functions ]; then
17 . /lib/lsb/init-functions
18 fi
19
20 [ -z "$BUILD_DIR" ] && BUILD_DIR=build
21
22 if [ `dirname $0` = "." ] && [ $PWD != "/etc/init.d" ]; then
23 # looks like an autotools src dir build
24 BINDIR=.
25 SBINDIR=.
26 LIBEXECDIR=.
27 ETCDIR=.
28 ASSUME_DEV=1
29 else
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`
33 BINDIR=bin
34 SBINDIR=bin
35 LIBEXECDIR=$CEPH_ROOT/src
36 ETCDIR=.
37 ASSUME_DEV=1
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
44 else
45 BINDIR=@bindir@
46 SBINDIR=@sbindir@
47 LIBEXECDIR=@libexecdir@/ceph
48 ETCDIR=@sysconfdir@/ceph
49 ASSUME_DEV=0
50 fi
51 fi
52
53 if [ -n "$CEPH_BIN" ] && [ -n "$CEPH_ROOT" ] && [ -n "$CEPH_BUILD_DIR" ]; then
54 BINDIR=$CEPH_BIN
55 SBINDIR=$CEPH_ROOT/src
56 ETCDIR=$CEPH_BIN
57 LIBEXECDIR=$CEPH_ROOT/src
58 ASSUME_DEV=1
59 fi
60
61 if [ `uname` = FreeBSD ]; then
62 GETOPT=/usr/local/bin/getopt
63 else
64 GETOPT=getopt
65 fi
66
67 if id ceph > /dev/null 2>&1; then
68 SET_CEPHUSER_ARGS=" --setuser ceph --setgroup ceph"
69 fi
70
71 usage_exit() {
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"
80 printf "\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"
93 exit
94 }
95
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
99
100 . $LIBEXECDIR/ceph_common.sh
101
102 EXIT_STATUS=0
103
104 signal_daemon() {
105 name=$1
106 daemon=$2
107 pidfile=$3
108 signal=$4
109 action=$5
110 [ -z "$action" ] && action="Stopping"
111 printf "$action Ceph $name on $host..."
112 do_cmd "if [ -e $pidfile ]; then
113 pid=\`cat $pidfile\`
114 if ps -p \$pid -o args= | grep -q $daemon; then
115 cmd=\"kill $signal \$pid\"
116 printf \"\$cmd...\"
117 \$cmd
118 fi
119 fi"
120 echo done
121 }
122
123 daemon_is_running() {
124 name=$1
125 daemon=$2
126 daemon_id=$3
127 pidfile=$4
128 do_cmd "[ -e $pidfile ] || exit 1 # no pid, presumably not running
129 pid=\`cat $pidfile\`
130 ps -p \$pid -o args= | grep $daemon | grep -qwe -i.$daemon_id && exit 0 # running
131 exit 1 # pid is something else" "" "okfail"
132 }
133
134 stop_daemon() {
135 name=$1
136 daemon=$2
137 pidfile=$3
138 signal=$4
139 action=$5
140 [ -z "$action" ] && action="Stopping"
141 printf "$action Ceph $name on $host..."
142 do_cmd "if [ -e $pidfile ] ; then
143 pid=\`cat $pidfile\`
144 while ps -p \$pid -o args= | grep -q $daemon; do
145 cmd=\"kill $signal \$pid\"
146 printf \"\$cmd...\"
147 \$cmd
148 sleep 2
149 continue
150 done
151 fi"
152 echo done
153 }
154
155 ## command line options
156 options=
157
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:' -- "$@")
159 if [ $? != 0 ]
160 then
161 exit 1
162 fi
163
164 eval set -- "$OPTS"
165
166 dovalgrind=
167 docrun=
168 allhosts=0
169 monaddr=
170 dofsmount=1
171 dofsumount=0
172 verbose=0
173 use_default_conf=1
174
175 ## set variables like cluster or conf
176 [ -e /etc/sysconfig/ceph ] && . /etc/sysconfig/ceph
177 [ -e /etc/default/ceph ] && . /etc/default/ceph
178
179
180 while echo $1 | grep -q '^-'; do # FIXME: why not '^-'?
181 case $1 in
182 -v | --verbose)
183 verbose=1
184 ;;
185 --valgrind)
186 dovalgrind=1
187 ;;
188 --novalgrind)
189 dovalgrind=0
190 ;;
191 --allhosts | -a)
192 allhosts=1;
193 ;;
194 --restart)
195 docrun=1
196 ;;
197 --norestart)
198 docrun=0
199 ;;
200 -h | --help)
201 usage_exit
202 ;;
203 -m )
204 [ -z "$2" ] && usage_exit
205 options="$options $1"
206 shift
207 MON_ADDR=$1
208 ;;
209 --btrfs | --fsmount)
210 dofsmount=1
211 ;;
212 --nobtrfs | --nofsmount)
213 dofsmount=0
214 ;;
215 --btrfsumount | --fsumount)
216 dofsumount=1
217 ;;
218 --conf | -c)
219 [ -z "$2" ] && usage_exit
220 options="$options $1"
221 shift
222 use_default_conf=0
223 conf=$1
224 ;;
225 --cluster )
226 [ -z "$2" ] && usage_exit
227 options="$options $1"
228 shift
229 cluster=$1
230 ;;
231 --hostname )
232 [ -z "$2" ] && usage_exit
233 options="$options $1"
234 shift
235 hostname=$1
236 ;;
237 -- )
238 shift
239 break
240 ;;
241 *)
242 echo unrecognized option \'$1\'
243 usage_exit
244 ;;
245 esac
246 options="$options $1"
247 shift
248 done
249
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`
253 else
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"
259 fi
260 fi
261
262
263 verify_conf
264
265 command=$1
266 [ -n "$*" ] && shift
267
268 get_local_name_list
269 get_name_list "$@"
270
271 # Reverse the order if we are stopping
272
273 if [ "$command" = "stop" -o "$command" = "onestop" ]; then
274 for f in $what; do
275 new_order="$f $new_order"
276 done
277 what="$new_order"
278 fi
279
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/^\\.//'`
283 num=$id
284 name="$type.$id"
285
286 check_host $cluster || continue
287
288 binary="$BINDIR/ceph-$type"
289 cmd="$binary -i $id"
290 if [ $ASSUME_DEV -eq 1 ]; then
291 cmd="PATH=$PWD:$PATH $cmd"
292 fi
293
294 get_conf run_dir "/var/run/ceph" "run dir"
295
296 get_conf pid_file "$run_dir/$type.$id.pid" "pid file"
297
298 if [ ! -d $run_dir ]; then
299 install -d -m0770 -o ceph -g ceph /var/run/ceph
300 fi
301
302 if [ "$command" = "start" -o "$command" = "onestart" ]; then
303 if [ -n "$pid_file" ]; then
304 cmd="$cmd --pid-file $pid_file"
305 fi
306
307 get_conf log_dir "" "log dir"
308 [ -n "$log_dir" ] && do_cmd "mkdir -p $log_dir"
309
310 get_conf auto_start "" "auto start"
311 if [ "$auto_start" = "no" ] || [ "$auto_start" = "false" ] || [ "$auto_start" = "0" ]; then
312 if [ -z "$@" ]; then
313 echo "Skipping Ceph $name on $host... auto start is disabled"
314 continue
315 fi
316 fi
317
318 if daemon_is_running $name ceph-$type $id $pid_file; then
319 echo "Starting Ceph $name on $host...already running"
320 continue
321 fi
322
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"
327 fi
328 fi
329
330 # conf file
331 cmd="$cmd -c $conf"
332
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"
342 fi
343 fi
344 first_dev=`echo $fs_devs | cut '-d ' -f 1`
345 fi
346
347 # do lockfile, if RH
348 get_conf lockfile "/var/lock/subsys/ceph" "lock file"
349 lockdir=`dirname $lockfile`
350 if [ ! -d "$lockdir" ]; then
351 lockfile=""
352 fi
353
354 get_conf asok "$run_dir/$cluster-$type.$id.asok" "admin socket"
355
356 case "$command" in
357 start|onestart)
358 # Increase max_open_files, if the configuration calls for it.
359 get_conf max_open_files "32768" "max open files"
360
361 # build final command
362 wrap=""
363 runmode=""
364 runarg=""
365
366 [ -z "$docrun" ] && get_conf_bool docrun "0" "restart on core dump"
367 [ "$docrun" -eq 1 ] && wrap="$BINDIR/ceph-run"
368
369 [ -z "$dovalgrind" ] && get_conf_bool valgrind "" "valgrind"
370 [ -n "$valgrind" ] && wrap="$wrap valgrind $valgrind"
371
372 [ -n "$wrap" ] && runmode="-f &" && runarg="-f"
373 [ -n "$max_open_files" ] && files="ulimit -n $max_open_files;"
374
375 [ -n "$TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES" ] && tcmalloc="TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=$TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES"
376
377 cmd="$files $tcmalloc $wrap $cmd --cluster $cluster ${SET_CEPHUSER_ARGS} $runmode"
378
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"
382
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
387 fs_type="btrfs"
388 else
389 echo No filesystem type defined!
390 exit 0
391 fi
392 fi
393
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"
399 fi
400
401 if [ -z "$fs_opt" ]; then
402 if [ "$fs_type" = "xfs" ]; then
403 fs_opt="rw,noatime,inode64"
404 else
405 #fallback to use at least noatime
406 fs_opt="rw,noatime"
407 fi
408 fi
409 fi
410
411 [ -n "$fs_opt" ] && fs_opt="-o $fs_opt"
412 [ -n "$pre_mount" ] && do_cmd "$pre_mount"
413
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"
418 else
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"
421 fi
422 if [ "$ERR" != "0" ]; then
423 EXIT_STATUS=$ERR
424 continue
425 fi
426 fi
427
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
436 EXIT_STATUS=$ERR
437 continue
438 fi
439
440 [ -n "$post_start" ] && do_cmd "$post_start"
441 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && touch $lockfile
442 ;;
443
444 stop|onestop)
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"
456 fi
457 ;;
458
459 status)
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
463 printf "\n"
464 elif [ -e "$pid_file" ]; then
465 # daemon is dead, but pid file still exists
466 echo "$name: dead."
467 EXIT_STATUS=1
468 else
469 # daemon is dead, and pid file is gone
470 echo "$name: not running."
471 EXIT_STATUS=3
472 fi
473 ;;
474
475 ssh)
476 $ssh
477 ;;
478
479 forcestop)
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
486 ;;
487
488 killall)
489 echo "killall ceph-$type on $host"
490 do_cmd "pkill ^ceph-$type || true"
491 [ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile
492 ;;
493
494 force-reload | reload)
495 signal_daemon $name ceph-$type $pid_file -1 "Reloading"
496 ;;
497
498 restart|onerestart)
499 $0 $options stop $name
500 $0 $options start $name
501 ;;
502
503 condrestart)
504 if daemon_is_running $name ceph-$type $id $pid_file; then
505 $0 $options stop $name
506 $0 $options start $name
507 else
508 echo "$name: not running."
509 fi
510 ;;
511
512 cleanlogs)
513 echo removing logs
514 [ -n "$log_dir" ] && do_cmd "rm -f $log_dir/$type.$id.*"
515 ;;
516
517 cleanalllogs)
518 echo removing all logs
519 [ -n "$log_dir" ] && do_cmd "rm -f $log_dir/* || true"
520 ;;
521
522 *)
523 usage_exit
524 ;;
525 esac
526 done
527
528 exit $EXIT_STATUS