Enabling a module across many tenant sites?

Topics: Customizing Orchard, General, Writing modules
May 31, 2012 at 6:34 PM

I have a bunch of tenant sites that I want to enable a new module for. Is there a super awesome way to go about this? Otherwise I need one of these:

Coordinator
May 31, 2012 at 8:42 PM

Yes, the Orchard command line is your friend.

Jun 1, 2012 at 1:47 AM

Hmm, could you provide a simple example of doing this?

After taking a look into the world of orchard command line, I'm not finding anything about tenants. I imagine I need to load a tenant, then enable the module, then unload, and repeat for each tenant? Or is there a way to call the enable module command that gets applied to each tenant?

Jun 1, 2012 at 1:57 AM
Edited Jun 1, 2012 at 2:03 AM

Never mind! If I would have actually loaded up the command line console and poked around, I would have seen the /t feature. Here is how it would work:

feature enable Contrib.RewriteRules /t:Default
feature enable Contrib.RewriteRules /t:MySite1
feature enable Contrib.RewriteRules /t:MySite2

 

Jun 1, 2012 at 2:04 AM

Now the true question is, can this be done in a batch file? Or better yet, could I be so lucky to do something like this?

feature enable Contrib.RewriteRules /t:All


Command or not, it's still going to take some time to enable the module across 50 some odd tenants.

Coordinator
Jun 1, 2012 at 4:02 AM

Of course it can be done in a batch file. That's the whole point of the command line. Why are you saying it will still take time? It will take the time to run the command-line.

Jun 1, 2012 at 1:22 PM

I meant it would take some time if I had to run "feature enable Contrib.RewriteRules /t:Mysite1" wait a few seconds, then run "feature enable Contrib.RewriteRules /t:Mysite2", and etc etc.

And it looks like you are right, yet again Bertrand.  However, I'm not sure how it's possible to run a batch file from inside Orchard.exe to enable the modules. What I did find is possible is to run a batch file in command prompt in \Orchard.Web that looks like this:

call bin\Orchard.exe feature enable Contrib.RewriteRules /t:Default
call bin\Orchard.exe feature enable Contrib.RewriteRules /t:Mysite1
call bin\Orchard.exe feature enable Contrib.RewriteRules /t:Mysite2

Seems a but redundant on memory to spool up and release Orchard.exe for each module enabled, but hey, it works right.

Jun 1, 2012 at 2:02 PM

Okay, I take that bit about it working back. When running this on my production machine (with an active application pool in IIS) ran into an issue.

Besides getting an error message when running the command, which it seems to overcome:

C:\inetpub\wwwroot\Orchard.Web.1.4.2>call bin\Orchard.exe feature enable Contrib
.RewriteRules /t:xxxx
Initializing Orchard session. (This might take a few seconds...)
log4net:ERROR [OrchardFileAppender] Unable to acquire lock on file C:\inetpub\ww
wroot\Orchard.Web.1.4.2\App_Data\Logs\orchard-error-2012.06.01.log. The process
cannot access the file 'C:\inetpub\wwwroot\Orchard.Web.1.4.2\App_Data\Logs\orcha
rd-error-2012.06.01.log' because it is being used by another process.
log4net:ERROR OrchardFileAppender: Failed to open [C:\inetpub\wwwroot\Orchard.We
b.1.4.2\App_Data\Logs\orchard-error]. Attempting [C:\inetpub\wwwroot\Orchard.Web
.1.4.2\App_Data\Logs\orchard-error-1] instead.
Enabling features Contrib.RewriteRules
Rewrite Rules was enabled

After this finishes, all my tenants crash with a Server Error message. Here's what I dug up in the event log:

Exception information:
    Exception type: ObjectDisposedException
    Exception message: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.
   at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
   at lambda_method(Closure )
   at Orchard.Environment.DefaultOrchardShell.Terminate() in d:\Builds\OrchardFull\src\Orchard\Environment\DefaultOrchardShell.cs:line 51
   at Orchard.Environment.DefaultOrchardHost.DisposeShellContext() in d:\Builds\OrchardFull\src\Orchard\Environment\DefaultOrchardHost.cs:line 202
   at Orchard.Environment.DefaultOrchardHost.<MonitorExtensions>b__6(AcquireContext`1 ctx) in d:\Builds\OrchardFull\src\Orchard\Environment\DefaultOrchardHost.cs:line 190
   at Orchard.Caching.Cache`2.CreateEntry(TKey k, Func`2 acquire) in d:\Builds\OrchardFull\src\Orchard\Caching\Cache.cs:line 57
   at Orchard.Caching.Cache`2.UpdateEntry(CacheEntry currentEntry, TKey k, Func`2 acquire) in d:\Builds\OrchardFull\src\Orchard\Caching\Cache.cs:line 33
   at System.Collections.Concurrent.ConcurrentDictionary`2.AddOrUpdate(TKey key, Func`2 addValueFactory, Func`3 updateValueFactory)
   at Orchard.Caching.Cache`2.Get(TKey key, Func`2 acquire) in d:\Builds\OrchardFull\src\Orchard\Caching\Cache.cs:line 17
   at Orchard.Environment.DefaultOrchardHost.BeginRequest() in d:\Builds\OrchardFull\src\Orchard\Environment\DefaultOrchardHost.cs:line 214
   at Orchard.WarmupStarter.Starter`1.OnBeginRequest(HttpApplication application) in d:\Builds\OrchardFull\src\Orchard.WarmupStarter\Starter.cs:line 68

 

It takes a recycling of the application pool to recover from this. There's got to be a better way to go about this.

Developer
Jun 1, 2012 at 4:35 PM
Edited Jun 1, 2012 at 4:35 PM

You get the frist set of errors when running the command line tool, because the running server (or the first Orchard.exe instance) locks on the log files and then the other Orchard.exe processes can't read/write it, just ignore it.

Anyway, for an Orchard.exe instance, you can pass only one command.
On related matter: if you want to enable/disable features in the default tenant at once, OrchardHUN.ModuleProfiles is quite handy (it sometimes has some troubles with dependencies, I'll see to fix it soon), see the module's CodePlex site for the available commands.

Coordinator
Jun 1, 2012 at 6:36 PM

It is not correct that you can pass only one command. If you do orchard.exe /? you'll see a number of additional options. In particular, you can run a batch file by doing bin\orchard.exe @mybatch.txt.

Developer
Jun 1, 2012 at 6:46 PM

My bad then, I checked the documentation, but I didn't read the command line help.

Coordinator
Jun 1, 2012 at 7:02 PM

Maybe someone could update the documentation by the way ;) also including all available switches.

Jun 2, 2012 at 4:06 PM
Edited Jun 2, 2012 at 4:08 PM

Thanks folks! Sure enough, Bertrand was on the mark again. I created my batch file like so:

feature enable MyModule /t:Default
feature enable MyModule /t:MySite1
feature enable MyModule /t:MySite2
...
feature enable MyModule /t:MySite50

And ran it bin\Orchard @enable_modules.bat

However, after 7 or so enables, it seems to crash:

Enabling features MyModule
MyModule was enabled
Enabling features MyModule
MyModule was enabled
Enabling features MyModule
MyModule was enabled
Enabling features MyModule
MyModule was enabled
Enabling features MyModule
MyModule was enabled
Enabling features MyModule
MyModule was enabled
Enabling features MyModule
MyModule was enabled
Error:
  Object '/4659cb59_d701_4250_9099_e59581e8fa79/z5h_4ys0yhtl223mdwuwqxga_21.rem'
 has been disconnected or does not exist at the server.

This happen every time I try this and it seems to take an extraordinary amount of CPU to be doing this. Is this a known issue, should I report a bug on this?

Update

It seems to always happen in increments of 7.

Coordinator
Jun 3, 2012 at 5:05 AM

Yes, please file a bug.