PostgreSQL rc.d script outputting fortunes
I've been having a weird problem with the postgresql rc.d script in a FreeBSD jail. I finally figured out today how to fix it and wanted to put it on here so I dont forget.
Whenever I call the postgresql rc.d script to start/stop/restart/whatever the postgres server I would get a fortune from freebsd-tips like when you log in:
[root@wackbox163 /usr/local/pgsql]# /usr/local/etc/rc.d/postgresql restart Any user that is a member of the wheel group can use "su -" to simulate a root login. You can add a user to the wheel group by editing /etc/group. -- Konstantinos Konstantinidis <email@example.com> server stopped [root@wackbox163 /usr/local/pgsql]#
I have been completely unable to figure out why this was happening, until a friend of mine reminded me to check .profile. I opened up /usr/local/pgsql/.profile and commented out the following line:
[ -x /usr/games/fortune ] && /usr/games/fortune freebsd-tips
And now I don't get the any tips when using the postgresql rc.d script:
[root@wackbox163 /usr/local/pgsql]# /usr/local/etc/rc.d/postgresql restart server stopped [root@wackbox163 /usr/local/pgsql]#
This happens because the postgresql rc.d script switches user to the postgresql pgsql user before executing the actual start/stop commands. For some reason, and only on this specific machine, the user switch with su called .profile which in turn ran the fortune system. The reason is probably that I always install "minimal" (in sysinstall) FreeBSD machines these days. The machine that had this problem is older and was installed as "standard" (in sysinstall). This means that /usr/games/fortune/ exists on this machine and not on a lot of my newer machines. The fortune line from .profile will only run if the fortunes are installed, of course.