Buona giornata, programmatori. Ho un problema. Per favore aiuto. Sto creando un servizio, che deve essere caricato automaticamente durante il caricamento di Linux. Così, ho copiato lo script nella directory /etc/rc.d/init.d o /etc/init.d/. Ma quando sto preformatura il comandoIl servizio non supporta chkconfig
chkconfig --add listOfProcesses
si verifica un errore:
service listOfProcesses doesn't support chkconfig
Ecco il contenuto dello script. Ho trovato la prima versione in Google e l'ho usata come 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;
La seconda versione è stata creata dallo script cron. Ho trovato lo script di cron, l'ho copiato e l'ho cambiato, quindi l'ho usato come 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;
}
Ma la situazione non era cambiata. Qual è il problema? Cosa c'è di sbagliato nella sceneggiatura?
Ma quando cambio il nome dello script si dice che il servizio non supporta chkc onfig. Il problema è stato risolto.Non so cosa volesse la bash, ma in un certo periodo questo script ha funzionato normalmente – user565447
Questa risposta in realtà non indica tutte le cause principali. Sì, la linea di riferimento potrebbe essere stata parzialmente da incolpare, ma la riga 'chkconfig:' ha un valore errato. ** La priorità iniziale dovrebbe essere un valore 0-99 **. –
Jake88