Launching Excel in a production web server on a Mac

I have written some code that will open Excel, edit a spreadsheet, then
save and print the sheet. This code needs to run on a production web
server in a Rails app. When I run it using Webrick (running under my
user) everything is great. When I try it on the production server
(nginx running as root), not so great.

I knew heading into this that this scenario was a longshot to work. My
question is is this even remotely possible? If not, does anyone have
any alternate suggestions?

To say that you’ve not given us sufficient information to help you
debug your problem would perhaps be biggest understatement I’ve yet
seen in 2014.

Seriously, chap - “I can’t open my spreadsheet in nginx” … are you
/really/ expecting anyone to be able to help from that minimal (if not
totally nonsensical) problem description?

Read this. End to end. And then try again:
http://www.catb.org/~esr/faqs/smart-questions.html

Fair enough, but I was looking for more of a high level guidance rather
than solving my problem specifically. I guess my question is in general
is it possible for Rails code running in nginx (running as root) to
spawn an application like Excel? I’m not familiar enough with OS X’s
userspace model to even know where to start with that…

The specifics of my problem:

  1. nginx 1.2.2 running as root on OS X 10.8.5. Rails is at 3.2.15
  2. A standard user request comes in
  3. Handled by Rails controller
  4. Controller launches Excel through rb-appscript (ruby-to-applescript
    bridge)

Normally at this point Excel actually launches in my dev environment,
and specific changes to an Excel document are made through rb-appscript
code. On the production side the Excel process never starts, and the
request eventually just times out… nothing in the logs.

On Feb 1, 2014, at 12:25 PM, Anth A. [email protected] wrote:

I’m running under root because that was the easy way to bind to port 80.
I’m guessing if I run nginx under my user account I’d have to forward a
higher port (8080 or whatever) to port 80 using an ip table (or whatever
the OS X equivalent is)?

IIRC, one of your later messages made it clear that you do not, in fact,
need nginx to communicate with Xcel. Rather you need your application
server to do so. I forget whether you said passenger or unicorn, but
either way that process needs to run as the logged-in user, and that’s
simpler since that process only needs to communicate via local sockets.

Thanks, Scott! Awesome info.

I’m running under root because that was the easy way to bind to port 80.
I’m guessing if I run nginx under my user account I’d have to forward a
higher port (8080 or whatever) to port 80 using an ip table (or whatever
the OS X equivalent is)?

On Jan 28, 2014, at 4:01 PM, Anth A. [email protected] wrote:

I knew heading into this that this scenario was a longshot to work. My
question is is this even remotely possible? If not, does anyone have
any alternate suggestions?

I don’t see any reason why it wouldn’t work, but you have to get your
users & permissions straight.

  • Are you really running nginx as root? That’s an odd, and insecure,
    thing to do. Remember, just because the process that launches it may
    have root privileges, does not necessarily mean the effective user is
    root.

  • Your server will have to be logged into a user account. Unlike nginx
    and other servers, Xcel requires an active logged-in user to run. So
    basically, you want a user, you want to have the server auto-login to
    that user account on boot, and you want nginx to run under that user’s
    account as well.

That’s the basics. Now, to make this actually reliable on a server is
another issue. You see, I do the same thing with MS Word on a Mac
server, and here’s what I have to cope with, and I assume it will be
similar for Xcel:

  • Of course if preferences are set to display the document gallery at
    startup, it will not open the document you tell it to. So you must set
    up the preferences to disable the document gallery.

  • It will occasionally spontaneously reset that preference, so you’re
    really best off setting up the preferences the way you want them,
    copying the file into your project somewhere, and replacing the
    application preferences with your cached copy before each launch.

  • Every once in a while, launching the application will take extra long,
    up to about a minute. So if you’re monitoring for a time-out, take that
    into account.

  • As you repeatedly open and print documents, it will slow down. I keep
    a document count, and quit & re-launch Word every 100 documents–of
    course launching more often means that launch problems happen more
    often.

  • Sometimes it just freezes. Sometimes it decides on quit to display a
    dialog about not being able to save the normal template or some other
    similar bullshit. So whenever you ask it to do something, you have to be
    prepared to time out and kill -9 it.

The good news is that all of the above problems have gotten much less
frequent with Word 2011, and Word 2011 completely eliminated the
nastiness where Word 2004 would corrupt the old emulation layer so
completely that it would not run at all until you rebooted the server
(even killing and restarting the “blued” stuff would not do it).

Enjoy yourself; I sure as hell did not :wink:

Thanks again, Scott. That makes a lot of sense. I’ve set
passenger_user_switching off and passenger_default_user to the user I
want Excel launched as… still nothing though. The processes look like
this:

Process User

PassengerWatchdog root
PassengerHelpterAgent userIwant
PassengerLoggingAgent nobody

nginx (master) root
nginx (worker) nobody

Does this seem correct?

Actually, after some more playing around I’ve finally got something
working! Well, not exactly, but I’m able to communicate through OSA
instead of appscript (and to be honest, I know very little about this
appscript gem and it’s been deprecated anyway, so it’s probably for the
best that I rewrite the spreadsheet manipulation code anyway.)

A MILLION thank yous, Scott! You are a life saver!

Oh, and Jonathan… a lesson for you: just because a question doesn’t
make sense /to you/ doesn’t make it nonsensical. I asked a question
that made sense to me, and it also happened to make sense to someone
else who had encountered a similar problem, and we were able to exchange
info that led to me solving my problem… weird, that almost sounds like
what support forums are supposed to be like. Please keep that in mind
before scolding someone for asking a question you don’t quite get.