Linux part 2
Tips
システム日時を偽装する(プログラムテスト用などに)(CentOS向け)
環境構築
- yum install git gcc make
- git clone https://github.com/wolfcw/libfaketime.git
- cd libfaketime/src
- make install
- echo -e ‘/usr/local/lib/faketime/libfaketime.so.1’ > /etc/ld.so.preload
- export DONT_FAKE_MONOTONIC=1
- export FAKETIME_CACHE_DURATION=1
- export DONT_FAKE_MONOTONIC=1
これを指定しておかないと Java でエラーが発生する?
プログラムから見た日時を変更
- 指定した日時にを変更する
echo -e ‘@2000-01-01 09:00:00’ > /etc/faketimerc
- システム日時から指定した日数ずらす
echo -e ‘+3d’ > /etc/faketimerc
- システム日時から指定した年数ずらす
echo -e ‘-10y’ > /etc/faketimerc
- 元に戻す
rm -f /etc/faketimerc
(参考) システム日付を変更したコンテナ環境でテストしたい