Forked from
DM / dm-docs
261 commits behind, 35 commits ahead of the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
dm-fs-service 3.35 KiB
#!/bin/sh
#
# dm-fs-service
#
# Starts the DM FileSystem Service
#
# chkconfig: 345 98 98
# description: controls DM FileSystem Service
### BEGIN INIT INFO
# Provides: dm-fs-service
# Required-Start: $local_fs dm-postgresql
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: controls DM FileSystem Service
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# For SELinux we need to use 'runuser' not 'su'
SU=su
if [ -x /sbin/runuser ]; then
SU=runuser
fi
# Check if we are root before running command
runCommand() {
_cmd="$@"
echo "COMMAND: $_cmd"
if [ `id -u` = 0 ]; then
$SU -l $DM_USER -c "_$cmd"
else
eval "$_cmd"
fi
}
# Set defaults for configuration variables
if [ -z $DM_ROOT_DIR ]; then
myDir=`dirname $0`
currentDir=`pwd` && cd $myDir/../..
export DM_ROOT_DIR=`pwd`
cd $currentDir
fi
DM_SETUP_FILE=$DM_ROOT_DIR/setup.sh
if [ ! -f $DM_SETUP_FILE ]; then
echo "Setup file $DM_SETUP_FILE does not exist."
exit 2
fi
. $DM_SETUP_FILE > /dev/null
mkdir -p ${DM_ROOT_DIR}/var/run
mkdir -p ${DM_ROOT_DIR}/var/log
#DM_USER=dm
DM_USER=`whoami`
DM_PORT=22236 # 222-DM
DM_HOST=0.0.0.0
DAEMON_CMD=${DM_ROOT_DIR}/lib/python/dm/fs_service/service/fsService.py
DAEMON_NAME="DmFsService"
PIDFILE=${DM_ROOT_DIR}/var/run/dm_fs_service.pid
DAEMON_ARGS="-d -p $PIDFILE --port $DM_PORT --host $DM_HOST --n-server-threads 12"
export DM_LOG_CONFIG_FILE=${DM_ROOT_DIR}/etc/dm.fsService.log.conf
# Determine SSL flags:
# DM_SERVICE_PROTOCOL=https
# DM_SERVICE_SSL_CERT_FILE=<cert path>
# DM_SERVICE_SSL_KEY_FILE=<key path>
# DM_SSL_CA_CERT_FILE=<ca cert path> (enables checking client certificates)
if [ "$DM_SERVICE_PROTOCOL" = "https" ]; then
if [ -z "$DM_SERVICE_SSL_CERT_FILE" ]; then
echo "Cannot start service using SSL: DM_SERVICE_SSL_CERT_FILE is not defined." && exit 2
fi
if [ -z "$DM_SERVICE_SSL_KEY_FILE" ]; then
echo "Cannot start service using SSL: DM_SERVICE_SSL_KEY_FILE is not defined." && exit 2
fi
DAEMON_ARGS="$DAEMON_ARGS -c $DM_SERVICE_SSL_CERT_FILE -k $DM_SERVICE_SSL_KEY_FILE"
# Client certificate will be checked if DM_SSL_CA_CERT_FILE is provided.
if [ ! -z "$DM_SSL_CA_CERT_FILE" ]; then
DAEMON_ARGS="$DAEMON_ARGS -C $DM_SSL_CA_CERT_FILE"
fi
fi
RETVAL=0
start() {
# Check if service is already running
status -p $PIDFILE > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -n $"Starting $DAEMON_NAME daemon: "
runCommand ${DAEMON_CMD} ${DAEMON_ARGS}
RETVAL=$?
[ $RETVAL -eq 0 ] && success $"$DAEMON_NAME startup" || failure $"$DAEMON_NAME startup"
echo
fi
return $RETVAL
}
stop() {
status -p $PIDFILE > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -n $"Stopping $DAEMON_NAME daemon: "
PID=`cat $PIDFILE`
kill $PID
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $PIDFILE && success $"$DAEMON_NAME shutdown" || failure $"$DAEMON_NAME shutdown"
echo
fi
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status -p $PIDFILE "$DAEMON_NAME"
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
RETVAL=2
esac
exit $RETVAL