【linux】 rpmでインストールする際に実行されるスクリプトを確認する
PostgreSQLのRPMをインストールすると、合わせて「postgres」ユーザーが作られたり、サービス自動起動が設定されたりと色々勝手にやってくれるのですが、ユーザー作成やサービス自動起動設定を定義している記述は何を参照すれば確認できるのかまったくわかっていませんでした。
ようやくその謎も解けました。。
RMPファイルインストール、アンインストール時に実行するスクリプトがRPMファイルには設定されていたのですね。
RPMのインストール、アンインストール時に実行されるスクリプトは、--scripts
オプションを付けてrpmコマンドを実行することで確認することができます。
# rpm -qp --scripts <rpmファイル>
試にPostgreSQLのPRMスクリプト確認コマンド実行結果
[vagrant@redmine ~]$ rpm -qp --scripts postgresql94-server-9.4.2-1PGDG.rhel6.x86_64.rpm preinstall scriptlet (using /bin/sh): groupadd -g 26 -o -r postgres >/dev/null 2>&1 || : useradd -M -n -g postgres -o -r -d /var/lib/pgsql -s /bin/bash \ -c "PostgreSQL Server" -u 26 postgres >/dev/null 2>&1 || : postinstall scriptlet (using /bin/sh): chkconfig --add postgresql-9.4 /sbin/ldconfig # postgres' .bash_profile. # We now don't install .bash_profile as we used to in pre 9.0. Instead, use cat, # so that package manager will be happy during upgrade to new major version. echo "[ -f /etc/profile ] && source /etc/profile PGDATA=/var/lib/pgsql/9.4/data export PGDATA # If you want to customize your settings, # Use the file below. This is not overridden # by the RPMS. [ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile" > /var/lib/pgsql/.bash_profile chown postgres: /var/lib/pgsql/.bash_profile chmod 700 /var/lib/pgsql/.bash_profile preuninstall scriptlet (using /bin/sh): if [ $1 = 0 ] ; then /sbin/service postgresql-9.4 condstop >/dev/null 2>&1 chkconfig --del postgresql-9.4 fi postuninstall scriptlet (using /bin/sh): /sbin/ldconfig if [ $1 -ge 1 ]; then /sbin/service postgresql-9.4 condrestart >/dev/null 2>&1 fi [vagrant@redmine ~]$
これを見ると、PostgreSQLのPRMには下記4種類のスクリプトが設定されていることがわかります。
- preinstall (インストール前に実行)
- postinstall (インストール完了後に実行)
- preuninstall (アンインストール前に実行)
- postuninstall (兄インストール完了後に実行)
個別に見ていきます。
preinstall script
preinstall scriptlet (using /bin/sh): groupadd -g 26 -o -r postgres >/dev/null 2>&1 || : useradd -M -n -g postgres -o -r -d /var/lib/pgsql -s /bin/bash \ -c "PostgreSQL Server" -u 26 postgres >/dev/null 2>&1 || :
下記流れの処理を実行していますね。
- postgresグループ作成
- postgresユーザー作成
これで、RPMインストール時にどのタイミングでユーザーが作られているかの謎が解けました。
postinstall script
postinstall scriptlet (using /bin/sh): chkconfig --add postgresql-9.4 /sbin/ldconfig # postgres' .bash_profile. # We now don't install .bash_profile as we used to in pre 9.0. Instead, use cat, # so that package manager will be happy during upgrade to new major version. echo "[ -f /etc/profile ] && source /etc/profile PGDATA=/var/lib/pgsql/9.4/data export PGDATA # If you want to customize your settings, # Use the file below. This is not overridden # by the RPMS. [ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile" > /var/lib/pgsql/.bash_profile chown postgres: /var/lib/pgsql/.bash_profile chmod 700 /var/lib/pgsql/.bash_profile
完了後は下記流れの処理を実行しているのがわかります。
- postgresql-9.4サービス自動起動
- ldconfigコマンド実行
- /var/lib/pgsql/.bash_profile作成
- 上記ファイルのパーミッション変更
preuninstall script
preuninstall scriptlet (using /bin/sh): if [ $1 = 0 ] ; then /sbin/service postgresql-9.4 condstop >/dev/null 2>&1 chkconfig --del postgresql-9.4 fi
アンインストール前は下記の処理実施
- PostgreSQLサーバのサービス停止
- 自動起動設定削除
postuninstall script
postuninstall scriptlet (using /bin/sh): /sbin/ldconfig if [ $1 -ge 1 ]; then /sbin/service postgresql-9.4 condrestart >/dev/null 2>&1 fi
アンインストール完了時は下記処理実施
- ldconfigコマンド実行
- 上記コマンド実行成功時以外はサービス再起動
rpm queryオプション
rpmのmanからQUERYオプションについて確認してみました。 色々と見れる情報も多いんですね。
PACKAGE QUERY OPTIONS: --changelog Display change information for the package. -c, --configfiles List only configuration files (implies -l). -d, --docfiles List only documentation files (implies -l). --dump Dump file information as follows (implies -l): path size mtime digest mode owner group isconfig isdoc rdev symlink --filesbypkg List all the files in each selected package. -i, --info Display package information, including name, version, and description. This uses the --queryformat if one was specified. --last Orders the package listing by install time such that the latest packages are at the top. -l, --list List files in package. --provides List capabilities this package provides. -R, --requires List capabilities on which this package depends. --scripts List the package specific scriptlet(s) that are used as part of the installation and uninstallation processes. -s, --state Display the states of files in the package (implies -l). The state of each file is one of normal, not installed, or replaced. --triggers, --triggerscripts Display the trigger scripts, if any, which are contained in the package.