![Команда service не распознает файл службы. RHEL6.9](https://rvso.com/image/154482/%D0%9A%D0%BE%D0%BC%D0%B0%D0%BD%D0%B4%D0%B0%20service%20%D0%BD%D0%B5%20%D1%80%D0%B0%D1%81%D0%BF%D0%BE%D0%B7%D0%BD%D0%B0%D0%B5%D1%82%20%D1%84%D0%B0%D0%B9%D0%BB%20%D1%81%D0%BB%D1%83%D0%B6%D0%B1%D1%8B.%20RHEL6.9.png)
Я использую rhel6.9
и скопировал свой файл службы в обе папки /etc/systemd/system
и /usr/lib/systemd/system/
. Я настраивал службы, используя systemctl
раньше, но я никогда не пробовал это с service
командой старой школы.
Теперь service mytest start
не работает, пишет, что это неопознанная служба. В systemctl
вы запускаете daemon-reload
, но как мне это сделать с service
?
решение1
service
это команда "высокого уровня", используемая для запуска, перезапуска, остановки и статуса
служб в различных Unix и Linux. В зависимости от менеджера служб "низкого уровня" служба перенаправляется на различные двоичные файлы.Например, в CentOS 7 он перенаправляет на
systemctl
, а в CentOS 6 он напрямую вызывает соответствующий/etc/init.d
скрипт. С другой стороны, в более старых релизах Ubuntu он перенаправляет на upstart.сервиса достаточно для базового управления услугами, в то время как прямой вызов
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
runlevel
требует предоставления зависимостей и информации в init.d
заголовке комментария LSB всех 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-и-systemctl-в-linux/
Источники:
https://askubuntu.com/questions/903354/разница-между-systemctl-и-сервисными-командами
https://stackoverflow.com/questions/43537851/разница-между-systemctl-и-service-command
http://www.safdar.com/how-to/linux-services-systemctl-systemd-vs-service-sysvinit.html
скрипты service и systemctl — что использовать