When starting some program services, sometimes go directly to the program's Bin directory to execute commands, sometimes using the service to start.
For example, when starting the MySQL service, most prefer to perform service mysqld start. Of course, you can also go to MySQL to execute the bin command with a few parameters or something.
So what's the service? Linux can be a man, to see that it is going to/ETC/INIT.D execute the executable shell script.
Service scripts are executed in the/ETC/INIT.D directory, and the commands executed under each of the programs are still under each bin.
This way we can also write a shell in this directory, imitating these programs to a.
First write a simple to explode service startup script.
# CD/ETC/INIT.D
# vi haha #这个脚本名字叫haha
#!/bin/SHEcho '$0='$0 '$1='$1start () {Echo 'ls'CD~ &&ls}stop () {Echo 'll'CD~ &&ls-L} Case " $" inch "Start") start;;"Stop") stop;;Esac
Execute permissions for this script such as # chmod +x haha
Do this:
# service haha start
# service haha stop
You can see the script output a bit $0,$1
$0=/etc/init.d/haha
$1=start or stop is the parameter of the haha script
Then start and stop execute a very simple command ~
As an example, the other script simply executes the command of its own command pack.
There is time to analyze the script for this nginx service Command mode:
Linux under service+ command and directly go to execute the difference of command, how to build a service start yourself