service 命令無法辨識服務文件。RHEL6.9
我正在使用
rhel6.9
並且我已經將我的服務文件複製到/etc/systemd/system
和/usr/lib/systemd/system/
文件夾中。我以前使用過設置服務systemctl
,但我從未嘗試過使用 oldschoolservice
命令。現在,
service mytest start
不起作用,它說這是一項無法辨識的服務。在systemctl
你執行daemon-reload
中,但我該怎麼做service
呢?
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.d``init.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
腳本和 Upstart 的initctl
命令的包裝器,現在它是這兩者和 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