Startup script and cronolog log Segmentation

Source: Internet
Author: User

Http://man.cx/start-stop-daemon (8) http://cronolog.org/usage.html http://book.opensourceproject.org.cn/lamp/ruby/railscook/opensource/0596527314/ I _0596527314_chp_13_sect_6.html
Install cronolog

Cronolog is a simple log splitting plug-in. Common typical applications are splitting a single huge log of apache and saving it by date.
Installation:

-----------------------------------------------------------------------------

 $ wget 
http://cronolog.org/download/cronolog-1.6.2.tar.gz
$ tar xvzf cronolog-1.6.2.tar.gz
$ cd cronolog-1.6.2
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

-----------------------------------------------------------------------------

Check where it is installed (which also requires the sudo permission ):
Which cronolog

Simple Test
$ Echo "This is a test." |/usr/bin/cronolog-o/var/log/www/% Y/access. % m-% d-% y. log

"-O" command to create a file without adding an error

OK!
Compile a self-starting program for your web server

Script File cam-hello without extension:

-----------------------------------------------------------------------------

#! /bin/sh
# example python daemon starter script
# based on skeleton from Debian GNU/Linux
# cliechti@gmx.net
# place the daemon scripts in a folder accessible by root. /usr/local/sbin is a good idea

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/usr/local/hello/python_server/HelloServer"
NAME=cam-hello
DESC="cam hello"
CRONOLOG="/usr/local/sbin/cronolog /var/log/www/cam/%Y/access.%m-%d-%y.log"
test -f $DAEMON || exit 0

set -e
export PIDFILE=/var/run/${NAME}.pid
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --make-pidfile --pidfile ${PIDFILE} --exec "$DAEMON" | $CRONOLOG &
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --pidfile ${PIDFILE} | $CRONOLOG
# \ --exec $DAEMON
echo "$NAME."
if [ -f ${PIDFILE} ]; then
rm ${PIDFILE}
fi
### rest of shutdown ###
exit 0
;;
#reload)
#
# If the daemon can reload its config files on the fly
# for example by sending it SIGHUP, do it here.
#
# If the daemon responds to changes in its config file
# directly anyway, make this a do-nothing entry.
#
# echo "Reloading $DESC configuration files."
# start-stop-daemon --stop --signal 1 --quiet --pidfile \
# /var/run/$NAME.pid --exec $DAEMON
#;;
restart|force-reload)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart".
#
echo -n "Restarting $DESC: "
start-stop-daemon --stop --pidfile ${PIDFILE}
# --exec $DAEMON
sleep 1
start-stop-daemon --start --make-pidfile --pidfile ${PIDFILE} --exec $DAEMON | $CRONOLOG &
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

exit 0

-----------------------------------------------------------------------------

-- Make-pidfile can be used to create a self-Startup File, Which is misled by incomplete programs on the Internet. As a result, the service can only be started and cannot be stopped =!
The python script must be changed to an executable file or cannot be run.
The log file has a buffer that can be written after a certain length. It is speechless (in this experiment, I thought python could not do this ....)
Deploy self-starting Program

Copy to/etc/rc. d/init. d/
Modify the script file chmod 777 cam-hello

Registration:
/Etc/init. d # sudo update-rc.d cam defaults
To delete start/stop links:
Sudo update-rc.d-f cam remove

(Note: The command chkconfig -- add autoruntest to add a service is incorrect. You don't need it!
There is a loop between service apache2 and rsyslog if stopped)

After successful deployment

/etc/init.d/cam-hello start
/etc/init.d/cam-hello restart
/etc/init.d/cam-hello stop

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.