Der Servicebefehl erkennt die Servicedatei nicht. RHEL6.9

Der Servicebefehl erkennt die Servicedatei nicht. RHEL6.9

Ich verwende rhel6.9und habe meine Servicedatei in beide Ordner kopiert /etc/systemd/system. /usr/lib/systemd/system/Ich habe Dienste bereits mit eingerichtet systemctl, aber ich habe es noch nie mit dem Oldschool- serviceBefehl versucht.

service mytest startFunktioniert jetzt nicht, es heißt, dass es sich um einen nicht erkannten Dienst handelt. In systemctlführen Sie aus daemon-reload, aber wie mache ich das mit service?

Antwort1

serviceist ein „High-Level“-Befehl, der zum Starten, Neustarten, Stoppen und für Statusdienste
in verschiedenen Unix- und Linux-Versionen verwendet wird. Abhängig vom „Lower-Level“-Dienstmanager werden die Dienste auf unterschiedliche Binärdateien umgeleitet.

Unter CentOS 7 wird beispielsweise zu umgeleitet systemctl, während unter CentOS 6 das entsprechende Skript direkt aufgerufen wird /etc/init.d. In älteren Ubuntu-Versionen wird dagegen zu Upstart umgeleitet.

Der Dienst ist für die grundlegende Dienstverwaltung ausreichend, während ein direkter Anruf systemctl umfassendere Kontrollmöglichkeiten bietet.

In RHEL6 fügen Sie zuerst den Dienst hinzu:

chkconfig --add SERVICE

dann zum Aktivieren oder Deaktivieren:

chkconfig SERVICE on
chkconfig SERVICE off

Überprüfen Sie, ob der Dienst aktiviert ist:

chkconfig SERVICE --list 

Sie können in RHEL7 und höher den Dienst auch wie folgt aktivieren, um ihn beim nächsten Booten oder mit einem anderen Auslöser zu starten:

systemctl enable SERVICE

Beachten Sie, dass alle neueren Versionen systemctldie Erweiterung „.service“ annehmen, wenn sie weggelassen wird.

/etc/systemd/system/lircmd.service

Wird:

systemctl enable lircmd

Außerdem Systemdbringt es alles, was Sie früher gemacht haben chkconfig, serviceunter einen Befehl, systemctlsodass ich das auf lange Sicht im Allgemeinen leichter zu bewältigen finde.

Siehe auch man update-rc.d:

update-rc.d runlevelerfordert die Angabe von Abhängigkeiten und Informationen im init.dLSB-Kommentarkopf aller init.dSkripte.

Wie hier:

Fügen Sie im init.dSkript einen Block wie diesen hinzu:

### BEGIN INIT INFO
# Provides:          scriptname
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

https://wiki.debian.org/LSBInitScripts


Der Service-Befehl ist ein Wrapper-Skript, mit dem Systemadministratoren Dienste starten, stoppen und ihren Status prüfen können, ohne sich allzu viele Gedanken über das tatsächlich initverwendete System machen zu müssen. Vor der Einführung von systemd war es ein Wrapper für /etc/init.dSkripte und den Upstart- initctlBefehl, und jetzt ist es auch ein Wrapper für diese beiden und systemctl.

man service:

service(8)                                                                                              System Manager's Manual                                                                                              service(8)

NAME
       service - run a System V init script

SYNOPSIS
       service SCRIPT COMMAND [OPTIONS]

       service --status-all

       service --help | -h | --version

DESCRIPTION
       service runs a System V init script, systemd unit, or upstart job in as predictable an environment as possible, removing most environment variables and with the current working directory set to /.

       The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT, or the name of a systemd unit, or the name of an upstart job in /etc/init. The existence of a systemd unit or upstart job of the same name
       as a script in /etc/init.d will cause the unit/job to take precedence over the init.d script.  The supported values of COMMAND depend on the invoked script.  service passes COMMAND and OPTIONS to the init script  unmodified.
       For  systemd  units  or upstart jobs, start, stop, status, and reload are passed through to their systemctl/initctl equivalents. For upstart jobs, restart will call the upstart 'stop' for the job, followed immediately by the
       'start', and will exit with the return code of the start command.

       All scripts should support at least the start and stop commands.  As a special case, if COMMAND is --full-restart, the script is run twice, first with the stop command, then with the start command. This option has no  effect
       on upstart jobs.

       service  --status-all  runs  all  init  scripts,  in alphabetical order, with the status command.  The status is [ + ] for running services, [ - ] for stopped services and [ ? ] for services without a 'status' command.  This
       option only calls status for sysvinit jobs; upstart jobs can be queried in a similar manner with initctl list.

EXIT CODES
       service calls the init script and returns the status returned by it.

FILES
       /etc/init.d
              The directory containing System V init scripts.

       /etc/init
              The directory containing upstart jobs.

       /{lib,run,etc}/systemd/system
              The directories containing systemd units.

ENVIRONMENT
       LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, LC_IDENTIFICATION, LC_ALL, TERM, PATH
              The only environment variables passed to the init scripts.

SEE ALSO
       /etc/init.d/skeleton,
       update-rc.d(8),
       init(8),
       invoke-rc.d(8).
       systemctl(1).
       initctl(8).

Siehe auch:

Dienste verwalten mit systemd und systemctl in Linux/

Quellen:

https://askubuntu.com/questions/903354/unterschied-zwischen-systemctl-und-service-commands

https://stackoverflow.com/questions/43537851/unterschied-zwischen-systemctl-und-service-command

http://www.safdar.com/how-to/linux-services-systemctl-systemd-vs-service-sysvinit.html

Service- oder Systemctl-Skripte – welche sollen verwendet werden?

https://wiki.debian.org/LSBInitScripts

https://access.redhat.com/articles/1189123

verwandte Informationen