Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # Control script for CrushFTP
- #
- # chkconfig: - 86 14
- # description: CrushFTP
- #
- ### BEGIN INIT INFO
- # Provides: crushftp_init.sh
- # Required-Start: $local_fs
- # Should-Start: $network
- # Required-Stop:
- # Should-Stop: $network
- # Default-Start: 2 3 5
- # Default-Stop: 2 5
- # Short-Description: CrushFTP Server
- # Description: Starts Crush on boot
- ### END INIT INFO
- # THESE NEED TO BE SET
- CRUSH_DIR="/var/opt/CrushFTP7_PC/" #crushftp directory
- USER="root" # only work for this user
- JAVA="java"
- PS="ps"
- AWK="awk"
- GREP="grep"
- WHOAMI="whoami"
- NOHUP="nohup"
- LC_ALL=en_US.UTF-8
- export LC_ALL=en_US.utf8
- # example of how to redirect a low port to a high port so Crush doesn't have to run as root
- # iptables -t nat -A PREROUTING -p tcp -m tcp --dport 21 -j REDIRECT --to-ports 2121
- # We MUST start the server in the proper directory. If we can not change to that directory, we exit.
- change_dir()
- {
- cd $CRUSH_DIR
- ret_val=$?
- if [ ${ret_val} -ne 0 ]; then
- echo FAIL
- echo could not change to CrushFTP directory
- echo the directory is setup as:
- echo $CRUSH_DIR
- exit 1
- fi
- }
- # get PID from process list. Not from a 'stored' file. Since Crush updates will
- # restart the server, but NEVER run this script, then if we stored off the PID into
- # a file, then after an update, this script would not be able to shut down the
- # process. We have added a couple greps into the get_pid() so that we 'know' we
- # are getting the proper PID if it exists.
- get_pid()
- {
- CRUSH_PID="`$PS -ef | $GREP java | $GREP $CRUSH_DIR | awk '{print $2}'`"
- CRUSH_PARENT="`$PS -ef | $GREP java | $GREP $CRUSH_DIR | awk '{print $3}'`"
- }
- # if the wrong user runs this script then BAIL. If this script should be run as user
- # OTHER than 'root' (or su or sudo), then you must redirect port 21 (or 22) up to a higher
- # port, such as 60021. iptables can do this well. Then setup the crush server to bind to
- # these higher ports. Running as non-root is much more secure. NOTE, it 'is' valid for root
- # to shut down the server (but not to start it, unless USER="root" is set at teh top of the file
- ROOT_OK=0
- chk_user()
- {
- if [ "$USER" != `whoami` ]; then
- if [ `whoami` = "root" -a "$ROOT_OK" = "1" ]; then
- # Not an error. Root user is OK here, even if 'not' the proper user (such as killing the process).
- echo
- else
- #echo FAIL
- echo "Wrong user. The user running this script MUST be $USER, but you are `whoami`"
- #exit 1;
- fi
- fi
- }
- #############################################################################################
- # Here is the 'main' script. We can either start the server, or shutdown the current #
- # running server. There is error checking to make sure the proper user is being used. #
- #############################################################################################
- case "$1" in
- start)
- chk_user
- get_pid
- if [ "$CRUSH_PID" ]; then
- echo FAIL
- echo Found an already running instance of CrushFTP.
- echo It is not valid o start 2 sessions in the same directory.
- exit 1;
- fi
- echo -n "Starting CrushFTP... "
- change_dir
- # run daemon
- #$NOHUP $JAVA -Ddir=$CRUSH_DIR -Xmx384M -jar CrushFTP.jar -d & >/dev/null 2>&1
- $NOHUP $JAVA -Ddir=$CRUSH_DIR -Xmx384M -jar plugins/lib/CrushFTPJarProxy.jar -d & >/dev/null 2>&1
- echo OK
- ;;
- stop)
- # root or $USER is ok to shut down the server.
- ROOT_OK=1
- chk_user
- get_pid
- if [ ! "$CRUSH_PID" ]; then
- echo FAIL
- echo Could not find Crush PID
- exit 1
- fi
- echo -n Shutting down CrushFTP...
- kill $CRUSH_PID
- ret_val=$?
- if [ ${ret_val} -ne 0 ]; then
- echo FAIL
- echo could not kill PID
- exit 1
- fi
- echo OK
- ;;
- status)
- get_pid
- if [ ! "$CRUSH_PID" ]; then
- echo stopped
- exit 3
- else
- if [ "$CRUSH_PARENT" = "1" ]; then
- echo "running as daemon (pid $CRUSH_PID)"
- else
- echo "running as user (pid $CRUSH_PID)"
- fi
- fi
- ;;
- *)
- echo "Usage: $0 [start|stop] NOTE you must be logged in as $USER to run this script"
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement