官术网_书友最值得收藏!

Deployment

After a long tough software development project, having issues to get the final product running on the live system can be extremely stressful if there is a last minute hitch. It is good to think about deployment early in the development process, so that the application is suitable for the target environment.

We will take a look at how to deploy Dart on two common environments—Windows and Unix. Of course, every individual system can vary on the details, so you may have to check for equivalent settings or programs on your system and take into account any currently running applications, such as web servers.

Dependencies

The Dart SDK itself is the key dependency for any Dart server application. The application is run via the dart command-line application, with the main.dart script passed as a parameter.

This is straightforward for an interactive session; however, for a server application, we need to run the application when there is no user logged into the machine.

Tip

The Dart SDK is available as a separate download (not including developer tools) from

https://www.dartlang.org/downloads/.

Deploying on Unix

On a Linux or other Unix-like system, web applications can be launched within a console application called screen (lowercase s). The screen command allows the creation of other console sessions that can be left running in the background once the main session has ended.

A screen application can be created—the application is started, then the screen detached from, and the main session is ended. The web application is then left running. If a change has to be made, the detached screen can be reattached (this can be months or years later!) for any adjustments; for example, installation of a new version or configuration change.

This can be used on hosted systems where shell access (usually SSH) is allowed directly on a server.

Using the screen command

Log in to an interactive shell on your system as an appropriate user. To check whether screen is installed, run the following command to get the version and description:

Screen
Screen version 4.01.00devel (GNU) 2-May-06

Copyright (c) 2010 Juergen Weigert, Sadrul Habib Chowdhury
Copyright (c) 2008, 2009 Juergen Weigert, Michael Schroeder
...

If the program is not installed, use your package manager to install the package, simply called screen.

Launching a screen

Once screen application is running, press the Enter key and you will be at Command Prompt again. Press Ctrl+a, and the version screen will be displayed, showing us that we are not in a normal shell.

Use cd to go to the BlogServer folder, and start the Dart blog server:

dart bin/main.dart

Next, press Ctrl+a, Ctrl-d and you will see a message similar to the following one:

[detached from 398.pts-2.localhost]

You should be back in your regular terminal now. Run the command top (or any other program that lists the processes that are running on the system) to get a list of processes, and you will see Dart running in the background.

Run a web browser and navigate to the index.html page. The blog will be served from the editor debugging session.

To reconnect to this screen, use the command screen -r and you will be back in the session.

Tip

The screen command is a powerful tool, but it can be a little confusing to remember which screen is in play. It is recommended that you commit keyboard shortcuts to memory for navigation.

Deploying on Windows

On Windows, server applications are usually run as Window Services, or hosted via Internet Information Services in the case of .Net applications.

It is a relatively simple operation to place the Dart bin/main.dart command into a batch file so that it runs with a double-click on interactive sessions. It would be best to remove this requirement for a user to be logged in if, for example, the machine is unexpectedly rebooted, or the application crashes.

Using the NSSM tool

The free tool NSSM (Non-Sucking Service Manager) (available at http://nssm.cc/) has a range of features to manage services. One of these is to install any application as a service, as shown in the following screenshot:

Using the NSSM tool

The DartBlog service is installed and set as automatic startup, and is run under the Local System account:

Using the NSSM tool

Note that the service is stopped when the first installed. Depending on what the application is does, the service will need to run under an appropriate user account, such as writing to a file, or performing other operations.

Using a Microsoft solution

Some system administrators may be happier if they use a more official Microsoft-based solution.

As an alternative, Microsoft provides a tool called srvany, which is service that is used to launch other applications. It is an older tool (dating back to NT4 Resource Kit), but is commonly used for this purpose. For more information, refer to https://support.microsoft.com/en-us/kb/137890.

主站蜘蛛池模板: 雷波县| 阜阳市| 钟山县| 清新县| 邯郸市| 永兴县| 永德县| 鹿泉市| 香河县| 神池县| 太谷县| 星座| 凤山市| 襄汾县| 白朗县| 元江| 哈巴河县| 平乡县| 奉贤区| 福建省| 平乡县| 新密市| 赣榆县| 馆陶县| 石棉县| 泌阳县| 安吉县| 富平县| 宿松县| 曲阜市| 乌拉特中旗| 洪泽县| 互助| 长岛县| 合水县| 新余市| 兴文县| 巍山| 双辽市| 南阳市| 六盘水市|