Difference between revisions of "Esmith::Build::CreateLinks"

From SME Server
Jump to navigationJump to search
Line 118: Line 118:
  
 
     templates2events("/opt/roundcube/config/db.inc.php", console-save);
 
     templates2events("/opt/roundcube/config/db.inc.php", console-save);
 +
 +
{{Note Box|msg=The settings below are new, waiting a release with the bug [[bugzilla: 8951]]}}
 +
===== event_templates =====
 +
      This function creates a file tree (of empty files) which is used by the generic_template_expand action to determine which templates need to be expanded for a particular event. Takes one event
 +
      argument and a list of file names, e.g.
 +
 +
        event_templates("$event", "/etc/some/file", "/etc/some/file2", "/etc/some/file3", ...);
 +
 +
# templates to expand
 +
for my $event (qw(
 +
conf-wordpress
 +
wordpress-update
 +
))
 +
{
 +
event_templates ($event , "/etc/httpd/conf/httpd.conf");
 +
event_templates ($event , "/etc/dar/DailyBackup.dcf");
 +
}
 +
 +
===== event_actions($event, %actions) =====
 +
      Create links to actions for the given event. %actions is a list of pairs Action => Priority. E.g
 +
 +
        event_actions('myevent', 'action1' => '10', 'action2' => '20', ..);
 +
 +
      See also event_link().
 +
 +
# actions to perform
 +
for my $event (qw(
 +
bootstrap-console-save
 +
console-save
 +
conf-wordpress
 +
wordpress-update
 +
))
 +
{
 +
event_actions ( $event , 'wordpress' => '20', 'wordpressa' => '30' , 'wordpressb' => '40');
 +
}
 +
===== event_services($event, %services) =====
 +
      Create links for the given $event in services2adjust/ subdirectory. %services is a list of pairs Service => LinkDestination
 +
          event_services(’myevent’, ’sshd’ => ’restart’, ’samba’ => ’reload’) See also safe_symlink().
 +
 +
# services to launch on event
 +
for my $event (qw(
 +
conf-wordpress
 +
wordpress-update
 +
))
 +
{
 +
event_services ( $event , "httpd-e-smith"=> 'sigusr1');
 +
event_services ( $event , "mysql.init"=> 'restart');
 +
}
  
 
==== AUTHOR ====
 
==== AUTHOR ====

Revision as of 15:25, 4 July 2015

PythonIcon.png Skill level: Developer
Risk of inconsistencies with Koozali SME Server methodology, upgrades & functionality is high. One must be knowledgeable about how changes impact their Koozali SME Server. Significant risk of irreversible harm.


NAME

esmith::Build::CreateLinks - A library for creating symlinks during rpm construction.

In a root terminal you can do the command below if you want to display the up-to-date content

perldoc esmith::Build::CreateLinks

SYNOPSIS

use esmith::Build::CreateLinks qw(:all);
safe_symlink("../../../functions/$function", "$cgibin/$function")

the beginning is always the same. The createlinks is a file who add during the built of rpm all correct link to different events and services.

#!/usr/bin/perl -w
use esmith::Build::CreateLinks qw(:all);

DESCRIPTION

safe_symlink

This function works like symlink(), but if the directory being linked to does not exist, it will create it.

ie. safe_symlink("../../../functions/$function", "$cgibin/$function")

  • links to add (other templates are available in /etc/e-smith/templates-default/)

You don't have to create the file /etc/e-smith/templates/etc/test/db.php/template-begin, it is automatic if needed. You simply have to link to the correct template you want (it depends of your software language). You don't need this safe_symlink if the default template is correct for you.

   safe_symlink("/etc/e-smith/templates-default/template-begin-php", "root/etc/e-smith/templates/etc/test/db.php/template-begin");
   safe_symlink("/etc/e-smith/templates-default/template-end-php", "root/etc/e-smith/templates/etc/test/db.php/template-end");

or another utilisation, do a link to an event already existing

                              existing event                                     new event linked to the other event
safe_symlink("/etc/e-smith/events/bootstrap-console-save/templates2expand", "root/etc/e-smith/events/service-expand/templates2expand");

or if you want to do a link to an existing file

                   existing file              link in the rpm
safe_symlink("/usr/share/php/Net/LDAP3","root/usr/share/pear/Net/LDAP3");
safe_symlink("/usr/share/php/Net/LDAP3.php","root/usr/share/pear/Net/LDAP3.php");


  • service to restart on demand
for  my $event (qw(
   conf-roundcube
   ))
{
   templates2events("/etc/httpd/conf/httpd.conf", $event);     #####expand-template on event conf-roundcube
   safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/mysql.init");  #####restart mysqlinit on event conf-roundcube
   safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/httpd-e-smith");  #####restart httpd on event conf-roundcube
}
panel_link

This function creates a link to a web panel.

ie.

my $panel = "manager";
panel_link("tug", $panel);

ie :

panel_link("denyhosts", "manager");
admin_common_link

This function creates a symlink from the common manager directory to a file in the functions directory.

event_link

This function creates a symlink from an action’s ordered location in an event directory to its action script. (actions are in /etc/e-smith/events/actions/)

ie.

my $event = "tug-update";
event_link("tug-conf", $event, "10");
event_link("conf-masq", $event, "20");
event_link("adjust-masq", $event, "30");
event_link("tug-restart", $event, "40");

or

foreach my $event (qw/webapps-update ipasserelle-update bootstrap-ldap-save/){
 event_link("phplist-create-pseudo", "$event", "55");
}
service_link_enhanced

This function creates a symlink from a SysV init start or kill link in a runlevel to e-smith-service, a wrapper that is config db aware.

ie.

safe_symlink("daemontools", "root/etc/rc.d/init.d/tug");
service_link_enhanced("tug", "S85", "7");
service_link_enhanced("tug", "K25", "6");
service_link_enhanced("tug", "K25", "0");
safe_symlink("/var/service/tug/", "root/service/tug");

of course the job script needs to be in /var/service/tug (should be relevant that it needs to be named by the same name : tug)

safe_touch

This function creates an empty file, but first creates any enclosing directories. For example:

ie :

safe_touch("root/var/lib/phplist/bounces.mbox");
safe_touch("a/b/c/d");

will create any of the directories "a", "a/b", "a/b/c" which don’t exist, then create an empty file "a/b/c/d".

templates2events

This function creates a file tree (of empty files) which is used by the generic_template_expand action to determine which templates need to be expanded for a particular event. Takes one file argument and a list of event names, e.g.

templates2events("/etc/some/file", "event1", "event2", ...);

eg :

foreach my $event (qw(share-create share-modify share-delete share-modify-servers)){
  templates2events("/etc/samba/smb.conf", $event);
  templates2events("/etc/httpd/conf/httpd.conf", $event);
  templates2events("/etc/rsyncd.conf", $event);
  templates2events("/etc/proftpd.conf", $event);
}

could be written like that also

templates2events("/etc/e-smith/sql/init/phplistdb", qw/webapps-update bootstrap-console-save/);
templates2events("/etc/phplist/config.php", qw/webapps-update bootstrap-console-save/);

or more simply

   templates2events("/opt/roundcube/config/db.inc.php", console-save);

Template:Note Box

event_templates
      This function creates a file tree (of empty files) which is used by the generic_template_expand action to determine which templates need to be expanded for a particular event. Takes one event
      argument and a list of file names, e.g.
       event_templates("$event", "/etc/some/file", "/etc/some/file2", "/etc/some/file3", ...);
# templates to expand
for my $event (qw(
conf-wordpress
wordpress-update
))
{
event_templates ($event , "/etc/httpd/conf/httpd.conf");
event_templates ($event , "/etc/dar/DailyBackup.dcf");
}
event_actions($event, %actions)
      Create links to actions for the given event. %actions is a list of pairs Action => Priority. E.g
        event_actions('myevent', 'action1' => '10', 'action2' => '20', ..);
      See also event_link().
# actions to perform
for my $event (qw(
bootstrap-console-save
console-save
conf-wordpress
wordpress-update
))
{
event_actions ( $event , 'wordpress' => '20', 'wordpressa' => '30' , 'wordpressb' => '40');
}
event_services($event, %services)
      Create links for the given $event in services2adjust/ subdirectory. %services is a list of pairs Service => LinkDestination
          event_services(’myevent’, ’sshd’ => ’restart’, ’samba’ => ’reload’) See also safe_symlink().
# services to launch on event
for my $event (qw(
conf-wordpress
wordpress-update
))
{
event_services ( $event , "httpd-e-smith"=> 'sigusr1');
event_services ( $event , "mysql.init"=> 'restart');
}

AUTHOR

SME Server Developers <bugs@e-smith.com>

SEE ALSO