FHS (Filesystem Hierarchy Standard)

注: 本ページでは主にLinuxについて述べている

initプログラムとは

詳細

http://cdn.memegenerator.net/instances/500x/46032666.jpg

(http://memegenerator.net/instance/46032666)

参考文献・リンク

3種類のinit

SysVinit

概要

参考

Upstart

概要

ツール

chkconfig --add <service>
chkconfig --level 345 <service> on
chkconfig --del <service>

update-rc.d <service> defaults
update-rc.d <service> start 20 3 4 5
update-rc.d -f <service>  remove

参考

systemd

概要

Fedora 20 (systemd環境)での chkconfig 実行例

$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description:    Fedora release 20 (Heisenbug)
Release:        20
Codename:       Heisenbug

$ chkconfig 

注記: この出力は SysV サービスのみであり、ネイティブな systemd のサービスは含まれていません。
      systemd services. SysV 設定のデータはネイティブな systemd の設定によって上書きされます。
      systemd サービスを一覧表示するには 'systemctl list-unit-files' を使用してください。
      特定のターゲットにおいて有効化されているサービスを確認するには、
      'systemctl list-dependencies [target]' 。

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
$ LANG=C chkconfig 

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

$ ls /etc/rc.d/init.d/
README  functions  netconsole  network

$ cat /etc/rc.d/init.d/README 
You are looking for the traditional init scripts in /etc/rc.d/init.d,
and they are gone?

Here's an explanation on what's going on:

You are running a systemd-based OS where traditional init scripts have
been replaced by native systemd services files. Service files provide
very similar functionality to init scripts. To make use of service
files simply invoke "systemctl", which will output a list of all
currently running services (and other units). Use "systemctl
list-unit-files" to get a listing of all known unit files, including
stopped, disabled and masked ones. Use "systemctl start
foobar.service" and "systemctl stop foobar.service" to start or stop a
service, respectively. For further details, please refer to
systemctl(1).

Note that traditional init scripts continue to function on a systemd
system. An init script /etc/rc.d/init.d/foobar is implicitly mapped
into a service unit foobar.service during system initialization.

Thank you!

Further reading:
        man:systemctl(1)
        man:systemd(1)
        http://0pointer.de/blog/projects/systemd-for-admins-3.html
        http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities

要するに

ツール

早見表

操作

SysV Init

Systemd

起動

/etc/init.d/sshd start

systemctl start sshd

終了

/etc/init.d/sshd stop

systemctl stop sshd

強制終了

PID探してkill -9

systemctl kill -s 9 sshd

再起動

/etc/init.d/sshd restart

systemctl restart sshd

設定反映

/etc/init.d/sshd reload

systemctl reload sshd

状態取得

/etc/init.d/sshd status

systemctl status sshd

自動起動を有効

chkconfig sshd on

systemctl enable sshd

自動起動を無効

chkconfig sshd off

systemctl disable sshd

自動起動の状態確認

chkconfig --list sshd

systemctl is-enabled sshd(status でも表示される)

サービス一覧の表示

ls /etc/init.d

systemctl --type service

Systemdコマンド早見表(CentOS 7対応)

sysv系との互換性について

参考: http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities/

参考

update-rc.d, insserv, sysv-rc-conf

insserv

(man insserv)
         ### BEGIN INIT INFO
         # Provides:          boot_facility_1 [ boot_facility_2 ...]
         # Required-Start:    boot_facility_1 [ boot_facility_2 ...]
         # Required-Stop:     boot_facility_1 [ boot_facility_2 ...]
         # Should-Start:      boot_facility_1 [ boot_facility_2 ...]
         # Should-Stop:       boot_facility_1 [ boot_facility_2 ...]
         # X-Start-Before:    boot_facility_1 [ boot_facility_2 ...]
         # X-Stop-After:      boot_facility_1 [ boot_facility_2 ...]
         # Default-Start:     run_level_1 [ run_level_2 ...]
         # Default-Stop:      run_level_1 [ run_level_2 ...]
         # X-Interactive:     true
         # Short-Description: single_line_description
         # Description:       multiline_description
         ### END INIT INFO
Provides: boot_facility_1 [boot_facility_2...]
boot facilities provided by this init script. When an init script is run with a start argument, the boot facility or facilities specified by the Provides keyword shall be deemed present and hence init scripts which require those boot facilities should be started later. When an init script is run with a stop argument, the boot facilities specified by the Provides keyword are deemed no longer present.
Required-Start: boot_facility_1 [boot_facility_2...]

facilities which must be available during startup of this service.
The init-script system should insure init scripts which provide the Required-Start facilities are started before starting this script.

Required-Stop: boot_facility_1 [boot_facility_2...]

facilities which must be available during the shutdown of this service.
The init-script system should avoid stopping init scripts which provide the Required-Stop facilities until this script is stopped.

Should-Start: boot_facility_1 [boot_facility_2...]

facilities which, if present, should be available during startup of this service.
This allows for weak dependencies which do not cause the service to fail if a facility is not available.
The service may provide reduced functionality in this situation. Conforming applications should not rely on the existence of this feature.

Should-Stop: boot_facility_1 [boot_facility_2...]
facilities which should be available during shutdown of this service.
Default-Start: run_level_1 [run_level_2...], Default-Stop: run_level_1 [run_level_2...]

which run levels should by default run the init script with a start (stop) argument to start (stop) the services controlled by the init script.
For example, if a service should run in runlevels 3, 4, and 5 only, specify "Default-Start: 3 4 5" and "Default-Stop: 0 1 2 6".

Short-Description: short_description
provide a brief description of the actions of the init script. Limited to a single line of text.
Description: multiline_description
provide a more complete description of the actions of the init script. May span mulitple lines. In a multiline description, each continuation line shall begin with a '#' followed by tab character or a '#' followed by at least two space characters. The multiline description is terminated by the first line that does not match this criteria.

参考. man insserv (info insserv)はあまり役に立たないので注意。

例: celerydをrabbitmq-serverの実行後に起動する

(実際にはこの作業自体はcelerydのためには必要ではない。念の為)

(/etc/insserv.conf の省略版)

$local_fs       +mountall +mountall-bootclean +mountoverflowtmp +umountfs
$network        +networking +ifupdown
$named          +named +dnsmasq +lwresd +bind9 +unbound $network
$remote_fs      $local_fs +mountnfs +mountnfs-bootclean +umountnfs +sendsigs
$syslog         +rsyslog +sysklogd +syslog-ng +dsyslog +inetutils-syslogd
$time           +hwclock
<interactive>   glibc udev console-screen keymap keyboard-setup console-setup cryptdisks cryptdisks-early checkfs-loop

(/etc/init.d/celecyd LSB)

### BEGIN INIT INFO
# Provides:          celeryd
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: celery task worker daemon
# Description:       Starts the Celery worker daemon for a single project.
### END INIT INFO

rabbitmq-serverあとに実行したいため、そのように設定を変更する。 ただしrabbitmq-serverアンインストール時にも一応起動だけするようにする。

(/etc/init.d/celecyd LSB)

### BEGIN INIT INFO
# Provides:          celeryd
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Should-Start:      rabbitmq-server
# Should-Stop:       rabbitmq-server
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: celery task worker daemon
# Description:       Starts the Celery worker daemon for a single project.
### END INIT INFO

> update-rc.d -n celeryd defaults
update-rc.d: using dependency based boot sequencing
insserv: remove service /etc/init.d/../rc0.d/K01rabbitmq-server
insserv: enable service ../init.d/rabbitmq-server -> /etc/init.d/../rc0.d/K02rabbitmq-server
insserv: remove service /etc/init.d/../rc1.d/K01rabbitmq-server
insserv: enable service ../init.d/rabbitmq-server -> /etc/init.d/../rc1.d/K02rabbitmq-server
insserv: remove service /etc/init.d/../rc2.d/S16celeryd
insserv: enable service ../init.d/celeryd -> /etc/init.d/../rc2.d/S19celeryd
insserv: remove service /etc/init.d/../rc3.d/S16celeryd
insserv: enable service ../init.d/celeryd -> /etc/init.d/../rc3.d/S19celeryd
insserv: remove service /etc/init.d/../rc4.d/S16celeryd
insserv: enable service ../init.d/celeryd -> /etc/init.d/../rc4.d/S19celeryd
insserv: remove service /etc/init.d/../rc5.d/S16celeryd
insserv: enable service ../init.d/celeryd -> /etc/init.d/../rc5.d/S19celeryd
insserv: remove service /etc/init.d/../rc6.d/K01rabbitmq-server
insserv: enable service ../init.d/rabbitmq-server -> /etc/init.d/../rc6.d/K02rabbitmq-server
insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop

適切に見えるので実行する。

> sudo update-rc.d celeryd defaults
update-rc.d: using dependency based boot sequencing

変更を確認する

> ls /etc/rc3.d
README         S16celerybeat   S16rabbitmq-server  S17lxc      S19atop     S19denyhosts  S19ssh      S20postfix
S01motd        S16celeryevcam  S16rsyslog          S18apache2  S19celeryd  S19docker     S19sysstat  S21bootlogs
S13rpcbind     S16munin        S16sudo             S19acpid    S19cron     S19mysql      S19winbind  S22rc.local
S14nfs-common  S16munin-node   S16zabbix-agent     S19atd      S19dbus     S19rsync      S20exim4    S22rmnologin

リンク

init (最終更新日時 2015-07-28 01:57:31 更新者 DaisukeMiyakawa)