Linux/etc/init. d/service script example, etcinit. d

Source: Internet
Author: User

Linux/etc/init. d/service script example, etcinit. d

1. Write the script and put it in the/etc/init. d/directory, and set the executable permission chmod + x scriptnamed.

2. The script contains several methods: start, stop, restart, and status,

The/opt/myservice. sh script can add the operations you want to perform.

Example:

#! /Bin/bash

# Chkconfig: 1234 90 60

# Default-Start: 2 3 4 5

# Default-Stop: S 0 1 6

# Description: Saves and restores system entropy pool \

# Higher quality random number generation

Servername = myservice

Serverdir =/opt/myservice

Binpath =/opt/myservice. sh

Prog = $ (basename $ binpath)

./Etc/init. d/functions

Restart (){

Stop

Start

}

Reload (){

Stop

Start

}

Start (){

Echo-n $ "Starting $ daemon :"

Daemon $ binpath start

Retval = $

Echo

[$ Retval-eq 0]

}

Stop (){

Echo-n $ "Stopping $ daemon :"

Daemon $ binpath stop

Retval = $

Echo

[$ Retval-eq 0]

}

Ha_status (){

# Status $ prog

Status $ prog

Ps-ef | grep $ prog & exit 0

}

Case "$1" in

Start)

$1

;;

Stop)

$1

;;

Reload)

$1

;;

Restart)

$1

;;

Status)

Ha_status

;;

*)

Echo "Usage: $0 {start | stop | reload | restart | status }"

Exit 1

Esac

3. Set chkconfig -- level 2345 scriptname on for startup.

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.