1. Create a WebLogic startup script
Log in as root user and execute the following command to create a startup script:
# cd /etc/rc.d/init.d/ # vi weblogic
Add the following to the script:
#!/bin/bash # chkconfig: 345 20 80 # description: Weblogic Server auto start/stop script. # /etc/rc.d/init.d/weblogic # Please edit the variable export BEA_BASE=/home/weblogic/Oracle/Middleware export BEA_HOME=$BEA_BASE/Oracle_Home/user_projects/domains/server1/bin export BEA_LOG=$BEA_HOME/nohup.out #export PATH=$PATH:$BEA_HOME BEA_OWNR="weblogic" # if the executables do not exist -- display error if [ ! -f $BEA_HOME/startWebLogic.sh -o ! -d $BEA_HOME ] then echo "WebLogic startup: cannot start" exit 1 fi if [ -d /data ] then chown -R $BEA_OWNR:weblogic /data fi # depending on parameter -- startup, shutdown, restart case "$1" in start) echo -n "Starting WebLogic,log file $BEA_LOG: " touch /var/lock/weblogic chown -R $BEA_OWNR:weblogic $BEA_BASE su $BEA_OWNR -c "cd ${BEA_HOME}; nohup ./startWebLogic.sh > $BEA_LOG 2>&1 &" echo "OK" ;; stop) echo -n "Shutdown WebLogic: " rm -f /var/lock/weblogic chown -R $BEA_OWNR:weblogic $BEA_BASE su $BEA_OWNR -c "cd ${BEA_HOME}; ./stopWebLogic.sh >> $BEA_LOG" echo "OK" ;; reload|restart) $0 stop $0 start ;; *) echo "Usage: `basename $0` start|stop|restart|reload" exit 1 esac exit 0
2. Give executable permission
Excuting an order:
# chmod +x weblogic
3. Add to service list
# chkconfig --add weblogic
4. Check whether the addition is successful
# chkconfig --list | grep weblogic
weblogic 0 : off 1: off 2: off 3: on 4: on 5: on 6: off
5. How to use
Power on or restart the WebLogic Application Server weblogic service will start automatically.
Stop the WebLogic service
# service weblogic stop(或/etc/rc.d/init.d/weblogic stop)
Shutdown WebLogic: OK
(ps: weblogic generally cannot be turned off in this way, and generally needs to be killed by itself)
Start the WebLogic service
# service weblogic start(或/etc/rc.d/init.d/weblogic start)
Starting WebLogic,log file
/weblogic/bea/user_projects/domains/csky/weblogic.log: OK
Most of the above content here is reproduced from https://blog.csdn.net/sheen1991/article/details/47088131
6. Detailed command
(1) export: convert local variables to global variables (in fact, define a global environment variable)
(2) File comparison operator: (where we used -d and -f)
- e filename True if filename exists - d filename True if filename is a directory - f filename True if filename is a regular file - L filename True if filename is a symbolic link - r filename True if filename readable, true -w filename true if filename is writable -x filename true if filename is executable
(3)-o:
- o means either - a is and means - not means the opposite if [ ! -f $BEA_HOME/startWebLogic.sh -o ! -d $BEA_HOME ] So this sentence means that if startWebLogic.sh is not a file or the path corresponding to $BEA_HOME is not a folder, execute the following statement
(4) su command:
-c command: Change the account to the user of USER, and execute the command (command) before changing back to the original user.
(5) echo command:
echo - n output without wrapping $echo -n "123" $echo "456" final output 123456 instead of 123 456
(6) Difference between ">" and ">>" in linux
> Generating the content directly to the specified file will overwrite the content in the source file. Another purpose is to directly generate a blank file, which is equivalent to the touch command
>> Append at the end, which will not overwrite the original content in the file
(7) What does $1 mean?
$1 is called "positional parameter" in the shell, which means the first parameter passed in (the first input parameter). Used in the shell script body to indicate the first input parameter of the shell script. Used in shell script functions, it represents the first input parameter of the function. test -z $ 1 is a judgment expression used to judge whether the value of $1 is an empty string. If empty, the result is true; otherwise, false.
(8) What exactly does 2>&1 mean?
command > /dev/null is equivalent to command 1 > /dev/ null , then 2>&1 is easy to understand, 2 is standard error, 1 is standard output, then this command is not equivalent to resetting standard error Directed to standard output. etc. is &1 instead of 1, what is the & here? Here & is equivalent to standard output.
It may not be very clear. If you want to figure it out yourself, please see this post: https://blog.csdn.net/ggxiaobai/article/details/53507530