#This setup is for running Crush. The original script file from crush #has been rewritten. There is no longer a lock file, or PID file. The #lock and TID are found using ps. There is a java define added on the #command line, that puts the 'root' $CRUSH_DIR on the command line, so #that the proper java VM is accessed to know if crush is running, or #to properly kill the VM to stop crush. # #To setup, set $CRUSH_DIR, the $USER and the $QUIT_USER properly. #Then you will possibly edit $JAVA, $PS, $GREP, $WHOAMI or any other #variables at the start of the file, that are non-standard. # #NOTE Original documentation. # #The current working directory must be the same as the CrushFTP.jar file. #You cannot use "java -jar /opt/files/CrushFTP.jar or else CrushFTP #will be writing its temp files and working from the "/" dir. #Instead always do "cd /opt/files/" Then "java -jar CrushFTP.jar" #Additional options can be found with "java jar CrushFTP.jar -?". #"sudo" is needed as CrushFTP is using port 21 which is priviledged. #The below line is the simplest form for starting CrushFTP. #It is however commented out for a more robust method provided by another CrushFTP user. # #Daemon mode #sudo java -jar CrushFTP.jar -d # #GUI mode #sudo java CrushFTP.jar # # THESE NEED TO BE SET #crushftp directory: CRUSH_DIR="/usr/local/CrushFTP5_PC" #Only work for this user (NOTE if not root, then Crush will NOT work with port 21, and will #have to use the firewall to DNAT port 21 to a higher port number) USER='frame' #This user must be a 'valid' user, who has the SITE QUIT permission. #This user is used to do a server 'stop' or 'restart' QUIT_USER='frame_x' QUIT_PW="$2" # These commands may not be needed on all systems. Update them if needed. JAVA=java PS=ps AWK=awk GREP=grep SED=sed #WHOAMI=`whoami` #solaris whoami is not there. We 'fake' it out, pulling user name out of SET. Thus works 'ok' #except if the right user uses su to super to root, then runs this command, THEN the set #will still show the original user, even though root is now starting this script. However #I think that whoami does the same thing. WHOAMI=`set|$GREP LOGNAME|$SED 's/=/ /'|$AWK '{print $2}'` NOHUP=nohup # We MUST start the server in the proper directory. If we can not change to that # directory, we bail, and do not allow the script to continue. 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, like the original script did, 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}'`" } # 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 [ $WHOAMI = "$USER" ]; then echo "" else 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, shutdown the current running # server, or 'restart' the server. There is error checking to make sure the proper # user is the user which is running this script. This is done so that Crush can be run as # root user if wanted, but also can be run as non-root, specific user. ############################################################################################# 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 start 2 sessions in the same directory. echo "" exit 1; fi echo -n "Starting CrushFTP... " change_dir # run daemon if [ "$2" = "debug" ]; then $NOHUP $JAVA -Ddir=$CRUSH_DIR -Xmx384M -Dcrushftp.version=5 -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000 -jar CrushFTP.jar -d & >/dev/null 2>&1 else $NOHUP $JAVA -Ddir=$CRUSH_DIR -Xmx384M -Dcrushftp.version=5 -jar CrushFTP.jar -d & >/dev/null 2>&1 fi echo The server start command has been issued. The server should start shortly. echo "waiting upto 20s for the restart) ^C if you are not wanting to wait" i="0" while [ $i -lt 20 ] do get_pid if [ ! "$CRUSH_PID" ]; then echo . sleep 1; else echo The server has now started. echo "" exit 0 fi done echo "The server did not start (yet). Try running the script again." echo "" exit 1 ;; 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 echo "" exit 1 fi if [ "$QUIT_PW" ]; then echo -n Shutting down CrushFTP... ftp -n localhost 60021 <