逆引きUNIXコマンド/サービス(デーモン)の起動・再起動・停止・状態取得
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* サービス(デーモン)の起動・再起動・停止・状態取得・servi...
serviceコマンドを利用することにより、サービス(デーモン)の...
本資料では、CentOS, Ubuntuを使って確認しました。
#contents
#htmlinsertpcsp(linux_ads_top.html,linux-sp.html)
* serviceコマンドの使いかた [#r4982e24]
serviceコマンドは以下のような使いかたになります。
service スクリプト コマンド オプション
スクリプトとは、/etc/init.d/にあるスクリプト名になります。~
以下のように、サービス(デーモン)のスクリプトがあります。
$ ls /etc/init.d/
NetworkManager hidd netconsole setr...
acpid hplip netfs single
anacron hsqldb netplugd smartd
atd httpd network smb
auditd ip6tables nfs squid
autofs ipmi nfslock sshd
:
:
* serviceコマンドの使用例(httpd) [#i67a2afb]
今回はApache(httpd)の起動・再起動・停止・状態取得をしてみ...
- CentOS
$ su -
パスワード:
# service httpd status
httpd is stopped
# service httpd start
Starting httpd: ...
# service httpd status
httpd (pid 7574) is running...
# service httpd restart
Stopping httpd: ...
Starting httpd: ...
# service httpd status
httpd (pid 7606) is running...
# service httpd stop
Stopping httpd: ...
# service httpd status
httpd is stopped
- Ubuntu
$ sudo service apache2 status
Apache is NOT running.
$ sudo service apache2 start
* Starting web server apache2 ...
$ sudo service apache2 status
Apache is running (pid 2178).
$ sudo service apache2 restart
* Restarting web server apache2 ...
... waiting ...
$ sudo service apache2 status
Apache is running (pid 2281).
$ sudo service apache2 stop
* Stopping web server apache2 ...
... waiting ...
$ sudo service apache2 status
Apache is NOT running.
* /etc/init.dのスクリプトで起動・再起動・停止・状態取得を...
/etc/init.dのスクリプトでも同様のことができます。~
以下、Apache(httpd)の起動・再起動・停止・状態取得をしてみ...
-CentOS
# /etc/init.d/httpd status
httpd is stopped
# /etc/init.d/httpd start
Starting httpd: ...
# /etc/init.d/httpd status
httpd (pid 7764) is running...
# /etc/init.d/httpd restart
Stopping httpd: ...
Starting httpd: ...
# /etc/init.d/httpd status
httpd (pid 7786) is running...
# /etc/init.d/httpd stop
Stopping httpd: ...
# /etc/init.d/httpd status
httpd is stopped
-Ubuntu
$ sudo /etc/init.d/apache2 status
[sudo] password for sakura:
Apache is NOT running.
$ sudo /etc/init.d/apache2 start
* Starting web server apache2 ...
$ sudo /etc/init.d/apache2 status
Apache is running (pid 2446).
$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2 ...
... waiting ...
$ sudo /etc/init.d/apache2 status
Apache is running (pid 2546).
$ sudo /etc/init.d/apache2 stop
* Stopping web server apache2 ...
... waiting ...
$ sudo /etc/init.d/apache2 status
Apache is NOT running.
$
* serviceコマンドと/etc/init.dの違い [#g11a4ed4]
serviceコマンドはシェルスクリプトで作成されています。~
- Ubuntu
$ file /usr/sbin/service
/usr/sbin/service: POSIX shell script text executable
- CentOS
# file /sbin/service
/sbin/service: Bourne shell script text executable
serviceコマンドを確認したところ、以下の処理がありました。~
env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" ...
env -i により環境を引き継がず、LANG, PATH, TERMのみ環境変...
man envの-iオプションの抜粋です。
オプション
-, -i, --ignore-environment
継承された環境を無視して、空の環境から始め...
したがって、/etc/init.d/サービス名(スクリプト) コマンドと...
#htmlinsertpcsp(linux_ads_btm.html,linux-sp.html)
終了行:
#navi(../)
* サービス(デーモン)の起動・再起動・停止・状態取得・servi...
serviceコマンドを利用することにより、サービス(デーモン)の...
本資料では、CentOS, Ubuntuを使って確認しました。
#contents
#htmlinsertpcsp(linux_ads_top.html,linux-sp.html)
* serviceコマンドの使いかた [#r4982e24]
serviceコマンドは以下のような使いかたになります。
service スクリプト コマンド オプション
スクリプトとは、/etc/init.d/にあるスクリプト名になります。~
以下のように、サービス(デーモン)のスクリプトがあります。
$ ls /etc/init.d/
NetworkManager hidd netconsole setr...
acpid hplip netfs single
anacron hsqldb netplugd smartd
atd httpd network smb
auditd ip6tables nfs squid
autofs ipmi nfslock sshd
:
:
* serviceコマンドの使用例(httpd) [#i67a2afb]
今回はApache(httpd)の起動・再起動・停止・状態取得をしてみ...
- CentOS
$ su -
パスワード:
# service httpd status
httpd is stopped
# service httpd start
Starting httpd: ...
# service httpd status
httpd (pid 7574) is running...
# service httpd restart
Stopping httpd: ...
Starting httpd: ...
# service httpd status
httpd (pid 7606) is running...
# service httpd stop
Stopping httpd: ...
# service httpd status
httpd is stopped
- Ubuntu
$ sudo service apache2 status
Apache is NOT running.
$ sudo service apache2 start
* Starting web server apache2 ...
$ sudo service apache2 status
Apache is running (pid 2178).
$ sudo service apache2 restart
* Restarting web server apache2 ...
... waiting ...
$ sudo service apache2 status
Apache is running (pid 2281).
$ sudo service apache2 stop
* Stopping web server apache2 ...
... waiting ...
$ sudo service apache2 status
Apache is NOT running.
* /etc/init.dのスクリプトで起動・再起動・停止・状態取得を...
/etc/init.dのスクリプトでも同様のことができます。~
以下、Apache(httpd)の起動・再起動・停止・状態取得をしてみ...
-CentOS
# /etc/init.d/httpd status
httpd is stopped
# /etc/init.d/httpd start
Starting httpd: ...
# /etc/init.d/httpd status
httpd (pid 7764) is running...
# /etc/init.d/httpd restart
Stopping httpd: ...
Starting httpd: ...
# /etc/init.d/httpd status
httpd (pid 7786) is running...
# /etc/init.d/httpd stop
Stopping httpd: ...
# /etc/init.d/httpd status
httpd is stopped
-Ubuntu
$ sudo /etc/init.d/apache2 status
[sudo] password for sakura:
Apache is NOT running.
$ sudo /etc/init.d/apache2 start
* Starting web server apache2 ...
$ sudo /etc/init.d/apache2 status
Apache is running (pid 2446).
$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2 ...
... waiting ...
$ sudo /etc/init.d/apache2 status
Apache is running (pid 2546).
$ sudo /etc/init.d/apache2 stop
* Stopping web server apache2 ...
... waiting ...
$ sudo /etc/init.d/apache2 status
Apache is NOT running.
$
* serviceコマンドと/etc/init.dの違い [#g11a4ed4]
serviceコマンドはシェルスクリプトで作成されています。~
- Ubuntu
$ file /usr/sbin/service
/usr/sbin/service: POSIX shell script text executable
- CentOS
# file /sbin/service
/sbin/service: Bourne shell script text executable
serviceコマンドを確認したところ、以下の処理がありました。~
env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" ...
env -i により環境を引き継がず、LANG, PATH, TERMのみ環境変...
man envの-iオプションの抜粋です。
オプション
-, -i, --ignore-environment
継承された環境を無視して、空の環境から始め...
したがって、/etc/init.d/サービス名(スクリプト) コマンドと...
#htmlinsertpcsp(linux_ads_btm.html,linux-sp.html)
ページ名: