设为首页 收藏本站
查看: 1131|回复: 0

[经验分享] 让阿帕奇-apache自动启动的办法

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-8-3 09:44:47 | 显示全部楼层 |阅读模式
由于要用到php5的一个新功能,不得不从source编译php5,从而打开了一个连锁反应,导致我的apache,mysql 全都要编译一遍,外加一个libxml的库,累得不轻。可是好戏还在后头,重新从source编译过来的apache启动时不自己起来,要去/usr/local/apache/bin里面手动起来,这可累坏了有省电习惯每天关机的我了。郁闷之极,决定搞个自动启动的脚本。会者不难,发现init.d下面有个skeleton,框架打好了,可以直接修改。改完后又修改了一下retry的超时,测试效果不错。
另外,做好的脚本还要挂到run level 2 3 4 5里面去,0 1 6是关机,冲启,单用户,需要设置为off.
下面推荐两个命令实现runlevel的挂接:
update-rc.d
sysv-rc-conf,如果没有装,就apt-get install 就OK啦
updaterc.d比较低层次,推荐sysv-rc-conf,它提供了命令行界面和类似top的基于文本的gui界面,界面还是比较友好的。就是没有发现可以控制运行顺序的选项。
下面是我的apache启动脚本:

  1 DSC0000.gif #! /bin/sh
  2### BEGIN INIT INFO
  3# Provides:          skeleton
  4# Required-Start:    $local_fs $remote_fs
  5# Required-Stop:     $local_fs $remote_fs
  6# Default-Start:     2 3 4 5
  7# Default-Stop:      0 1 6
  8# Short-Description: Example initscript
  9# Description:       This file should be used to construct scripts to be
10#                    placed in /etc/init.d.
11### END INIT INFO
12
13# Author: Foo Bar
14#
15# Please remove the "Author" lines above and replace them
16# with your own name if you copy and modify this script.
17
18# Do NOT "set -e"
19
20# PATH should only include /usr/* if it runs after the mountnfs.sh script
21#PATH=/sbin:/usr/sbin:/bin:/usr/bin
22DESC="Apache http service"
23NAME=httpd
24DAEMON=/usr/local/apache/bin/$NAME
25DAEMON_ARGS=""
26PIDFILE=/var/run/$NAME.pid
27SCRIPTNAME=/etc/init.d/$NAME
28
29# Exit if the package is not installed
30[ -x "$DAEMON" ] || exit 0
31
32# Read configuration variable file if it is present
33#[ -r /usr/local/apache/conf/httpd.conf ] && . /usr/local/apache/conf/httpd.conf
34
35# Load the VERBOSE setting and other rcS variables
36. /lib/init/vars.sh
37
38# Define LSB log_* functions.
39# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
40. /lib/lsb/init-functions
41
42#
43# Function that starts the daemon/service
44#
45do_start()
46{
47    # Return
48    #   0 if daemon has been started
49    #   1 if daemon was already running
50    #   2 if daemon could not be started
51    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
52        || return 1
53    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
54        $DAEMON_ARGS \
55        || return 2
56    # Add code here, if necessary, that waits for the process to be ready
57    # to handle requests from services started subsequently which depend
58    # on this one.  As a last resort, sleep for some time.
59}
60
61#
62# Function that stops the daemon/service
63#
64do_stop()
65{
66    # Return
67    #   0 if daemon has been stopped
68    #   1 if daemon was already stopped
69    #   2 if daemon could not be stopped
70    #   other if a failure occurred
71    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
72    RETVAL="$?"
73    [ "$RETVAL" = 2 ] && return 2
74    # Wait for children to finish too if this is a daemon that forks
75    # and if the daemon is only ever run from this initscript.
76    # If the above conditions are not satisfied then add some other code
77    # that waits for the process to drop all resources that could be
78    # needed by services started subsequently.  A last resort is to
79    # sleep for some time.
80    start-stop-daemon --stop --quiet --oknodo --retry=0/2/KILL/5 --exec $DAEMON
81    [ "$?" = 2 ] && return 2
82    # Many daemons don't delete their pidfiles when they exit.
83    rm -f $PIDFILE
84    return "$RETVAL"
85}
86
87#
88# Function that sends a SIGHUP to the daemon/service
89#
90do_reload() {
91    #
92    # If the daemon can reload its configuration without
93    # restarting (for example, when it is sent a SIGHUP),
94    # then implement that here.
95    #
96    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
97    return 0
98}
99
100case "$1" in
101  start)
102    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
103    do_start
104    case "$?" in
105        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
106        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
107    esac
108    ;;
109  stop)
110    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
111    do_stop
112    case "$?" in
113        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
114        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
115    esac
116    ;;
117  #reload|force-reload)
118    #
119    # If do_reload() is not implemented then leave this commented out
120    # and leave 'force-reload' as an alias for 'restart'.
121    #
122    #log_daemon_msg "Reloading $DESC" "$NAME"
123    #do_reload
124    #log_end_msg $?
125    #;;
126  restart|force-reload)
127    #
128    # If the "reload" option is implemented then remove the
129    # 'force-reload' alias
130    #
131    log_daemon_msg "Restarting $DESC" "$NAME"
132    do_stop
133    case "$?" in
134      0|1)
135        do_start
136        case "$?" in
137            0) log_end_msg 0 ;;
138            1) log_end_msg 1 ;; # Old process is still running
139            *) log_end_msg 1 ;; # Failed to start
140        esac
141        ;;
142      *)
143          # Failed to stop
144        log_end_msg 1
145        ;;
146    esac
147    ;;
148  *)
149    #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
150    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
151    exit 3
152    ;;
153esac
154
155:
156

可从这里下载文件

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-93549-1-1.html 上篇帖子: 配置IIS和Apache的HTTP压缩-Gzip (IIS 6.0配置Gzip Apache配置Gzip [转载] 下篇帖子: 【Django】Apache上运行多个Django项目
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表