易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 993|回复: 0
收起左侧

keepalived 配置文件中 shell 脚本中case选择语句写法

[复制链接]
发表于 2022-2-25 09:51:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
cat /etc/init.d/keepalived
2 C2 v- F& A3 }. A3 G#! /bin/sh
4 M2 S  I( ?# U! L" P( v$ D* P#
4 q( s. q! t% T; w# keepalived   LVS cluster monitor daemon.
( u) {5 S( a, Z6 Z" p- ]#- P8 U8 {* [: e+ ]2 E, H
#              Written by Andres Salomon <dilinger@voxel.net>
7 q/ `. ~7 r  P9 v- t3 t$ Z/ v1 X#
6 i8 ^/ k8 M/ N* {6 d### BEGIN INIT INFO/ ^( ]5 z; e7 r  o
# Provides:          keepalived* ^/ p8 T. E: i4 a, e
# Required-Start:    $syslog $network $remote_fs
/ F: i) V, U( {% I: ]# Required-Stop:     $syslog $network $remote_fs
, [9 o0 |4 q5 u- @+ w6 D# Default-Start:     2 3 4 5
) }" ^$ X4 p' A+ e6 O3 f. t# Default-Stop:      0 1 6- \7 d2 Q" _8 D4 A0 X( B. t/ d& z/ t; a$ }
# Short-Description: Starts keepalived  x/ Q2 r- }( v' Z2 H
# Description:       Starts keepalived lvs loadbalancer+ E+ H% h( O& \8 y: s7 T! \& k
### END INIT INFO9 i5 q' D; w6 K/ \
PATH=/sbin:/bin:/usr/sbin:/usr/bin! l' G6 G4 u* o0 c' m
DAEMON=/usr/sbin/keepalived& b1 u+ C3 A  {) }+ J2 Y* \
NAME=keepalived
7 J1 Z$ O" T; h( }) G% rDESC=keepalived: @, v* W' j. O- K) ^' {
CONFIG=/etc/keepalived/keepalived.conf; c; y5 l6 i) `
TMPFILES="/tmp/.vrrp /tmp/.healthcheckers"' v* j, m; Q; ]1 a0 |  c: D, r
#includes lsb functions
1 [& Q; @; H  a/ m5 V' }& k) Z. /lib/lsb/init-functions
9 l' N  C4 z7 U+ Stest -f $CONFIG || exit 0
6 l9 x1 X# B& n/ Xtest -f $DAEMON || exit 0
$ ?" g8 n; `* H7 t' D
2 c0 E/ ]3 c! z5 E+ J+ @% w8 p0 L# Read configuration variable file if it is present* N: W+ Q- m) s  O! b  M0 A1 [; l( u
[ -r /etc/default/$NAME ] && . /etc/default/$NAME; u* o* ~" W2 U# }+ J8 [0 B! M
case "$1" in
. ]+ ]' S. O; K" d% R+ O! l3 H; f  start)
9 b! [1 J2 V1 m0 q" I/ D        log_daemon_msg "Starting $DESC" "$NAME"; F1 l  y1 e$ r5 W, P' N8 f" \( A
for file in $TMPFILES
0 x1 b% F6 D) Q# b& M# g7 A7 v6 X+ { do - s! L7 K2 p3 Y
         test -e $file && test ! -L $file && rm $file% A; P; o4 \, G& M/ U
done
! w, B8 j* d' T+ m4 s if start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
1 @" W  T5 j3 x               --exec $DAEMON -- $DAEMON_ARGS; then& I! @/ B' n9 m+ ^, ]
  log_end_msg 00 M0 {+ j0 N' |( I& c6 ?
else/ W& q2 s5 i- W# f; `
  log_end_msg 1: p. Q: y& @4 ^; o; E) w
fi
6 u, c- l' E6 X# ~$ A# \# B6 `       ;;
, K; n2 Y  }0 ~/ _0 K- B  stop)
2 L. P* X! m# n9 r6 W) V log_daemon_msg "Stopping $DESC" "$NAME"* Y- g  |9 {. `( s
if start-stop-daemon --oknodo --stop --quiet --pidfile /var/run/$NAME.pid \
9 w, b. O. F# L* D         --exec $DAEMON; then! T4 w. j4 C/ U4 R- J3 G: Q
  log_end_msg 03 ]+ N; f! j! R
else. v6 e$ ^5 {% F. R. f+ P$ y6 n
  log_end_msg 12 {; R6 G. w5 j/ y8 }" A( D) j
fi0 `* r" h  [9 `  e, z7 t6 m
       ;;) `1 x: m& q& m( b
  reload|force-reload)
7 F1 T) q+ |$ d log_action_begin_msg "Reloading $DESC configuration..."+ P" p7 Z% I1 X) X" {: [3 o2 k
       if start-stop-daemon --stop --quiet --signal 1 --pidfile \3 A( i. E0 H! ]- r
               /var/run/$NAME.pid --exec $DAEMON; then# {* z! N0 y, [9 B- u8 F+ j8 F* Y( _
        log_end_msg 0
0 x" X4 I6 K* \" P- {3 h8 c3 x else2 }' l- A& A5 v7 {
  log_action_end_msg 16 z1 E" F# Q1 [7 K( w( S
fi
% K2 S+ V, ?2 K) L       ;;
+ G# ~3 F. j% M- R$ y  restart)
2 N2 J: G) m% W0 O& }1 q+ T   log_action_begin_msg "Restarting $DESC" "$NAME"5 ^& D8 B8 v1 a2 w$ _1 P' X
        start-stop-daemon --stop --quiet --pidfile \% S& G8 Y- K+ w2 O: G
  /var/run/$NAME.pid --exec $DAEMON || true 3 v1 D. Y6 w9 C; c
       sleep 1- F/ U9 X( r, n
       if start-stop-daemon --start --quiet --pidfile \1 F' w8 H; s# e9 A
               /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_ARGS; then2 t5 K/ b* X0 |! k+ c! t5 n" N
        log_end_msg 0: }$ p, d6 c" i& }
else
5 i; }% h5 i; a3 ]' N/ V" x  log_end_msg 1" n7 F: J& w" I* E0 R! l. Z
fi- I% N1 r( X& A  P. c9 d" @, L
       ;;0 K# O4 Q: K% {4 w' ^. c' R
  *)
6 E; n! U+ b# }: H4 `       echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload|force-reload}" >&2- Q- s- Q8 b0 ~+ i* h
       exit 1
3 K' p) G6 t6 {  i       ;;
! {' E7 r% Y1 M+ J  `/ Kesac
* {! w+ }" \+ hexit 00 x3 q0 N2 y5 X6 I1 P
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-9 01:11 , Processed in 0.050438 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表