Setting Crowd to Run Automatically and Use an Unprivileged System User on UNIX
This page contains some useful information about running Crowd under Linux/UNIX:
- Dedicated system user. For security reasons, and to keep your system administrator happy, you should probably create a dedicated non-root user to run Crowd.
- Automatic startup. It is useful to set up Crowd to run automatically on UNIX startup.
Running Crowd as an Unprivileged User
Here is an example of some of the changes you can make to harden up the directory and file permissions for Crowd to run as a non-root user.
You will need to update the environment variables to suit your installation. This is also for use in BASH. If you are using a different shell, you might need to tweak some things.
#!/bin/bash
CROWD_USER="crowd"
CROWD_GROUP="crowd"
INSTALL_BASE="/opt/crowd/atlassian-crowd-2.2.2"
CROWD_HOME="/var/crowd-home"
sudo chgrp ${CROWD_GROUP} ${INSTALL_BASE}/{*.sh,apache-tomcat/bin/*.sh}
sudo chmod g+x ${INSTALL_BASE}/{*.sh,apache-tomcat/bin/*.sh}
sudo chown -R ${CROWD_USER} ${CROWD_HOME} ${INSTALL_BASE}/apache-tomcat/{logs,work,temp}
sudo touch -a ${INSTALL_BASE}/atlassian-crowd-openid-server.log
sudo mkdir ${INSTALL_BASE}/database
sudo chown -R ${CROWD_USER} ${INSTALL_BASE}/{database,atlassian-crowd-openid-server.log}
Getting Crowd to Start Automatically
Create an
init.d file
(for example, 'crowd.init.d') inside your {CROWD_INSTALL
} directory:#!/bin/bash # Crowd startup script #chkconfig: 2345 80 05 #description: Crowd # Based on script at http://www.bifrost.org/problems.html RUN_AS_USER=crowd CATALINA_HOME=/opt/crowd/atlassian-crowd-2.2.2/apache-tomcat start() { echo "Starting Crowd: " if [ "x$USER" != "x$RUN_AS_USER" ]; then su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh" else $CATALINA_HOME/bin/startup.sh fi echo "done." } stop() { echo "Shutting down Crowd: " if [ "x$USER" != "x$RUN_AS_USER" ]; then su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh" else $CATALINA_HOME/bin/shutdown.sh fi echo "done." } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 10 #echo "Hard killing any remaining threads.." #kill -9 `cat $CATALINA_HOME/work/catalina.pid` start ;; *) echo "Usage: $0 {start|stop|restart}" esac exit 0
- Create a symbolic link from
/etc/init.d/crowd
to theinit.d file
file.
Hint for Red Hat systems
On Red Hat and Red Hat-based systems such as CentOS, if you put the above script in /etc/init.d
, you can create the necessary symbolic links with the chkconfig
script, since all the rrequired information is in the script header.
sudo /sbin/chkconfig --add SCRIPT_NAME
Replace "SCRIPT_NAME" with whatever the real name of the script is.
Thank you for this information
Thank you to Matthew Block and Pete Toscano for the original comments that we based this information on.