mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
chasquid: Do a Chdir into the configuration directory
In some cases, it's be useful to have references to directories relative to the configuration itself. So this patch makes chasquid do a Chdir into it, so we can assume it in the rest of the code and config.
This commit is contained in:
12
chasquid.go
12
chasquid.go
@@ -60,6 +60,13 @@ func main() {
|
||||
glog.Fatalf("Error reading config")
|
||||
}
|
||||
|
||||
// Change to the config dir.
|
||||
// This allow us to use relative paths for configuration directories.
|
||||
// It also can be useful in unusual environments and for testing purposes,
|
||||
// where paths inside the configuration itself could be relative, and this
|
||||
// fixes the point of reference.
|
||||
os.Chdir(*configDir)
|
||||
|
||||
if conf.MonitoringAddress != "" {
|
||||
glog.Infof("Monitoring HTTP server listening on %s",
|
||||
conf.MonitoringAddress)
|
||||
@@ -74,7 +81,8 @@ func main() {
|
||||
s.MaxDataSize = conf.MaxDataSizeMb * 1024 * 1024
|
||||
|
||||
// Load domains.
|
||||
domainDirs, err := ioutil.ReadDir(*configDir + "/domains/")
|
||||
// They live inside the config directory, so the relative path works.
|
||||
domainDirs, err := ioutil.ReadDir("domains/")
|
||||
if err != nil {
|
||||
glog.Fatalf("Error in glob: %v", err)
|
||||
}
|
||||
@@ -85,7 +93,7 @@ func main() {
|
||||
glog.Infof("Domain config paths:")
|
||||
for _, info := range domainDirs {
|
||||
name := info.Name()
|
||||
dir := filepath.Join(*configDir, "domains", name)
|
||||
dir := filepath.Join("domains", name)
|
||||
loadDomain(s, name, dir)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,10 @@ function generate_cert() {
|
||||
function chasquid() {
|
||||
# HOSTALIASES: so we "fake" hostnames.
|
||||
# PATH: so chasquid can call test-mda without path issues.
|
||||
# MDA_DIR: so our test-mda knows where to deliver emails.
|
||||
HOSTALIASES=${TBASE}/hosts \
|
||||
PATH=${UTILDIR}:${PATH} \
|
||||
MDA_DIR=${TBASE}/.mail \
|
||||
go run ${TBASE}/../../chasquid.go "$@"
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p .mail
|
||||
mkdir -p ${MDA_DIR}
|
||||
|
||||
# TODO: use flock to lock the file, to prevent atomic writes.
|
||||
echo "From ${1}" >> .mail/.tmp-${1}
|
||||
cat >> .mail/.tmp-${1}
|
||||
echo "From ${1}" >> ${MDA_DIR}/.tmp-${1}
|
||||
cat >> ${MDA_DIR}/.tmp-${1}
|
||||
X=$?
|
||||
if [ -e .mail/.tmp-${1} ]; then
|
||||
mv .mail/.tmp-${1} .mail/${1}
|
||||
if [ -e ${MDA_DIR}/.tmp-${1} ]; then
|
||||
mv ${MDA_DIR}/.tmp-${1} ${MDA_DIR}/${1}
|
||||
fi
|
||||
exit $X
|
||||
|
||||
Reference in New Issue
Block a user