服务命令无法识别服务文件。 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

相关内容