Change directadmin.conf through command line

nieuwhier

Verified User
Joined
Sep 8, 2005
Messages
280
Location
Netherlands
I have multiple servers and want to make sure every server uses the same directadmin.conf options. Now I need to change and compare all servers manually.

/usr/local/directadmin/directadmin c (this show all values)

It would be great if this would be possible(for example putting awstats on):
/usr/local/directadmin/directadmin c awstats=1

That way I only would have to make one script which sets the most important DA value for me and execute that on the servers.

Also an option like this to remove everything that is default would be handy:
/usr/local/directadmin/directadmin c removedefaults

Kind of like how custombuils works.
 
You can create your own one-line perl script and execute it on each server. Perl one-liner edit scripts (example here can be easily written on the fly once you get the hang of them. You can copy the same script to run on each server with a simple copy-and-paste.

Jeff
 
Thx Jeff.

True; but I would rather see something like this in DA for safety.

The script should not find and replace but also add when not available and it would be great that defaults are left out.

I myself am not that great in perl but I know my way in php... Perhaps I will make something in php for now.
 
I made a nice tool for myself to change it through PHP.

I have all directadmin.conf settings in the php file.
I compare it to all my servers and write a new directadmin.conf with my default settings.

- You can run it with example mode. It will write a example.conf file
- It wil mail you the difference between the old and new file
- it wil always make a copy of the current directadmin file.
- You can add keys you want to skip(like servername)

If anyone wants a free copy just PM me.
 
Hello,

There is actually such a tool in the custombuild build script to modify the options.conf. It uses /bin/sh.. and calls perl. Here's the code we've got in the build script
Code:
setOpt()
{
                #$1 is option name
                #$2 is value
                if [ "$1" = "email" ]; then
                        OPT_VALUE1="`grep -m1 "^$1=" ${OPTIONS_CONF} | cut -d= -f2 | cut -d\@ -f 1`"
                        OPT_VALUE2="`grep -m1 "^$1=" ${OPTIONS_CONF} | cut -d= -f2 | cut -d\@ -f 2`"
                        OPT_NEW_VALUE1="`echo "$2" | cut -d\@ -f 1`"
                        OPT_NEW_VALUE2="`echo "$2" | cut -d\@ -f 2`"
                        perl -pi -e "s#$1=${OPT_VALUE1}\@${OPT_VALUE2}#$1=${OPT_NEW_VALUE1}\@${OPT_NEW_VALUE2}#" ${WORKDIR}/options.conf
                        if [ "${HIDE_CHANGES}" = "0" ]; then
                                echo "Changed ${boldon}$1${boldoff} option from ${boldon}${OPT_VALUE1}@${OPT_VALUE2}${boldoff} to ${boldon}$2${boldoff}"
                        fi
                else
                        OPT_VALUE="`grep -m1 "^$1=" ${OPTIONS_CONF} | cut -d= -f2`"
                        perl -pi -e "s#$1=${OPT_VALUE}#$1=$2#" ${WORKDIR}/options.conf
                        if [ "${HIDE_CHANGES}" = "0" ]; then
                                echo "Changed ${boldon}$1${boldoff} option from ${boldon}${OPT_VALUE}${boldoff} to ${boldon}$2${boldoff}"
                        fi
                fi
}
Where a sample function call to it would be
Code:
setOpt php5_cgi no;
which sets "php5_cgi=no" in the options.conf. I'm sure something similar could be used for writing to the directadmin.conf file. I have my doubts that we'd have such a script as default, for the time being.

For things like custombuild changing directadmin.conf settings, it just runs things like (eg: to set dovecot=1):
Code:
        COUNT="`grep -c -e '^dovecot=1' ${DACONF_FILE}`"
        if [ "${COUNT}" = "0" ] && [ -e ${DACONF_FILE} ]; then
                echo "Adding dovecot=1 to the ${DACONF_FILE} file...";
                echo "dovecot=1" >> ${DACONF_FILE}
                echo "dovecot=ON" >> /usr/local/directadmin/data/admin/services.status
                doRestartDA
        fi
John
 
Not to bump up an old thread, but I often use a command like below to add a value to the Directadmin configuration, it checks first if it isn't already there and if not, adds it:

grep -q 'letsencrypt=1' /usr/local/directadmin/conf/directadmin.conf || echo 'letsencrypt=1' >> /usr/local/directadmin/conf/directadmin.conf
 
Back
Top