私は を使用しており、サービス ファイルをとフォルダーのrhel6.9
両方にコピーしました。 以前に を使用してサービスをセットアップしたことがありますが、oldschool コマンドで試したことはありません。/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
の最新バージョンでは、「.service」がsystemctl
省略されている場合は「.service」が想定されることに注意してください。
/etc/systemd/system/lircmd.service
次のように変わります:
systemctl enable lircmd
また、これまでとSystemd
を使用して行っていたすべての操作が1 つのコマンド にまとめられるため、長期的には、その方が対処しやすいと感じています。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 コマンドは、システム管理者が実際に使用しているシステムをあまり気にせずに、サービスを開始、停止、およびステータス確認できるようにするラッパー スクリプトです。systemdが導入される前は、スクリプトと Upstart のコマンドinit
のラッパーでしたが、現在はこれら 2 つと systemctl のラッパーでもあります。/etc/init.d
initctl
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).
参照:
Linux で systemd と systemctl を使用してサービスを管理する/
出典:
https://askubuntu.com/questions/903354/systemctl とサービス コマンドの違い
https://stackoverflow.com/questions/43537851/systemctl とサービス コマンドの違い
http://www.safdar.com/how-to/linux-services-systemctl-systemd-vs-service-sysvinit.html
サービス スクリプトと systemctl スクリプト - どちらを使用するか