- Dart:Scalable Application Development
- Davy Mitchell Sergey Akopkokhyants Ivo Balbaert
- 802字
- 2021-07-09 18:56:22
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.
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.
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.
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:

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

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.
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.
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- Delphi程序設(shè)計基礎(chǔ):教程、實驗、習(xí)題
- Twilio Best Practices
- 新手學(xué)Visual C# 2008程序設(shè)計
- Mastering Unity Shaders and Effects
- Eclipse Plug-in Development:Beginner's Guide(Second Edition)
- Learning Selenium Testing Tools(Third Edition)
- iOS應(yīng)用逆向工程(第2版)
- 深入淺出PostgreSQL
- Hands-On Full Stack Development with Go
- Visual Basic程序設(shè)計
- Visualforce Developer’s guide
- HTML5 WebSocket權(quán)威指南
- MySQL從入門到精通
- Java程序性能優(yōu)化實戰(zhàn)