2

For years, I've been able to do a build using a continuous build system like Jenkins and then remotely deploying my apps to various Unix servers. I can use the ssh and scp commands to do my bidding.

Now, I have a .NET build I'm doing. I've done the build using Jenkins and would now like to deploy to a remote .NET server. I need to shutdown the application, copy the files over, and then restart the application. I need to be able to do this remotely and via command line tools (no GUI tools). I am on a series of machines that are locked down, and cannot deploy stuff willy-nilly -- especially to the production machines.

Is there a mechanism that will allow me to remotely shutdown the server, deploy a new set of files, and restart the application?

BONUS QUESTION

I understand that a *.cab file is somewhat similar to a Java *.jar file. That is, you can deploy a single *.cab file to a server, and the server will treat it as if it's a bunch of files in a directory.

  • Is this correct? If so, I'd like to deploy things using the cab file.
  • There is a webapp.config file that's part of my build that's different for each and every server. I'd prefer to create a cab file that does not contain the webapp.config file, that way, the cab file I have can be deployed to every machine without changing it (only the webapp.config file has to be changed).

Thanks


Addendum

I just can't win...

I have a build on machine02 and I need to deploy to machine06. Machine06 is in a DMZ, so I can't add a domain user on it. I can only create local accounts.

With sc, I can access remote systems, but the account I'm running sc from also needs to exist on the remote system. Since I can't create a domain account on machine06, and I can't add a computer local account to another Windows system (i.e., make machine06\user an administrator on machine02 too)., I can't use sc.

I tried the lp commands from Sysinternals. These allow me to specify a user name and password (which I assume is for the other system. However, I get the following error:

C:\Windows\system32>pslist \\machine02 -user remuser02 -password Swordfish

pslist v1.29 - Sysinternals PsList
Copyright (C) 2000-2009 Mark Russinovich
Sysinternals

Cannot connect to remote registry on MACHINE02:
Access is denied.
Failed to take process snapshot on MACHINE02.
Make sure that the Remote Registry service is running on the remote system, 
that you havefirewall ports allow RPC access, and your account has read
access the following key on the remote system:
    HKLM\Software\Microsoft\Windows NT\CurrentVersion\Perflib


C:\Windows\system32>

Since that user is an admin on machine02, I am sure that user has read access to the Windows registry key, and I verified that Remote Registry Access is on. I suspect that the router is blocking RPC calls.

So, sc is out since I can't specify an account to use. The Sysinternals PS tools are out. I can't add the sshd on the server.

Community
  • 1
  • 1
David W.
  • 105,218
  • 39
  • 216
  • 337
  • just wondered why you aren't using powershell? – Matt Jun 22 '11 at 18:33
  • @Matt: I really don't know powershell. Will Powershell allow me to run a command on a remote system? What if the remote system doesn't have Powershell on it? Or, is Powershell on on Windows systems now? – David W. Jun 22 '11 at 18:51
  • @David-W yeah PowerShell is the scripting tool for windows. v1 has some commands that can use remote calls (the computername parameter on the get-service below) and v2 has remoting (similar to ssh). What OS are you running on the boxes? – Matt Jun 22 '11 at 19:50
  • you should be able to try out powershell from your build server by typing "powershell" (without quotes) in the run box or a command prompt. – Matt Jun 22 '11 at 19:52
  • Just checked and Powershell is on the servers. There's nothing about remote commands in the help, but found information on the Internet. I'd say you've answered my question, but you didn't provide an official answer. Makes it hard to mark this as "accept". Anyway, I need to test it before I can do anything. Thanks. – David W. Jun 22 '11 at 20:40
  • dude, what about the answer below from me? i actually gave you the commands to use and people voted for it... :-s – Matt Jun 22 '11 at 21:25

4 Answers4

2

When deploying web applications before I've used vbscript and powershell plus good old fashioned xcopy (though I'd agree robocopy is probably a better copy replacement).

So going through the requirements - I think this is the sort of thing you want to do (this should be done form a PowerShell command prompt):

get-service iisadmin -ComputerName TARGETMACHINE | Stop-Service -force

xcopy source dest

get-service iisadmin -ComputerName TARGETMACHINE | Start-Service

I wouldn't use *.cab unless you wanted compression for transferring the files then I'd use a *.zip file. I don't believe their is any real difference between the two but in general *.cab files are used in msi deployments.

Personally, unless you have someone how understands MSI versioning well, I don't think MSI should be used to deploy files to a web server. And even if someone did understand it I still like it's only useful for tracking what's installed where which can be achieved many ways whilst avoiding autoupdate etc...

As it's IIS you may what to remove the temporary asp.net files whilst the web site is down.

I've made the assumption (from the tags) that this is a web application, hence iisadmin in the code. This would equally work with any service.

HTH, Matt

Matt
  • 1,931
  • 12
  • 20
1

You could use netsvc.exe to stop and start the IIS service on the remote machine

SYNTAX: NETSVC servicename \\computername /start  (or /stop)
Patrick McDonald
  • 64,141
  • 14
  • 108
  • 120
  • Thanks. That's exactly what I needed. As for transfering the files, I can mount a share drive, and delete/copy what I need that way. – David W. Jun 19 '11 at 23:41
  • Oops! Doesn't look like `netsvc` is available for Windows Server 2008 or Windows Server 2003. However, you can also use the [sc](http://support.microsoft.com/kb/251192) command to do the same thing. One of the issues I've had with Microsoft is changing tools on you. `cabarc` is no more. You have to use `makecab` which has completely different syntax and doesn't work with Ant's `` task. – David W. Jun 20 '11 at 15:24
  • Can't use the `sc` command. I have two different logins on both machines, and `sc` simply assumes similar logings. I have to use the psTools. – David W. Jun 20 '11 at 17:13
  • Is using runas (http://technet.microsoft.com/en-us/library/bb490994.aspx) a possibility to run sc as the other user? – Patrick McDonald Jun 20 '11 at 23:12
  • you could also look at psexec, also from sysinternals (http://technet.microsoft.com/en-us/sysinternals/bb897553) – Patrick McDonald Jun 20 '11 at 23:20
  • This article seems quite comprehensive: http://www.windowsitpro.com/article/remote-computing/psexec – Patrick McDonald Jun 20 '11 at 23:23
1

I see you have already accepted an answer, but I thought I would add this, because maybe it is useful to someone else:

You could also use PsTools. It allows you to remotely execute commands, stop and start services, copy files etc. (No installation needed on the target host).

mydoghasworms
  • 18,233
  • 11
  • 61
  • 95
  • Looks great, have sysinternals installed but there are so many features its hard to keep up :) – Patrick McDonald Jun 20 '11 at 12:20
  • Turns out that `netsvc` isn't available anymore for Windows 2008 and 2003 servers. I ended up using `sc` which now seems to combine both the old `sc` (which could only operate on local servers) and `netsvc` commands. – David W. Jun 20 '11 at 15:26
  • Augh! The PsTools allow me to connect remotely, and I can pass the user name and password to the other system, but now I'm told that the Remote Registry Server must be running on the other system. Drats and Darn. – David W. Jun 20 '11 at 17:13
  • Windows: You just can't "win" :-D This is highly frustrating. Being production servers, I guess you will have tough time trying to convince the admins to allow the Registry Server to be enabled, right? – mydoghasworms Jun 22 '11 at 06:13
0

Perhaps you want to try a Windows version of an SSH server? For example http://mobassh.mobatek.net/. As usual, the free version has fewer features, but if you are able to execute commands remotely, you might be able to do carry your deployment tasks.

mydoghasworms
  • 18,233
  • 11
  • 61
  • 95
  • SSH is out. I'd have to get SSHD running on all the servers in order to get this to work, and I can't touch those production servers I have to deploy to. I'm hoping that there is some way of remotely talking to an ISS server in order to stop and start it up. I think I'll be able to use `net use` to mount a Windows share and to copy the files that way. The problem is controlling the ISS servers from a remote system. – David W. Jun 17 '11 at 21:12