我构建了这个部署脚本,它在部署我的 debian 6.0 服务器时运行。我之前在这里展示过(这是一个 linode 堆栈脚本,以防其他人想知道):
#!/bin/bash
#
# Install PostgreSQL
#
# Copyright (c) 2010 Filip Wasilewski <en@ig.ma>.
#
# My ref: http://www.linode.com/?r=aadfce9845055011e00f0c6c9a5c01158c452deb
function postgresql_install {
aptitude -y install postgresql postgresql-contrib postgresql-dev libpq-dev
}
function postgresql_create_user {
# postgresql_create_user(username, password)
if [ -z "$1" ]; then
echo "postgresql_create_user() requires username as the first argument"
return 1;
fi
if [ -z "$2" ]; then
echo "postgresql_create_user() requires a password as the second argument"
return 1;
fi
echo "CREATE ROLE $1 WITH LOGIN ENCRYPTED PASSWORD '$2';" | sudo -i -u postgres psql
}
function postgresql_create_database {
# postgresql_create_database(dbname, owner)
if [ -z "$1" ]; then
echo "postgresql_create_database() requires database name as the first argument"
return 1;
fi
if [ -z "$2" ]; then
echo "postgresql_create_database() requires an owner username as the second argument"
return 1;
fi
sudo -i -u postgres createdb --owner=$2 $1
}
postgresql_install
postgresql_create_user(username, password)
postgresql_create_database(dbname, username)
我使用这个脚本部署了我的服务器,该脚本是在 Filip 的版本之上构建的,但是当我尝试通过键入 pg_ctl 来查看 postgresql 是否正在运行时,它说找不到命令。
我在哪里做错了?因为它在服务器运行时部署,所以我无法看到它哪里出错了。