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 1 commit
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
8 changes: 7 additions & 1 deletion dev-tools/packer/platforms/centos/init.j2
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ test_args="-e -configtest"
beat_user="${BEAT_USER:-root}"
wrapper="/usr/share/{{.beat_name}}/bin/{{.beat_name}}-god"
wrapperopts="-r / -n -p $pidfile -u $beat_user"
user_wrapper="su"
user_wrapperopts="$beat_user -c"
RETVAL=0

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

if [ -f /sbin/runuser ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than explicitly stating the path, I think it would be better to use the check described here. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

user_wrapper="runuser"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also need to update to user_wrapperopts="-u $beat_user"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's same argument and order. So I can reuse user_wrapperopts here.

fi

test() {
runuser -u $beat_user $agent $args $test_args
$user_wrapper $user_wrapperopts "$agent $args $test_args"
}

start() {
Expand Down
8 changes: 7 additions & 1 deletion dev-tools/packer/platforms/debian/init.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ SCRIPTNAME=/etc/init.d/$NAME
[ -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 [ -f /sbin/runuser ]; then
USER_WRAPPER="runuser"
fi

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
Expand All @@ -47,7 +53,7 @@ WRAPPER_ARGS="-r / -n -p $PIDFILE -u $BEAT_USER"
#
do_test()
{
runuser -u $DAEMON $DAEMON_ARGS $TEST_ARGS
$USER_WRAPPER $USER_WRAPPER_ARGS "$DAEMON $DAEMON_ARGS $TEST_ARGS"
}

#
Expand Down