服務命令無法辨識服務文件。 RHEL6.9

服務命令無法辨識服務文件。 RHEL6.9

我正在使用rhel6.9並將我的服務文件複製到/etc/systemd/system/usr/lib/systemd/system/資料夾中。我以前使用過設定服務systemctl,但從未嘗試過使用 oldschoolservice命令。

現在,service mytest start不起作用,它說這是一項無法識別的服務。你在systemctldaemon-reload,但我該怎麼辦呢service

答案1

service是一個「進階」指令,用於
不同 Unix 和 Linux 中的啟動、重新啟動、停止和狀態服務。根據「較低等級」服務管理器,服務在不同的二進位檔案上重新導向。

例如,在 CentOS 7 上它會重新導向到systemctl,而在 CentOS 6 上它直接呼叫相對/etc/init.d腳本。另一方面,在較舊的 Ubuntu 版本中,它會重新導向到新貴。

service 足以滿足基本的服務管理,而直接呼叫則systemctl 提供了更多的控制選項。

在 RHEL6 中,您首先新增服務:

chkconfig --add SERVICE

然後啟用或停用:

chkconfig SERVICE on
chkconfig SERVICE off

檢查服務是否啟用:

chkconfig SERVICE --list 

您也可以在 RHEL7 及更高版本中像這樣開啟服務,以便在下次啟動或其他觸發器時啟動:

systemctl enable SERVICE

systemctl請注意,如果保留,所有最新版本均假定為“.service”。

/etc/systemd/system/lircmd.service

變成:

systemctl enable lircmd

還將Systemd您過去使用的所有操作都帶到chkconfig一個service命令下,systemctl因此我通常發現從長遠來看更容易應對。

另請參閱man update-rc.d

update-rc.d 要求在所有腳本的腳本 LSB 註解標頭runlevel中提供依賴性和資訊。init.dinit.d

像這兒:

在腳本中加入這樣的區塊init.d

### 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


service 指令是包裝腳本,可讓系統管理員啟動、停止和檢查服務的狀態,而不必過度擔心init正在使用的實際系統。在systemd推出之前,它是/etc/init.d腳本和Upstartinitctl指令的包裝器,現在它也是這兩者和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).

也可以看看:

使用 systemd-and-systemctl-in-linux/ 管理服務

資料來源:

https://askubuntu.com/questions/903354/difference- Between-systemctl-and-service-commands

https://stackoverflow.com/questions/43537851/difference- Between-systemctl-and-service-command

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

service 與 systemctl 腳本-使用哪一個

https://wiki.debian.org/LSBInitScripts

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

相關內容