diff --git a/presto-server-rpm/pom.xml b/presto-server-rpm/pom.xml
index 7e1686cc85c5..7741e9f9eb69 100644
--- a/presto-server-rpm/pom.xml
+++ b/presto-server-rpm/pom.xml
@@ -95,6 +95,12 @@
python
[2.4,)
+
+ /usr/sbin/useradd
+
+
+ /usr/sbin/groupadd
+
diff --git a/presto-server-rpm/src/main/resources/dist/etc/init.d/presto b/presto-server-rpm/src/main/resources/dist/etc/init.d/presto
index b982e454c362..8f5bca509ab3 100644
--- a/presto-server-rpm/src/main/resources/dist/etc/init.d/presto
+++ b/presto-server-rpm/src/main/resources/dist/etc/init.d/presto
@@ -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
@@ -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 $?
}
diff --git a/presto-server-rpm/src/main/rpm/postinstall b/presto-server-rpm/src/main/rpm/postinstall
index 49f2f1cc1961..f06cf7878edf 100644
--- a/presto-server-rpm/src/main/rpm/postinstall
+++ b/presto-server-rpm/src/main/rpm/postinstall
@@ -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
diff --git a/presto-server-rpm/src/main/rpm/preinstall b/presto-server-rpm/src/main/rpm/preinstall
index ba79d5e933d3..d36d8958bbe5 100644
--- a/presto-server-rpm/src/main/rpm/preinstall
+++ b/presto-server-rpm/src/main/rpm/preinstall
@@ -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 || :