yum install acpid
chkconfig acpid on
When you press power-off button on chassis, an ACPI signal is generated. If OS have acpid daemon listen for that kind of signal, shutdown command will be issued instead of sudden power-off ( in case of power outage).
Showing posts with label centos. Show all posts
Showing posts with label centos. Show all posts
11/13/2013
11/03/2013
Centos: make on-boot startup script
This post guide how to make script that start up at boot time on CentOS.
Write a script named, e.g launchd, that follows the pattern below:
#!/bin/bash
# name of service
# chkconfig: 345 90 90
# description: describe what your script would do
start(){
# create a lock file
touch /var/lock/subsystem/launchd
# tasks to do on boot
}
stop(){
# remove the lock file
rm -f /var/lock/subsystem/launchd
# tasks to do to stop scripts
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
esac
# ------------------------------------------------------------------------------------
The line that starts with # chkconfig is required to let chkconfig utility know which levels to run this script, start and stop priority.
Put this script in /etc/init.d directory.
Run: chkconfig --add launchd so that chkconfig can recognize your script.
Run: chkconfig launchd on to enable the script at some run-levels.
If you look at other script in /etc/init.d, you will find all scripts have lock file created in start() and removed in stop().
Write a script named, e.g launchd, that follows the pattern below:
Sample script
#----------------------------------------------------------#!/bin/bash
# name of service
# chkconfig: 345 90 90
# description: describe what your script would do
start(){
# create a lock file
touch /var/lock/subsystem/launchd
# tasks to do on boot
}
stop(){
# remove the lock file
rm -f /var/lock/subsystem/launchd
# tasks to do to stop scripts
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
esac
# ------------------------------------------------------------------------------------
Elaboration
This script must implement at least start() for the system to call.The line that starts with # chkconfig is required to let chkconfig utility know which levels to run this script, start and stop priority.
Put this script in /etc/init.d directory.
Run: chkconfig --add launchd so that chkconfig can recognize your script.
Run: chkconfig launchd on to enable the script at some run-levels.
Lockfile
Lockfile lets the system know whether there has been a running instance of this script. When the system starts up your script, it checks if lock file exists or not so that it won't have to run the script again and similar for stop(). This is why the function stop() won't be called if you haven't created a lockfile earlier.If you look at other script in /etc/init.d, you will find all scripts have lock file created in start() and removed in stop().
Subscribe to:
Posts (Atom)