GNU/Linux >> Linux の 問題 >  >> Linux

初心者向けのLinuxサービスコマンドチュートリアル(例付き)

serviceコマンドを使用すると、SystemVinitスクリプトを実行できます。このチュートリアルでは、わかりやすい例を使用して、このツールについて簡単に説明します。ただし、その前に、ここでのすべての例がUbuntu18.04LTSマシンでテストされていることを言及する価値があります。

Linuxサービスコマンド

Linuxで使用できるserviceコマンドの構文は次のとおりです。

service SCRIPT COMMAND [OPTIONS]

service --status-all

service --help | -h | --version

そして、manページで説明されているのは次のとおりです。

service  runs  a System V init script or systemd unit 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. The  existence of  a  systemd unit of the same name as a script in /etc/init.d
will cause the unit 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, start, stop, status, and reload are passed through to their systemctl/initctl
equivalents.

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.

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.
サービスコマンドの使用方法

'service'コマンドラインツールの使用法はまったく複雑ではありません。 httpdやsshdなどのスクリプトの処理に関してこのユーティリティをどのように使用できるかについて話しましょう。

サービスを使用してスクリプトを実行する方法は次のとおりです。

service httpd start

サービスを使用してすでに実行中のスクリプトを停止する方法は次のとおりです。

service sshd stop

スクリプトのステータスを取得する方法は次のとおりです。

service httpd status

サービスを再起動してすでに実行している方法は次のとおりです。

service sshd restart
結論

Linuxユーザーとしての特権によっては、「sudo」コマンドを使用して上記のすべての例を実行することをお勧めします。 'service'コマンドの詳細については、そのマニュアルページにアクセスしてください。


Linux
  1. Linuxは初心者向けのコマンドチュートリアルを展開します(例付き)

  2. 初心者向けのLinuxファクターコマンドチュートリアル(例付き)

  3. 初心者向けのLinuxtacコマンドチュートリアル(例付き)

  1. Linuxユーザー初心者向けコマンドチュートリアル(例付き)

  2. 初心者向けのLinuxsumコマンドチュートリアル(例付き)

  3. 初心者向けのLinuxbasenameコマンドチュートリアル(例付き)

  1. Linux yes初心者向けコマンドチュートリアル(例付き)

  2. 初心者向けのLinuxnprocコマンドチュートリアル(例付き)

  3. 初心者向けのLinuxsleepコマンドチュートリアル(例付き)