Php-fpm automatically starts Shell script upon startup

Source: Internet
Author: User

Php-fpm automatically starts Shell script upon startup

This article mainly introduces the php-fpm script for automatically starting Shell upon startup. The script in this article is just an example. In fact, after you compile and install the script, it is generated in the compilation directory, you only need to copy and use it. For more information, see

There are various versions of php-fpm automatic start scripts on the Internet. In fact, after you compile the script, the source directory has generated an automatic script. You can use it without any modifications.

?

1

Cp {php-5.3.x-source-dir}/sapi/fpm/init. d. php-fpm/etc/init. d/php-fpm

The php-fpm boot script is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

#! /Bin/sh

### BEGIN INIT INFO

# Provides: php-fpm

# Required-Start: $ remote_fs $ network

# Required-Stop: $ remote_fs $ network

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: starts php-fpm

# Description: starts the PHP FastCGI Process Manager daemon

### END INIT INFO

 

Prefix =/usr/local/php

Exec_prefix =$ {prefix}

 

Php_fpm_BIN =$ {exec_prefix}/sbin/php-fpm

Php_fpm_CONF =$ {prefix}/etc/php-fpm.conf

Php_fpm_PID =$ {prefix}/var/run/php-fpm.pid

 

Php_opts = "-- fpm-config $ php_fpm_CONF -- pid $ php_fpm_PID"

 

Wait_for_pid (){

Try = 0

 

While test $ try-lt 35; do

 

Case "$1" in

'Created ')

If [-f "$2"]; then

Try =''

Break

Fi

;;

 

'Removed ')

If [! -F "$2"]; then

Try =''

Break

Fi

;;

Esac

 

Echo-n.

Try = 'expr $ try + 1'

Sleep 1

 

Done

 

}

 

Case "$1" in

Start)

Echo-n "Starting php-fpm"

 

$ Php_fpm_BIN -- daemonize $ php_opts

 

If ["$? "! = 0]; then

Echo "failed"

Exit 1

Fi

 

Wait_for_pid created $ php_fpm_PID

 

If [-n "$ try"]; then

Echo "failed"

Exit 1

Else

Echo "done"

Fi

;;

 

Stop)

Echo-n "Gracefully shutting down php-fpm"

 

If [! -R $ php_fpm_PID]; then

Echo "warning, no pid file found-php-fpm is not running? "

Exit 1

Fi

 

Kill-QUIT 'cat $ php_fpm_PID'

 

Wait_for_pid removed $ php_fpm_PID

 

If [-n "$ try"]; then

Echo "failed. Use force-quit"

Exit 1

Else

Echo "done"

Fi

;;

 

Force-quit)

Echo-n "Terminating php-fpm"

 

If [! -R $ php_fpm_PID]; then

Echo "warning, no pid file found-php-fpm is not running? "

Exit 1

Fi

 

Kill-TERM 'cat $ php_fpm_PID'

 

Wait_for_pid removed $ php_fpm_PID

 

If [-n "$ try"]; then

Echo "failed"

Exit 1

Else

Echo "done"

Fi

;;

 

Restart)

$0 stop

$0 start

;;

 

Reload)

 

Echo-n "Reload service php-fpm"

 

If [! -R $ php_fpm_PID]; then

Echo "warning, no pid file found-php-fpm is not running? "

Exit 1

Fi

 

Kill-USR2 'cat $ php_fpm_PID'

 

Echo "done"

;;

 

*)

Echo "Usage: $0 {start | stop | force-quit | restart | reload }"

Exit 1

;;

 

Esac

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.