Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
P
provision
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
provision
Commits
f77b1576
Commit
f77b1576
authored
Jan 17, 2008
by
Adrian Rossouw
Committed by
adrian
Jan 17, 2008
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #default_value in provision_drupal and add backup command
parent
0e9cbce6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
44 deletions
+114
-44
provision.inc
provision.inc
+30
-31
provision.module
provision.module
+59
-10
provision_apache.module
provision_apache.module
+2
-2
provision_drupal.info
provision_drupal.info
+1
-1
provision_drupal.module
provision_drupal.module
+15
-0
provision_mysql.module
provision_mysql.module
+7
-0
No files found.
provision.inc
View file @
f77b1576
...
...
@@ -114,31 +114,10 @@ function provision_output($url, $data, $extra = null) {
* on how to diagnose any problems that may have occurred.
*/
/**
* @name Error status definitions
* @{
* Bitmask values used to generate the error code to return.
* @see provision_set_error(), provision_get_error(), provision_cmp_error()
*/
/** Database could not be accessed, or configured */
define
(
'PROVISION_DB_ERROR'
,
1
);
/** Drupal was unable to complete it's installation */
define
(
'PROVISION_INSTALL_ERROR'
,
2
);
/** Could not create files due to permission error - potentially less severe */
define
(
'PROVISION_PERM_ERROR'
,
4
);
/** Web server could not be restarted, or other server related issues - less severe */
define
(
'PROVISION_WEB_ERROR'
,
8
);
/** To be used while testing if the provision framework is actually working. */
define
(
'PROVISION_FRAMEWORK_ERROR'
,
16
);
/** When the site is not available on this platform, or has not been installed. */
define
(
'PROVISION_SITE_NOT_FOUND'
,
32
);
/** When the site is already installed, ie: there is a conflict. */
define
(
'PROVISION_SITE_INSTALLED'
,
64
);
/**
* @} End of "name Error status defintions".
*/
if
(
PROVISION_SUCCESS
!=
-
1
)
{
include_once
(
'provision_errors.inc'
);
}
/**
* Set an error code for the error handling system.
...
...
@@ -338,7 +317,6 @@ function provision_save_site_data($url, $data) {
fwrite
(
$fp
,
$line
);
}
}
fwrite
(
$fp
,
"?>"
);
fclose
(
$fp
);
}
}
...
...
@@ -389,12 +367,12 @@ function provision_token_list($type = 'all') {
if
(
$type
==
'site'
)
{
/** TODO: Complete the token list to allow the front end to more easily edit the settings. */
$tokens
[
'site'
][
'site-url'
]
=
t
(
"The domain name used to access the site."
);
$tokens
[
'site'
][
'site-db-type'
]
=
t
(
""
);
$tokens
[
'site'
][
'site-db-username'
]
=
t
(
""
);
$tokens
[
'site'
][
'site-db-password'
]
=
t
(
""
);
$tokens
[
'site'
][
'site-db-name'
]
=
t
(
""
);
$tokens
[
'site'
][
'site-profile'
]
=
t
(
""
);
$tokens
[
'site'
][
'site-action-type'
]
=
t
(
""
);
$tokens
[
'site'
][
'site-db-type'
]
=
t
(
"
The type of database server used
"
);
$tokens
[
'site'
][
'site-db-username'
]
=
t
(
"
Username to access database for site
"
);
$tokens
[
'site'
][
'site-db-password'
]
=
t
(
"
Password to access database for site
"
);
$tokens
[
'site'
][
'site-db-name'
]
=
t
(
"
Database name for the site
"
);
$tokens
[
'site'
][
'site-profile'
]
=
t
(
"
Installation Profile
"
);
$tokens
[
'site'
][
'site-action-type'
]
=
t
(
"
What type of action has been used
"
);
}
return
$tokens
;
}
...
...
@@ -415,3 +393,24 @@ function _provision_confirm_drush() {
#confirm that code is running through the command line.
}
/**
* Get the root path of the Provision installation
*/
function
_provision_root_path
()
{
return
variable_get
(
'provision_root'
,
ereg_replace
(
"/webroot$"
,
""
,
$_SERVER
[
'DOCUMENT_ROOT'
]));
}
/**
* Wrapper around drush_shell_exec to provide sprintf functionality with some more safety.
*/
function
provision_shell_exec
()
{
$args
=
func_get_args
();
#do not change the command itself, just the parameters.
for
(
$x
=
1
;
$x
<
sizeof
(
$args
);
$x
++
)
{
$args
[
$x
]
=
escapeshellcmd
(
$args
[
$x
]);
}
$command
=
call_user_func_array
(
"sprintf"
,
$args
);
return
drush_shell_exec
(
$command
);
}
\ No newline at end of file
provision.module
View file @
f77b1576
...
...
@@ -53,7 +53,7 @@ function hook_perm() {
/**
* Implementation of hook_menu().
*/
function
provision_menu
(
$
items
,
$
may_cache
=
true
)
{
function
provision_menu
(
$may_cache
=
true
)
{
if
(
$may_cache
)
{
$items
[]
=
array
(
'path'
=>
'admin/settings/provision'
,
...
...
@@ -149,6 +149,10 @@ function provision_drush_command() {
$items
[
'provision import'
]
=
array
(
'callback'
=>
'_provision_import'
,
'description'
=>
'Turn an already running site into a provisioned site.'
);
$items
[
'provision backup'
]
=
array
(
'callback'
=>
'_provision_backup'
,
'description'
=>
'Generate a back up for the site.'
);
/*
$items['provision enable'] = array(
...
...
@@ -165,10 +169,7 @@ function provision_drush_command() {
'description' => 'Delete a site.'
);
$items['provision backup'] = array(
'callback' => '_provision_backup',
'description' => 'Generate a back up for the site.'
);
$items['provision rollback'] = array(
'callback' => '_provision_rollback',
'description' => 'Roll back the site to a previous backup.'
...
...
@@ -311,14 +312,14 @@ function _provision_post_install($url, &$data) {
* @param url
* The url of the site being synched.
* @return
* Output of
drupal
_output() function.
* Output of
provision
_output() function.
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site does not exist.
*/
function
_provision_synch
(
$url
)
{
if
(
!
_provision_drupal_site_exists
(
$url
))
{
provision_log
(
"Error"
,
"Site has not been installed yet."
);
drupal_set_error
(
PROVISION_SITE_NOT_FOUND
);
drupal
_output
(
$url
,
$data
);
provision
_output
(
$url
,
$data
);
}
$data
=
provision_get_site_data
(
$url
);
// This is the actual drupal provisioning requirements.
...
...
@@ -327,7 +328,55 @@ function _provision_synch($url) {
// Requires at least the database settings to complete.
_provision_drupal_create_settings_file
(
$url
,
$data
);
provision_save_site_data
(
$url
,
$data
);
drupal_output
(
$url
,
$data
);
provision_output
(
$url
,
$data
);
}
/**
* Generate a backup of the site using a site package.
*
* @param url
* The url of the site being backed up.
* @return
* Output of provision_output() function.
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site does not exist.
*/
function
_provision_backup
(
$url
)
{
if
(
!
_provision_drupal_site_exists
(
$url
))
{
provision_log
(
"Error"
,
"Site has not been installed yet."
);
provision_set_error
(
PROVISION_SITE_NOT_FOUND
);
provision_output
(
$url
,
$data
);
}
$data
=
provision_get_site_data
(
$url
);
$backup_path
=
variable_get
(
'provision_backup_path'
,
_provision_root_path
()
.
'/backups'
);
// This is the actual drupal provisioning requirements.
if
(
!
is_dir
(
$backup_path
))
{
provision_log
(
"Backup directory does not exist."
);
provision_set_error
(
PROVISION_PERM_ERROR
);
provision_output
(
$url
,
$data
);
}
$args
=
func_get_args
();
array_shift
(
$args
);
$file
=
array_shift
(
$args
);
if
(
is_file
(
$file
))
{
provision_log
(
"File specified already exists."
);
provision_set_error
(
PROVISION_PERM_ERROR
);
provision_output
(
$url
,
$data
);
}
$suggested
=
"
$backup_path
/
$url
-"
.
date
(
"Y-m-d"
,
mktime
())
.
".tar"
;
// Use format of mysite.com-2008-01-02, if already existing, add number.
while
(
is_file
(
$suggested
.
'.gz'
))
{
$count
++
;
$suggested
=
"
$backup_path
/
$url
-"
.
date
(
"Y-m-d"
,
mktime
())
.
"_
$count
.tar"
;
}
$data
[
'backup_file'
]
=
(
!
empty
(
$file
))
?
$file
:
$suggested
;
$rolled_back
=
provision_invoke
(
"backup"
,
$url
,
$data
);
provision_shell_exec
(
"gzip %s"
,
$data
[
'backup_file'
]);
$data
[
'backup_file'
]
=
$data
[
'backup_file'
]
.
'.gz'
;
provision_save_site_data
(
$url
,
$data
);
provision_output
(
$url
,
$data
);
}
/**
...
...
@@ -338,14 +387,14 @@ function _provision_synch($url) {
* @param url
* The url of the site being synched.
* @return
* Output of
drupal
_output() function.
* Output of
provision
_output() function.
* Will exit with a PROVISION_SITE_NOT_FOUND error if the site does not exist.
*/
function
_provision_import
(
$url
)
{
if
(
!
_provision_drupal_site_exists
(
$url
))
{
provision_log
(
"Error"
,
"Site directory is not present, and can not be imported."
);
drupal_set_error
(
PROVISION_SITE_NOT_FOUND
);
drupal
_output
(
$url
,
$data
);
provision
_output
(
$url
,
$data
);
}
$data
=
provision_get_site_data
(
$url
);
...
...
provision_apache.module
View file @
f77b1576
...
...
@@ -33,7 +33,7 @@ function provision_apache_provision_configure() {
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Path to the directory to store apache configuration files for hosted sites'
),
'#size'
=>
40
,
'#value'
=>
variable_get
(
'provision_apache_vhost_path'
,
$default_path
),
'#
default_
value'
=>
variable_get
(
'provision_apache_vhost_path'
,
$default_path
),
'#maxlength'
=>
255
,
);
$form
[
'provision_apache_restart_cmd'
]
=
array
(
...
...
@@ -106,7 +106,7 @@ function _provision_apache_restart_apache() {
# This is required to be configurable, due to the fact that different hosts might need to do this differently.
# TODO : add configuration / test for this
$apache_restart_cmd
=
escapeshellcmd
(
variable_get
(
'provision_apache_restart_cmd'
,
'sudo apachectl graceful'
));
$code
=
drush_shell_exec
(
$apache_restart_cmd
);
$code
=
drush_shell_exec
(
escapeshellcmd
(
$apache_restart_cmd
)
);
if
(
$code
)
{
provision_set_error
(
PROVISION_WEB_ERROR
);
provision_log
(
"error"
,
"Web server could not be restarted. Changes might not be available until this has been done."
);
...
...
provision_drupal.info
View file @
f77b1576
name
=
Provision
:
Drupal
description
=
Allows
for
Drupal
sites
to
be
provisioned
using
the
provisioning
framework
.
package
=
Provision
dependencies
=
drush
provision_drupal
provision_mysql
provision_apache
\ No newline at end of file
dependencies
=
drush
provision
\ No newline at end of file
provision_drupal.module
View file @
f77b1576
...
...
@@ -74,6 +74,21 @@ function _provision_drupal_site_exists($url) {
return
file_exists
(
"sites/
$url
/settings.php"
);
}
/**
* Implentation of hook_provision_backup()
*/
function
provision_drupal_provision_backup
(
$url
,
$data
)
{
// Adds the site directory into the backup file
provision_log
(
"backup"
,
"Adding sites directory to
$data[backup_file]
.gz"
);
$result
=
provision_shell_exec
(
"cd %s; tar -rf %s * "
,
"sites/
$url
"
,
$data
[
'backup_file'
]);
if
(
!
$result
)
{
provision_log
(
"error"
,
"Could not back up sites directory for drupal"
);
provision_set_error
(
PROVISION_FRAMEWORK_ERROR
);
}
}
/**
* The default template to use while generating config files.
*
...
...
provision_mysql.module
View file @
f77b1576
...
...
@@ -99,3 +99,10 @@ function provision_mysql_provision_pre_install($url, &$data) {
#TODO : Test to confirm that the database is actually writeable. Taking this on faith for now.
}
function
provision_mysql_provision_backup
(
$url
,
&
$data
)
{
provision_log
(
"backup"
,
"Generating mysql dump for
$url
."
);
provision_shell_exec
(
"mysqldump -u%s -p%s %s > sites/%s/database.sql"
,
$data
[
'site-db-username'
],
$data
[
'site-db-passwd'
],
$data
[
'site-db-name'
],
$url
);
provision_shell_exec
(
"cd sites/%; tar -rf %s database.sql"
,
$url
,
$data
[
'backup_file'
]);
provision_shell_exec
(
"rm sites/%s/database.sql"
,
$url
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment