Linux under service+ command and directly go to execute the difference of command, how to build a service start yourself

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.