Startup script and cronolog log segmentation

Startup script and cronolog log segmentation

Related reference materials: Install cronolog cronolog is a simple log splitting plug-in. A common classic application is to split a single huge log of Apache and save and install it by date: -------------- -------------------------------------------------- ------------

 $ wget
$ 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 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 can be used to create a file without adding an error ok! Write a script file cam-hello with no extension for the self-starting program for your own web server: ------------------------------- ----------------------------------------------

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

DESC="cam hello"
test -f $DAEMON || exit 0

set -e
export PIDFILE=/var/run/${NAME}.pid
case "$1" in
echo -n "Starting $DESC: "
start-stop-daemon --start --make-pidfile --pidfile ${PIDFILE} --exec "$DAEMON" | $CRONOLOG &
echo -n "Stopping $DESC: "
start-stop-daemon --stop --pidfile ${PIDFILE} | $CRONOLOG
#/--exec $DAEMON
echo "$NAME."
if [-f ${PIDFILE} ]; then
### rest of shutdown ### 
exit 0
# 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/$ --exec $DAEMON
# 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."
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1

exit 0

-------------------------------------------------- --------------------------- --make-pidfile can create a self-starting file, which is misled by the imperfect program on the Internet, which can only start but not Stop service ==! The python script needs to be changed to an executable file, otherwise the log file cannot be run. The log file has a buffer and can be written to a certain length. It is very speechless (I thought that python can't do this in the experiment...) Deploy the self-starting program and copy it to/etc/rc .d/init.d/Modify the script file chmod 777 cam-hello Register:/etc/init.d# sudo update-rc.d cam defaults If you want to delete the start/stop links, then: sudo update-rc.d -f cam remove (Note: chkconfig --add autoruntest add service command is wrong, don’t use it! There is a loop between service apache2 and rsyslog if stopped) After the deployment is successful

/etc/init.d/cam-hello start
/etc/init.d/cam-hello restart
/etc/init.d/cam-hello stop
Reference: startup script and cronolog log segmentation-Cloud + Community-Tencent Cloud