FreedomBox/actions/owncloud-setup
Sunil Mohan Adapa 771581a75f owncloud: Do Apache reload instead of restart
Restarting Apache breaks existing connections.  This includes the connection
on which the Plinth's user has made the ownCloud enable/disable request.  This
leads to an almost certain 'Connection Interupted' message to the client when
changes to ownCloud are submitted.

On the other hand, 'reload' is sufficient and 'restart' is not required.  It is
also faster and recommended by 'a2enconf' and 'a2disconf' commands.
2015-02-11 10:48:41 +05:30

109 lines
3.1 KiB
Bash
Executable File

#!/bin/sh
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# See also
# http://doc.owncloud.org/server/6.0/admin_manual/configuration/configuration_automation.html
if [ -e /etc/apache2/conf-enabled/owncloud.conf ] ; then
owncloud_enable=true
else
owncloud_enable=false
fi
owncloud_enable_cur=$owncloud_enable
export owncloud_enable
while [ "$1" ] ; do
arg="$1"
shift
case "$arg" in
enable|noenable) # Not using disable for consistency with other options
if [ 'enable' = "$arg" ] ; then
owncloud_enable=true
else
owncloud_enable=false
fi
export owncloud_enable
;;
status)
printstatus() {
if "$2" ; then
echo "$1"
else
echo no"$1"
fi
}
printstatus enable $owncloud_enable_cur
exit 0
;;
*)
;;
esac
done
if [ "$owncloud_enable" != "$owncloud_enable_cur" ] ; then
if $owncloud_enable ; then
# Keep existing configuration if it exist
if [ ! -e /etc/owncloud/config.php ] ; then
# Set up postgresql database and user
dbpwd=$(pwgen -1 30)
su - postgres -c "psql -c \"CREATE USER owncloud WITH NOCREATEDB NOCREATEUSER ENCRYPTED PASSWORD '$dbpwd'\"" \
2>&1 | logger -t owncloud-setup
su - postgres -c "createdb --owner owncloud owncloud" \
2>&1 | logger -t owncloud-setup
cat > /etc/owncloud/autoconfig.php <<EOF
<?php
\$AUTOCONFIG = array(
'directory' => '/usr/share/owncloud/data',
'dbtype' => 'pgsql',
'dbname' => 'owncloud',
'dbuser' => 'owncloud',
'dbpass' => '$dbpwd',
'dbhost' => 'localhost',
'dbtableprefix' => 'oc_',
'installed' => false,
);
EOF
# The default admin user and password set up in owncloud
# FIXME figure out how to pick username and password, perhaps from the
# plinth user database?
#adminuser=admin
#adminpwd=secret
# Use these in autoconfig.php to set admin username and password:
# 'adminlogin' => '$adminuser',
# 'adminpass' => '$adminpwd',
a2enconf owncloud 2>&1 | logger -t owncloud-setup
service apache2 reload 2>&1 | logger -t owncloud-setup
# Initialize application and database tables by visiting
# the front page. This only work if admin user and
# password was set above.
#wget --quiet http://$(uname -n)/owncloud/index.php
else
a2enconf owncloud 2>&1 | logger -t owncloud-setup
service apache2 reload 2>&1 | logger -t owncloud-setup
fi
else
a2disconf owncloud 2>&1 | logger -t owncloud-setup
service apache2 reload 2>&1 | logger -t owncloud-setup
fi
fi