Skip to content

Commit

Permalink
Run Presto server as presto user in RPM init.d scripts
Browse files Browse the repository at this point in the history
* Add presto user in preinstall
* Use presto user in init.d scripts
* Update file permissions so that the presto user can start presto
  • Loading branch information
cawallin authored and martint committed Oct 11, 2015
1 parent eda80b6 commit eee188f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions presto-server-rpm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
<name>python</name>
<version>[2.4,)</version>
</dependency>
<dependency>
<name>/usr/sbin/useradd</name>
</dependency>
<dependency>
<name>/usr/sbin/groupadd</name>
</dependency>
</dependencies>

<rules>
Expand Down
11 changes: 6 additions & 5 deletions presto-server-rpm/src/main/resources/dist/etc/init.d/presto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SCRIPT_NAME=$0
ACTION_NAME=$1
SERVICE_NAME='presto'
SERVICE_USER='presto'

# Launcher Config.
# Use data-dir from node.properties file (assumes it to be at /etc/presto). For other args use defaults from rpm install
Expand All @@ -33,28 +34,28 @@ start () {
if [ -z "$JAVA8_HOME" ]
then
echo "Warning: No value found for JAVA8_HOME. Default Java will be used."
/usr/lib/presto/bin/launcher start ${CONFIGURATION}
sudo -u $SERVICE_USER /usr/lib/presto/bin/launcher start ${CONFIGURATION}
else
PATH=${JAVA8_HOME}/bin:$PATH /usr/lib/presto/bin/launcher start "${CONFIGURATION[@]}"
sudo -u $SERVICE_USER PATH=${JAVA8_HOME}/bin:$PATH /usr/lib/presto/bin/launcher start "${CONFIGURATION[@]}"
fi
return $?
}

stop () {
echo "Stopping ${SERVICE_NAME} "
/usr/lib/presto/bin/launcher stop "${CONFIGURATION[@]}"
sudo -u $SERVICE_USER /usr/lib/presto/bin/launcher stop "${CONFIGURATION[@]}"
return $?
}

status () {
echo "Getting status for ${SERVICE_NAME} "
/usr/lib/presto/bin/launcher status "${CONFIGURATION[@]}"
sudo -u $SERVICE_USER /usr/lib/presto/bin/launcher status "${CONFIGURATION[@]}"
return $?
}


restart () {
/usr/lib/presto/bin/launcher restart "${CONFIGURATION[@]}"
sudo -u $SERVICE_USER /usr/lib/presto/bin/launcher restart "${CONFIGURATION[@]}"
return $?
}

Expand Down
9 changes: 7 additions & 2 deletions presto-server-rpm/src/main/rpm/postinstall
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Post installation script

# Dynamically populated directories that we expect to exist but do
# not want to remove when removing the RPM
install --directory --mode=775 /var/log/presto
# not want to remove when removing the RPM. Ideally, we would do this
# via the RPM building plugin, but adding empty directories is not
# supported.
install --directory --mode=755 /var/lib/presto
install --directory --mode=755 /var/log/presto
chown -R presto:presto /var/lib/presto
chown -R presto:presto /var/log/presto

# Populate node.id from uuidgen by replacing template with the node uuid
sed -i "s/\$(uuid-generated-nodeid)/$(uuidgen)/g" /etc/presto/node.properties
Expand Down
3 changes: 3 additions & 0 deletions presto-server-rpm/src/main/rpm/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ if [ "$java_found" = false ]; then
EOF
exit 1
fi

getent group presto >/dev/null || /usr/sbin/groupadd -r presto
getent passwd presto >/dev/null || /usr/sbin/useradd --comment "Presto" -s /sbin/nologin -g presto -r -d /var/lib/presto presto 2> /dev/null || :

0 comments on commit eee188f

Please sign in to comment.