Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-root support in sysvinit script #4340

Merged
merged 5 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha1...master[Check the HEAD d

*Winlogbeat*


==== Added

*Affecting all Beats*

- Added the possibility to set Elasticsearch mapping template settings from the Beat configuration file. {pull}4284[4284] {pull}4317[4317]
- Add a variable to the SysV init scripts to make it easier to change the user. {pull}4340[4340]
- Add the option to write the generated Elasticsearch mapping template into a file. {pull}4323[4323]

*Filebeat*
Expand Down
13 changes: 10 additions & 3 deletions dev-tools/packer/platforms/centos/init.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: {{.beat_description}}
# Description: {{.beat_name}} is a shipper part of the Elastic Beats
# Description: {{.beat_name}} is a shipper part of the Elastic Beats
# family. Please see: https://www.elastic.co/products/beats
### END INIT INFO

Expand All @@ -27,8 +27,11 @@ pidfile=${PIDFILE-/var/run/{{.beat_name}}.pid}
agent=${BEATS_AGENT-/usr/share/{{.beat_name}}/bin/{{.beat_name}}}
args="-c /etc/{{.beat_name}}/{{.beat_name}}.yml -path.home /usr/share/{{.beat_name}} -path.config /etc/{{.beat_name}} -path.data /var/lib/{{.beat_name}} -path.logs /var/log/{{.beat_name}}"
test_args="-e -configtest"
beat_user="${BEAT_USER:-root}"
wrapper="/usr/share/{{.beat_name}}/bin/{{.beat_name}}-god"
wrapperopts="-r / -n -p $pidfile"
wrapperopts="-r / -n -p $pidfile -u $beat_user"
user_wrapper="su"
user_wrapperopts="$beat_user -c"
RETVAL=0

# Source function library.
Expand All @@ -41,8 +44,12 @@ if status | grep -q -- '-p' 2>/dev/null; then
pidopts="-p $pidfile"
fi

if runuser -v &> /dev/null; then
user_wrapper="runuser"
fi

test() {
$agent $args $test_args
$user_wrapper $user_wrapperopts "$agent $args $test_args"
}

start() {
Expand Down
11 changes: 10 additions & 1 deletion dev-tools/packer/platforms/debian/init.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DAEMON_ARGS="-c /etc/{{.beat_name}}/{{.beat_name}}.yml -path.home /usr/share/{{.
TEST_ARGS="-e -configtest"
PIDFILE=/var/run/{{.beat_name}}.pid
WRAPPER="/usr/share/{{.beat_name}}/bin/{{.beat_name}}-god"
BEAT_USER="root"
WRAPPER_ARGS="-r / -n -p $PIDFILE"
SCRIPTNAME=/etc/init.d/$NAME

Expand All @@ -30,6 +31,14 @@ SCRIPTNAME=/etc/init.d/$NAME
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

WRAPPER_ARGS="-r / -n -p $PIDFILE -u $BEAT_USER"
USER_WRAPPER="su"
USER_WRAPPER_ARGS="$BEAT_USER -c"

if runuser -v &> /dev/null; then
USER_WRAPPER="runuser"
fi

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

Expand All @@ -44,7 +53,7 @@ SCRIPTNAME=/etc/init.d/$NAME
#
do_test()
{
$DAEMON $DAEMON_ARGS $TEST_ARGS
$USER_WRAPPER $USER_WRAPPER_ARGS "$DAEMON $DAEMON_ARGS $TEST_ARGS"
}

#
Expand Down