LoginSignup
3
2

More than 3 years have passed since last update.

Ubuntuのパッケージをアップデートした際にプロセス再起動が必要かを確認する

Posted at

はじめに

サーバー運用していると脆弱性対応などでパッケージのバージョンアップを行うことがよくあります。
その際、稼働中のサーバーへの影響の一つとしてサービスの再起動の発生が気になるところです。
今回はそういった場面で何を再起動したら良いかを確認する方法です。

コマンドインストール

Ubuntu では checkrestart コマンドで再起動が必要なプロセスを確認できます。
まず、コマンドのインストールですが、これは debian-goodies というパッケージに入っています。

パッケージインストール
$ sudo apt-get install debian-goodies

$ which checkrestart
/usr/sbin/checkrestart

再起動プロセスの確認

では実際にチェックしてみます。

再起動プロセス確認
$ sudo checkrestart
Found 30 processes using old versions of upgraded files
(22 distinct programs)
(15 distinct packages)

Of these, 13 seem to contain systemd service definitions or init scripts which can be used to restart them.
The following packages seem to have definitions that could be used
to restart their services:
haveged:
    457 /usr/sbin/haveged
lvm2:
    429 /sbin/lvmetad
acpid:
    1225    /usr/sbin/acpid
cron:
    1214    /usr/sbin/cron
accountsservice:
    24306   /usr/lib/accountsservice/accounts-daemon
policykit-1:
    1281    /usr/lib/policykit-1/polkitd
at:
    1141    /usr/sbin/atd
rsyslog:
    1198    /usr/sbin/rsyslogd
open-iscsi:
    1144    /sbin/iscsid
    1145    /sbin/iscsid
unattended-upgrades:
    1279    /usr/share/unattended-upgrades/unattended-upgrade-shutdown
mdadm:
    1270    /sbin/mdadm
dbus:
    1173    /usr/bin/dbus-daemon
lxcfs:
    1143    /usr/bin/lxcfs

These are the systemd services:
systemctl restart accounts-daemon.service
systemctl restart polkitd.service

These are the initd scripts:
service haveged restart
service lvm2-lvmpolld restart
service lvm2 restart
service lvm2-lvmetad restart
service acpid restart
service cron restart
service atd restart
service rsyslog restart
service open-iscsi restart
service iscsid restart
service unattended-upgrades restart
service mdadm-waitidle restart
service mdadm restart
service dbus restart
service lxcfs restart

These processes (2) do not seem to have an associated init script to restart them:
isc-dhcp-client:
    980 /sbin/dhclient
dash:
    1637    /bin/dash

再起動が必要なプロセスがたくさん出てきました。
ここで出力されている内容は systemd または init で管理されているかどうかで変わります。

対応1:systemd または initd で管理されている場合

init で管理されている場合、以下の内容が出力されます。

出力内容
The following packages seem to have definitions that could be used
to restart their services:

この場合、対応については続きに出力されているように systemctl または service コマンドを使って再起動します。
ここでは cron の場合を例に対応します。

cron再起動
$ sudo service cron restart

対応2:systemd または initd で管理されていない場合

もう一つは以下の出力がされた場合の対応です。

出力内容
These processes (2) do not seem to have an associated init script to restart them:
isc-dhcp-client:
    980 /sbin/dhclient
dash:
    1637    /bin/dash

これはプロセスが initスクリプトに関連付けられていない場合に表示されます。
今回は dash を例に対応していきたいと思います。

まず、ここではプロセスIDが 1637 と表示されています。
それでは該当のプロセスIDが利用しているプログラムを確認します。

プログラム確認
$ cat /proc/1637/cmdline 
/bin/sh/opt/bitnami/mysql/bin/mysqld_safe--defaults-file=/opt/bitnami/mysql/my.cnf--mysqld=mysqld.bin--socket=/opt/bitnami/mysql/tmp/mysql.sock--datadir=/opt/bitnami/mysql/data--log-error=/opt/bitnami/mysql/data/mysqld.log--pid-file=/opt/bitnami/mysql/data/mysqld.pid--lower-case-table-names=1 

mysqlプロセスが利用していることがわかりました。
今回、bitnami 環境のため専用のスクリプト ctlscript.sh を使って再起動を行います。
まず、利用方法について確認です。

ctlscript.sh
$ sudo /opt/bitnami/ctlscript.sh --help
usage: /opt/bitnami/ctlscript.sh help
       /opt/bitnami/ctlscript.sh (start|stop|restart|status)
       /opt/bitnami/ctlscript.sh (start|stop|restart|status) mysql
       /opt/bitnami/ctlscript.sh (start|stop|restart|status) php-fpm
       /opt/bitnami/ctlscript.sh (start|stop|restart|status) apache
       /opt/bitnami/ctlscript.sh (start|stop|restart|status) subversion

help       - this screen
start      - start the service(s)
stop       - stop  the service(s)
restart    - restart or start the service(s)
status     - show the status of the service(s)

それでは mysql の再起動を行います。

myql再起動
$ sudo /opt/bitnami/ctlscript.sh restart mysql
Unmonitored mysql
/opt/bitnami/mysql/scripts/ctl.sh : mysql stopped
/opt/bitnami/mysql/scripts/ctl.sh : mysql  started at port 3306
Monitored mysql

以上で再起動完了です。

確認

checkrestart コマンドで確認してみます。

checkrestart
$ sudo checkrestart
Found 28 processes using old versions of upgraded files
(20 distinct programs)
(13 distinct packages)

Of these, 12 seem to contain systemd service definitions or init scripts which can be used to restart them.
The following packages seem to have definitions that could be used
to restart their services:
haveged:
    457 /usr/sbin/haveged
lvm2:
    429 /sbin/lvmetad
dbus:
    1173    /usr/bin/dbus-daemon
accountsservice:
    24306   /usr/lib/accountsservice/accounts-daemon
policykit-1:
    1281    /usr/lib/policykit-1/polkitd
at:
    1141    /usr/sbin/atd
rsyslog:
    1198    /usr/sbin/rsyslogd
open-iscsi:
    1144    /sbin/iscsid
    1145    /sbin/iscsid
lxcfs:
    1143    /usr/bin/lxcfs
mdadm:
    1270    /sbin/mdadm
acpid:
    1225    /usr/sbin/acpid
unattended-upgrades:
    1279    /usr/share/unattended-upgrades/unattended-upgrade-shutdown

These are the systemd services:
systemctl restart accounts-daemon.service
systemctl restart polkitd.service

These are the initd scripts:
service haveged restart
service lvm2-lvmpolld restart
service lvm2 restart
service lvm2-lvmetad restart
service dbus restart
service atd restart
service rsyslog restart
service open-iscsi restart
service iscsid restart
service lxcfs restart
service mdadm-waitidle restart
service mdadm restart
service acpid restart
service unattended-upgrades restart

These processes (1) do not seem to have an associated init script to restart them:
isc-dhcp-client:
    980 /sbin/dhclient

対応を行なった crondash の2つが出力されなくなったのが確認できました。

おわりに

パッケージをアップデートした際、再起動が必要かどうかが気になるところですがこのコマンドを使うことで解決できるのはとても助かるなと思いました。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2