| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- #!/usr/bin/env bash
- #
- # emqx
- #
- # chkconfig: 2345 80 30
- # description: EMQX, a distributed, massively scalable, highly extensible MQTT message broker written in Erlang/OTP
- # processname: beam
- #
- # Source function library.
- # shellcheck disable=SC1091
- . /etc/rc.d/init.d/functions
- RETVAL=0
- PATH=/sbin:/usr/sbin:/bin:/usr/bin
- NAME=emqx
- DAEMON=/usr/bin/$NAME
- lockfile=/var/lock/subsys/$NAME
- mkdir -p /var/run/$NAME
- pidfile=/var/run/$NAME/$NAME.pid
- # Check for script, config and data dirs
- [ -x /usr/bin/$NAME ] || exit 0
- [ -d /etc/$NAME ] || exit 0
- [ -d /var/lib/$NAME ] || exit 0
- # Read configuration variable file if it is present and readable
- # shellcheck disable=SC1090
- [ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
- # `service` strips all environmental VARS so
- # if no HOME was set in /etc/sysconfig/$NAME then set one here
- # to the data directory for erlexec's sake
- if [ -z "$HOME" ]; then
- export HOME=
- fi
- status -p $pidfile -l "$(basename $lockfile)" $NAME >/dev/null 2>&1
- running=$?
- find_pid() {
- # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
- ps ax | grep -E "\-progname\s+$NAME\s" | awk '{print $1}'
- }
- check_pid_status() {
- local pid
- pid="$(find_pid)"
- if [ "$pid" = "" ]; then
- # prog not running?
- return 1
- else
- # running
- return 0
- fi
- }
- start() {
- # Start daemons.
- echo -n $"Starting emqx: "
- $DAEMON start
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- touch $lockfile
- find_pid > $pidfile
- success
- else
- failure $"$NAME start"
- fi
- echo
- return $RETVAL
- }
- stop() {
- # Stop daemon.
- echo -n $"Shutting down emqx: "
- $DAEMON stop 2>/dev/null
- for _ in $(seq 1 10); do
- sleep 1
- check_pid_status
- RETVAL=$?
- if [ $RETVAL -eq 1 ]; then
- break
- fi
- done
- if [ $RETVAL -eq 1 ]; then
- rm -f $lockfile $pidfile
- success
- echo && return 0
- else
- failure $"$NAME stop"
- echo && return 1
- fi
- }
- hardstop() {
- echo -n $"Shutting down $NAME: "
- su - emqx -c "ps -ef | grep -E '\-progname\s+$NAME\s' | awk '{print \$2}' | xargs kill -9"
- for _ in $(seq 1 10); do
- sleep 1
- check_pid_status
- RETVAL=$?
- if [ $RETVAL -eq 1 ]; then
- break
- fi
- done
- if [ $RETVAL -eq 1 ]; then
- rm -f $lockfile $pidfile
- success
- echo && return 0
- else
- failure $"$NAME hardstop"
- echo && return 1
- fi
- }
- # See how we were called.
- case "$1" in
- start)
- [ $running -eq 0 ] && exit 0
- start
- ;;
- stop)
- stop
- ;;
- restart|force-reload)
- [ $running -eq 0 ] && stop
- start
- ;;
- hardstop)
- [ $running -eq 0 ] || exit 0
- hardstop
- ;;
- condrestart|try-restart)
- [ $running -eq 0 ] || exit 0
- restart
- ;;
- status)
- status -p $pidfile -l "$(basename $lockfile)" $NAME
- ;;
- ping)
- $DAEMON ping || exit $?
- ;;
- *)
- echo $"Usage: $0 {start|stop|restart|force-reload|hardstop|condrestart|try-restart|status|ping}"
- exit 1
- esac
- exit $?
|