gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:54:33 24 4
gpt4 key购买 nike

我试图让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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com