Script d'init pour apache2
Options disponibles : start, stop, restart, condrestart, reload, status, fullstatus, graceful, help, configtest.
Voici la bête ! à copier coller dans un fichier nommé httpd dans /etc/rc.d/init.d/
#!/bin/bash # httpd Startup script for the Apache HTTP Server . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi HTTPD_LANG=${HTTPD_LANG-"C"} INITLOG_ARGS="" apachectl=/opt/httpd/bin/apachectl httpd=${HTTPD-/opt/httpd/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 check13 () { CONFFILE=/opt/httpd/conf/httpd.conf GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|" GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|" GONE="${GONE}AccessConfig|ResourceConfig)" if LANG=C grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then echo echo 1>&2 " Apache 1.3 configuration directives found" echo 1>&2 " please read /usr/share/doc/httpd-2.2.3/migration.html" failure "Apache 1.3 config directives test" echo exit 1 fi } start() { echo -n $"Starting $prog: " check13 || exit 1 LANG=$HTTPD_LANG daemon $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -d 10 $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else killproc $httpd -HUP RETVAL=$? fi echo } case "$1" in start) start ;; stop) stop ;; status) status $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL
Un petit chmod 755 httpd sera nécessaire, ensuite plus qu'a tester !
service httpd start ou invoke-rc.d httpd start
Intéressant à savoir l'option configtest qui parse vos fichiers de configuration et vous indique les erreurs de syntaxe, et l'option graceful qui elle redémarre votre apache sans coupure de service. Pour les options status et fullstatus il vous faudra les modules status et info.