program self-start script is essentially a shell script. Take a simple Tomcat self-starting script as an example. Tomcat uses startup.sh in the installation directory to start and shutdown.sh to stop. We can write them into a startup script.
Create a self-starting script:
vim /etc/init.d/tomcat
Enter the following:
#!/bin/bash## Tomcat startup script for the Tomcat server## chkconfig: 345 80 20# description: start the tomcat deamon## Source function library. /etc/rc.d/init.d/functions
prog=tomcatJAVA_HOME=/Usr/java/jdk1.6.0_27export JAVA_HOMECATALANA_HOME=/usr/local/tomcatexport CATALINA_HOME
case "$1" instart)echo "Starting Tomcat..."$CATALANA_HOME/bin/startup.sh; ;
stop)echo "Stopping Tomcat..."$CATALANA_HOME/bin/shutdown.sh;;
restart)echo "Stopping Tomcat..."$CATALANA_HOME/Bin/shutdown.shsleep 2echoecho "Starting Tomcat..."$CATALANA_HOME/bin/startup.sh;;
*)echo "Usage: $prog {start|
Stop|
Restart}";;esacexit 0 Description: The startup script here can be divided into three parts, the first part is to declare the startup script and comments, the second part is to define the path variable, the third part is a case... In condition selection structure.
The first part 1) Because it is a shell script, you must have a #!/bin/bash line at the beginning, which means that the shell used is bash. 2) #chkconfig: 345 80 20 is to let the chkconfig command recognize this startup script, it must be there, and the rest with # are comments. 3). /etc/rc.d/init.d/functions executes the functions file in the current shell, not in the subshell. It is similar to library functions, and later startup scripts may call the underlying functions in functions.
Second part 1) Starting from prog=tomcat, set 3 variables, use prog to define the script name, JAVA_HOME to define the JDK installation directory, and CATALANA_HOME to define the tomcat installation directory. 2) The export command is to make the defined variables available in the subshell.
The third part 1) The third part is a case condition selection structure, the syntax structure is as follows:
case string in value 1) operation;; value 2) operation;; value 3) Operation;;...*) Operation;;esac2)$1 is a positional parameter. The positional parameter is a variable that is determined according to its position on the command line of the calling shell program, and is a parameter that is entered after the program name. The positional parameters are separated by spaces. The shell takes the first position parameter to replace $1 in the program file, the second replaces $2, and so on. 3) $CATALANA_HOME/bin/startup.sh means to start tomcat. 4) $CATALANA_HOME/bin/shutdown.sh means to stop tomcat. 5) Sleep 2 means sleep for 2 seconds. 6) exit 0 means exit.
DNS (Domain Name System), a distributed database on the Internet that maps domain names and IP addr
For beginner Linux (me too), I dont want to mess with Linux in the virtual machine, and I dont want
Slightly larger sites are inevitably load balanced, but hardware load balancing is expensive. There
Linux shared memory Shared memory is a memory area reserved by the system for communication between
Xauth: (stdin):1: bad display name "LSPPC-Lenny:1" in "ad
How to Migrate Account Information Between Linux Servers
Linux system PPPoE broadband connection setting method
Resolve VSFTP local users can not authenticate login problems
U disk installation Linux skills
Linux System Bash Vulnerability Fixing Method
Simple comparison of linear power supply, thyristor power supply, switching power supply circuit
Why is the linux system newly mounted partition already used more than 100 M space
Talking about the shallow learning: Talking about Linux learning direction and learning methods
Do we really need anti-virus software?
How to quickly upgrade the balloon recovery system level
Microsoft fixes serious vulnerability in Win7/Win8.1 Media Center
Win7 system computer boot found that the desktop QQ icon disappeared, how to do
How to set up Win8.1 personality theme problem
Windows 7 burn files support the new format - flash can also "engraved"
What should I do if the Win10 system cannot open the UEFI boot mode?