github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/src/saltbase/salt/etcd/initd (about) 1 #!/bin/bash 2 # 3 ### BEGIN INIT INFO 4 # Provides: etcd 5 # Required-Start: $local_fs $network $syslog 6 # Required-Stop: 7 # Default-Start: 2 3 4 5 8 # Default-Stop: 0 1 6 9 # Short-Description: The etcd key-value share configuration service. 10 # Description: This launches and controls the etcd daemon. 11 ### END INIT INFO 12 13 14 # PATH should only include /usr/* if it runs after the mountnfs.sh script 15 PATH=/sbin:/usr/sbin:/bin:/usr/bin 16 DESC="The etcd key-value share configuration service" 17 NAME=etcd 18 DAEMON=/usr/local/bin/$NAME 19 DAEMON_ARGS="-peer-addr $HOSTNAME:7001 -name $HOSTNAME" 20 DAEMON_LOG_FILE=/var/log/$NAME.log 21 PIDFILE=/var/run/$NAME.pid 22 SCRIPTNAME=/etc/init.d/$NAME 23 DAEMON_USER=etcd 24 25 # Exit if the package is not installed 26 [ -x "$DAEMON" ] || exit 0 27 28 # Read configuration variable file if it is present 29 [ -r /etc/default/$NAME ] && . /etc/default/$NAME 30 31 # Define LSB log_* functions. 32 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present 33 # and status_of_proc is working. 34 . /lib/lsb/init-functions 35 36 # 37 # Function that starts the daemon/service 38 # 39 do_start() 40 { 41 # Return 42 # 0 if daemon has been started 43 # 1 if daemon was already running 44 # 2 if daemon could not be started 45 start-stop-daemon --start --quiet --background --no-close \ 46 --make-pidfile --pidfile $PIDFILE \ 47 --exec $DAEMON -c $DAEMON_USER --test > /dev/null \ 48 || return 1 49 start-stop-daemon --start --quiet --background --no-close \ 50 --make-pidfile --pidfile $PIDFILE \ 51 --exec $DAEMON -c $DAEMON_USER -- \ 52 $DAEMON_ARGS >> $DAEMON_LOG_FILE 2>&1 \ 53 || return 2 54 } 55 56 # 57 # Function that stops the daemon/service 58 # 59 do_stop() 60 { 61 # Return 62 # 0 if daemon has been stopped 63 # 1 if daemon was already stopped 64 # 2 if daemon could not be stopped 65 # other if a failure occurred 66 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME 67 RETVAL="$?" 68 [ "$RETVAL" = 2 ] && return 2 69 # Many daemons don't delete their pidfiles when they exit. 70 rm -f $PIDFILE 71 return "$RETVAL" 72 } 73 74 75 case "$1" in 76 start) 77 log_daemon_msg "Starting $DESC" "$NAME" 78 do_start 79 case "$?" in 80 0|1) log_end_msg 0 || exit 0 ;; 81 2) verblog_end_msg 1 || exit 1 ;; 82 esac 83 ;; 84 stop) 85 log_daemon_msg "Stopping $DESC" "$NAME" 86 do_stop 87 case "$?" in 88 0|1) log_end_msg 0 ;; 89 2) exit 1 ;; 90 esac 91 ;; 92 status) 93 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? 94 ;; 95 96 restart|force-reload) 97 log_daemon_msg "Restarting $DESC" "$NAME" 98 do_stop 99 case "$?" in 100 0|1) 101 do_start 102 case "$?" in 103 0) log_end_msg 0 ;; 104 1) log_end_msg 1 ;; # Old process is still running 105 *) log_end_msg 1 ;; # Failed to start 106 esac 107 ;; 108 *) 109 # Failed to stop 110 log_end_msg 1 111 ;; 112 esac 113 ;; 114 *) 115 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 116 exit 3 117 ;; 118 esac