ubuntu - 如何让 logstash 在 Ubuntu 12.04 上作为服务运行,其中该进程由 root 以外的用户拥有?

标签 ubuntu logstash init.d

我试图让logstash作为root以外的用户拥有的服务运行。 init.d 脚本如下:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          tlogserver
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Log Server
# Description:       Talend Logstash Service
### END INIT INFO
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin

if [ "X${TALEND_LOGSERV}" = "X" ]; then
  TALEND_LOGSERV="/opt/talend/logserv"
fi

if [ "X${TALEND_RUN}" = "X" ]; then
  TALEND_RUN="/opt/talend/run"
fi

DESC="Logstash service for the TAC"
APP_NAME="tlogserver"
DAEMON_START="${TALEND_LOGSERV}/start_logserver.sh"
DAEMON_START_ARGS=""
DAEMON_STOP="${TALEND_LOGSERV}/stop_logserver.sh"
DAEMON_STOP_ARGS=""
PIDFILE="${TALEND_RUN}/${APP_NAME}.pid"
RUN_AS="tomcat7"
RUN_GRP="tomcat7"
SCRIPTNAME="/etc/init.d/${APP_NAME}"

# Exit if the package is not installed
[ -x "${DAEMON_START}" ] || "The daemon is not installed"

# Read configuration variable file if it is present
[ -r /etc/default/${APP_NAME} ] && . /etc/default/${APP_NAME}

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start() {
  start-stop-daemon --start --quiet --background --chuid ${RUN_AS}:${RUN_GRP} --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON_START} --test > /dev/null \
    || return 1
  start-stop-daemon --start --quiet --background --chuid ${RUN_AS}:${RUN_GRP} --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON_START} -- \
    ${DAEMON_ARGS} \
    || return 2
}

#
# Function that stops the daemon/service
#
do_stop() {
  start-stop-daemon --start --quiet --background --chuid ${RUN_AS}:${RUN_GRP} --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON_STOP} --test > /dev/null \
    || return 1
  start-stop-daemon --start --quiet --background --chuid ${RUN_AS}:${RUN_GRP} --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON_STOP} -- \
    ${DAEMON_ARGS} \
    || return 2
}

case "$1" in
  start)
    [ "${VERBOSE}" != no ] && log_daemon_msg "Starting ${DESC}" "${APP_NAME}"
    do_start
    case "$?" in
      0|1) [ "${VERBOSE}" != no ] && log_end_msg 0 ;;
      2) [ "${VERBOSE}" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    [ "${VERBOSE}" != no ] && log_daemon_msg "Stopping ${DESC}" "${APP_NAME}"
    do_stop
    case "$?" in
      0|1) [ "${VERBOSE}" != no ] && log_end_msg 0 ;;
      2) [ "${VERBOSE}" != no ] && log_end_msg 1 ;;
    esac
    ;;
  restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting ${DESC}" "${APP_NAME}"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
          0) log_end_msg 0 ;;
          1) log_end_msg 1 ;; # Old process is still running
          *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
      *)
        # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
  *)
    echo "Usage: ${SCRIPTNAME} {start|stop|restart}" >&2
    exit 3
    ;;
esac

当我将它作为服务运行时,我得到了成功的返回码,但是当我查找它时,logstash 进程没有运行。 start_logserver 脚本如下:

if [ "X${TALEND_LOGSERV}" = "X" ]; then
  TALEND_LOGSERV="/opt/talend/logserv"
fi

cd "$TALEND_LOGSERV"
# ./logstash-1.4.2/bin/logstash agent -f logstash-talend.conf -l /var/log/talend/logserv.log > /dev/null 2>&1 < /dev/null &
echo "inside the start script...." >&2
echo `pwd` >&2
./logstash-1.4.2/bin/logstash agent -f logstash-talend.conf -l /var/log/talend/logserv.log
echo $!

最佳答案

logstash 的服务脚本可以为 sysv 生成/upstart/systemd和:

LS_HOME=/usr/share/logstash

# use ONE of the following:
${LS_HOME}/bin/system-install ${LS_HOME}/config/startup.options sysv
${LS_HOME}/bin/system-install ${LS_HOME}/config/startup.options upstart
${LS_HOME}/bin/system-install ${LS_HOME}/config/startup.options systemd

这些脚本运行为 logstash:logstash默认。

关于ubuntu - 如何让 logstash 在 Ubuntu 12.04 上作为服务运行,其中该进程由 root 以外的用户拥有?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32851394/

相关文章:

linux - Firefox 不加载虚拟主机网站而 chrome 加载虚拟主机网站

xml - 使用 Elasticsearch 地理功能从 XML 原始数据中查找最常见的位置

elasticsearch - Logstash Web界面仍然可用吗?

daemon - 如何为 Daemon-kit 项目设置 init.d rc 脚本?

python - cv2.convexityDefects 错误

ubuntu - 使用 deb intall 文件在 ubuntu 中安装 hadoop 1.0.1 后如何指定 HADOOP_HOME

elasticsearch - 使用或不使用Logstash过滤Filebeat输入

ubuntu - Supervisor 不会在 Ubuntu 16.04 上启动时启动

node.js - CentOS、Node.js、init.d、ENOENT,当应用程序自动启动时,无法在系统重新启动时打开或写入日志文件

bash - Unix 脚本无法更改 Ubuntu 上的 postgres hba.conf 配置文件