Good day,programmers. I have a problem. Please help. I am creating a service, which must load automatically when Linux is being loaded. So,I copied the script into the directory /etc/rc.d/init.d or /etc/init.d/. But when I am preforming the command
chkconfig --add listOfProcesses
an error occurs:
service listOfProcesses doesn't support chkconfig
Here is the content of the script. I have found the first version in the Google and have used it as a pattern.
#!/bin/bash # listOfProcesses Start the process which will show the list of processes # chkconfig: 345 110 02 # description: This process shows current time and the list of processes # processname: listOfProcesses ### BEGIN INIT INFO # Provides: # Required-Start: # Required-Stop: # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: shows current time and the list of processes # Description: This process shows current time and the list of processes ### END INIT INFO # Source function library. KIND="listOfProcesses" start() { echo -n $"Starting $KIND services: " daemon /home/myscript echo } stop() { echo -n $"Shutting down $KIND services: " killproc /home/myscript echo } restart() { echo -n $"Restarting $KIND services: " killproc /home/myscript daemon /home/myscript echo } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac exit $? exit 0;
The second version was made from the cron script. I found the cron script,copied it, and changed it, so I used it as the pattern.
#!/bin/sh # # crond Start/Stop the cron clock daemon. # # chkconfig: 2345 90 60 # description: cron is a standard UNIX program that runs user-specified \ # programs at periodic scheduled times. vixie cron adds a \ # number of features to the basic UNIX cron, including better \ # security and more powerful configuration options. ### BEGIN INIT INFO # Provides: crond crontab # Required-Start: $local_fs $syslog # Required-Stop: $local_fs $syslog # Default-Start: 2345 # Default-Stop: 90 # Short-Description: run cron daemon # Description: cron is a standard UNIX program that runs user-specified # programs at periodic scheduled times. vixie cron adds a # number of features to the basic UNIX cron, including better # security and more powerful configuration options. ### END INIT INFO rights=whoami; root=root; [ -f "$rights"=="$root" ] || { echo "this programme requires root rights"; exit 1; } # Source function library. . /etc/rc.d/init.d/functions start() { echo -n $"Starting $KIND services: "; daemon showListOfProcesses; } stop() { echo -n $"Shutting down $KIND services: "; killproc showListOfProcesses; } restart() { stop start } reload() { restart; } force_reload() { # new configuration takes effect after restart restart } case "$1" in start) start ;; stop) stop ;; restart) restart ;; reload) reload ;; force-reload) force_reload ;; *) echo $"Usage: $0 {start|stop|restart|reload|force-reload}" exit 2 esac exit $? # Show the list of processes function showListOfProcesses { top > /dev/tty2; }
But the situation hadn't changed. What is the problem? What is wrong in the script?
chkconfig command is used to list all available services and view or update their run level settings. In simple words it is used to list current startup information of services or any particular service, updating runlevel settings of service and adding or removing service from management.
Note: “chkconfig –add” only adds an existing service to the list of startup. If the service doesn't exist, you should first install it before adding it to the system startup list. While this is pretty obvious, it is worth to mention it, as a newbie might make this mistake.
The chkconfig tool is used in RedHat based systems (like CentOS) to control what services are started at which runlevels. Running the command chkconfig –list will display a list of services whether they are enabled or disabled for each runlevel.
Look at all the scripts that chkconfig
can turn on or off in /etc/rc.d/init.d, you'll notice that the top few comments are very important. See How-To manage services with chkconfig and service
#!/bin/sh # # crond Start/Stop the cron clock daemon. # # chkconfig: 2345 90 60 # description: cron is a standard UNIX program that runs user-specified \ # programs at periodic scheduled times. vixie cron adds a \ # number of features to the basic UNIX cron, including better \ # security and more powerful configuration options.
You have a script called listofprocesses
but to chkconfig
this script looks like crond
due to the 3rd line and thus it does not find any script called listofprocesses
You'll also most certainly want to change chkconfig: 2345 90 60
. Which says which run levels it should be on (in this case 2, 3, 4 and 5), what it's start order is (90) and what its kill order is (60).
You can check the service is correctly set up with chkconfig --list listofprocesses
.
Just add the following line at the top: # chkconfig: - 99 10
it should do the trick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With