Running an app on another box

  • Here is my situation:

    I have 3 machines (sql server, app server, file server). My app server runs a 3rd party program that is stored on the file server. I have written a procedure that monitors if the application goes down (it writes a timestamp to the db), but i need to be able to restart the application on the app server via sql. Can this be done?

    I have tried to create a batch file on the app server, but when i execute it by using xp_cmdshell, it tries to run the application locally on my sql box instead of the app server where the batch file is located. Is there anything I can do?

    Any help would be appreciated.

    Justin

  • If the procedure that moniters the application can restart the job use it.

    Or Use a windows service locally to execute the batch file.

    Regards,
    gova

  • The procedure that monitors the app is just a stored proc that runs as a job every few minutes. That's where I'm trying to restart the app from, but it tries to execute it on the sql server instead of the app server.

  • You're halfway there.  Running from the SQL server, you can execute 'xp_cmdshell' to spool off a job on the app server using the NT-shell "AT" command.  I have such a need on our servers, and here's how I run it from within a stored procedure, scheduling it for two minutes from "now":

    DECLARE @when VARCHAR (10), @cmd VARCHAR (8000), @appserver VARCHAR (30), @atcmd VARCHAR (200)

    SELECT @appserver = '<server name -- I think IPADDR also works>'

    SELECT @atcmd = '<command to execute on app server>'

    SELECT @when = LEFT (CONVERT (VARCHAR, DATEADD (MI, 2, GETDATE ()), 108), 5)

         , @cmd  = 'AT \\' + @appserver

                 + ' '     + @when

                 + ' '     + @atcmd

     EXEC master..xp_cmdshell @cmd

    Assuming the app server is copacetic with the network login you use to run SQLSERVERAGENT, this, or something like it, orta work.

  • Thanks, Lee!  That looks like it will work.  I'm just having one problem...my scheduled task won't work, because I need to provide a username and password to run it on the app server.  Is there a way I can pass this information?

  • Hmmmm....  I may be venturing into uncharted territory, so be advised.

    I assumed your login was a network login that owns the MSSQLSERVER and SQLSERVERAGENT services on your database server and could be granted sufficient permissions on the app server to run the AT command.  When you run something in 'xp_cmdshell' from the server, it assumes the security context of the owner of the SQLSERVERAGENT service.  Then, it's only a matter of making sure that the app server knows who that network login is and grants it sufficient permissions to schedule jobs.

    If you are running the database services with a local login (local to the database server), I don't know the best way, or if there even is a way.

  • You can also use PsExec of sysinternals

     

     


    * Noel

  • The login that runs the SQL services can create the scheduled task on the app server fine. My problem is that the scheduled task is not being supplied a user name and password to "run as", so it is using the Local System account on that app server. It doesn't work, because the Local System account on that app server does not have permissions on my file server to restart the executable.

    Is there a way, when creating the scheduled task via command line to pass it a user id/password to run the job as?

  • That sounds like an application issue, and I've probably helped as much as I can safely do so.  But that's never stopped me before.  You can either proceed to give the login sufficient permissions to run the app, or you schedule the app indirectly, through a *.BAT file that contains the connecting credentials.  That is, you schedule the *.BAT file to run, and the *.BAT file then calls your app.  This has security ramifications, but it ought to work, assuming I understand your problem.

    The AT command can schedule pretty much anything that can be expressed in a DOS line command.  If there's a place for a userid and password, you can include that, but again be careful you don't unsecure yourself to your detriment.

  • Lee, you'll have to forgive my ignorance on security, but I don't know how to assign permissions on a directory on a file server to a local system account from another server.

    I also don't know how to implement the connecting credentials into my batch file. Can you (or anyone) provide me an example of how to do this?

  • Security in computers is like gravity in physics.  In small amounts, it's easy, almost inconsequential.  In large amounts, it completely dominates everything around it.  It's one of the hardest things we get involved with.

    If you know how to call the app via command line and pass in credentials, you can just add those credentials inside the double-quotes in the AT command -- in the @atcmd variable in the example I gave you, above.  You can at least try it and see if it works, though you may balk (for good reason) at storing connection passwords in a flat file or a database executable.

     

     

  • My batch file has the command line credentials for the application (see below), I just can't get to the application without having the scheduled task that executes the batch file run as a user with permissions to it.

    Here's a sample of the batch file:

    kill app.exe

    start /D\\fileserver\startin_dir \\fileserver\executable_dir\app.exe /ulogin /wpass  /GO

  • Did you have a look at my post ?


    * Noel

  • Noel, I looked at it, and it might be able to do what i need, but there's so much red tape involved over here, it would take an act of congress for me to even get to install a freeware app.

  • Well, you might try setting up a domain user with permissions to run everything you need on all the servers, and set this domain user up as the owner of your database services.  This will work if your app has a "trusted" login connection option.

    The only other thing I could suggest, and I don't know if this would work, would be trying to set up services on the app server, and set the owner of the service to the login who has all the permissions you need.  Then you could use 'xp_cmdshell' from T-SQL to NET START the service.

    Good luck!

     

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic. Login to reply