How do you compile an Erlang program into a standalone windows executable? - windows

Richard of Last.fm over at metabrew has ported his apps to Erlang. It was also done by riak, couchdb and others. He mentions extracting the needed parts, or including the whole VM into the distribution. Main trait here is: the program does not require Erlang to be installed on the target machine.
So the question is, how do you, step by step, package an Erlang program into a windows (and, less important, linux) executable?
P.S. I've seen the SAE project, and I've read all the relevant questions here. None answer my question.

Create a portable version of Erlang (for example using method from this discussion group: Erlang on Windows from USB). The most important part in this exercise is the creation of the erl.ini file with correct paths which can be used to start Erlang from any desired location.
Create an Erlang release of your application and the release boot script. For instructions see Erlang documentation about releases.
Create a Windows command line script to boot your application. This will simply run Erlang with your boot script as the parameter (e.g. erl -boot someapp). Erlang will read the erl.ini file to load your application and system libraries from correct locations.
Create a Windows setup application with all the relevant parts packaged in:
the Erlang distribution
the erl.ini file with all the paths as variables to be filled in by the setup application
the release of your application (all the beam files and the boot script)
the command line script to boot the application using the boot script
How it should work from the Windows installer point of view:
Ask user where to install the application (or use some default location in Program Files)
Copy the Erlang distribution, your application and the boot script to the correct location
Update erl.ini and the command line script to use the chosen location
Create icons or autostart entries that will execute the command line script
Now when user clicks the icon or executes the command line script in another way they will in fact run Erlang from the custom location, which in turn will boot your application according to the Erlang boot script. This is just a general idea because the command line script should for example check if Erlang isn't already running when user starts the application for the second time, or it may need to be able to uninstall it.

Related

qt program deployed on mac. config file not writing when standalone app launched, works when run from within qt creator

I have a program that I have developed for mac osx. When the program is run from within Qt creator, a log file and a config.cfg file are created in the myapp.app/Contents/MacOS folder, alongside the executable. This is the correct behaviour, the program needs these files.
When I deploy the app to run standalone (by linking the required libraries using macdeploymentqt tool) the app launches and runs correctly however the log and config.cfg file do not get written to the myapp.app/Contents/MacOS folder and so settings can't be read in.
Is there anyway to get around this? Has anyone encountered this before?
Mitch
osx will likely not allow you writing to your bundle location on installed apps, for security reasons and because it may conflict when multiple users are using your app.
To be cross platform, you could write instead to:
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
which resolves to
~/Library/Application Support/<APPNAME>
and
C:/Users/<USER>/AppData/Local/<APPNAME>
or equivalent on windows.
You're never supposed to write to the application bundle, whether on Mac or on Windows. Even on Windows, it will not work if your user isn't an administrator. This idea last made sense on Windows 95 - not even on Windows NT. Don't do it.

I want to install complete software using command line for test automation

Let take as one example, I want to install Java on my machine using the command line so I just type below command as administrator:
start /w jre-7u51-windows-x64.exe
I also tried below command in order to get help from command line
jre-7u51-windows-x64.exe /?
Now a pop up appears in which we need to click the "install" button.
I don't want any user interaction and I want complete installation using command line.
Is there any way to automate the install button click?
If any other technologies available for this also let me know.
You need to use the /s silent installation switch.
Source How do I arrange a silent (unattended) Java installation?
Command-Line Installation
The Java SE 7 Windows Offline Installer command has the following syntax:
<jre>.exe [/s] [INSTALLDIR=<drive>:\<JRE_install_path>] [STATIC=1]
[WEB_JAVA=0/1] [WEB_JAVA_SECURITY_LEVEL=VH/H/M] [SPONSORS=0]
Note:
.exe is the single executable installer for the JRE.
/s, if used, indicates a silent installation.
INSTALLDIR, if used, specifies the drive and path of the JRE. If INSTALLDIR is not specified, the installation will go into C:\Program
Files\java\jre (default location).
STATIC=1, if used, specifies a static installation. For more information about static installations, see Static Installation in
Patch-in-Place and Static JRE Installation.
WEB_JAVA=0, if used, disables any Java application from running in the browser.
WEB_JAVA=1, the default, enables Java applications in
the browser. This field is available as of the 7u10 release. For more
information, see Setting the Security Level of the Java Client.
WEB_JAVA_SECURITY_LEVEL, if used, sets the security level of unsigned Java apps running in a browser. The possible values for this
field are VH (very high), H (high, the default), or M (medium). This
field is available as of the 7u10 release. For more information, see
Setting the Security Level of the Java Client.
SPONSORS=0, if used, entirely bypasses sponsor offers such as browser add-ons. This field is available as of the 7u55 release. Note
that sponsor offers, and therefore this functionality, is only
applicable to online 32 bit JRE installers and Auto Update mechanisms.
Source JRE Installer Options
Installation Configurations
Example 1
Suppose the JRE installer is
jre-7-windows-i586.exe and you want to install the following
configuration:
Perform a Windows Installation
Install the JRE core, additional fonts, colors, and Soundbank
The command to install the above mentioned configuration is as
follows: jre-7-windows-i586.exe /s
Example 2
Suppose the JRE installer is jre-7-windows-i586.exe and you
want to install the following configuration:
Perform a Windows Offline Installation and install the JRE on D drive at java\jre
Have all features of the JRE installed
The command to install the above mentioned configuration is as
follows: jre-7-windows-i586.exe /s INSTALLDIR=D:\java\jre
Note: To keep the MS-DOS window open, until the installation of Java
is complete use the start /w command as follows: start /w
jre-7-windows-i586.exe /s
"I want the command in terms of general use for other applications not only java"
Note that there is no general solution to this problem, since there are many different types of installer and installers for different programs will likely have different "popups" (and may even change when new version of the program are released).
Read the whole of following link for a full discussion of how difficult this is.
Unattended/Silent Installation Switches for Windows Apps
The goal of this document is to collect instructions for performing unattended / silent installations of many popular application installers. Such instructions are useful for automating these installations.
The document includes instructions for silent installation using many different installer types.
It also includes a suggestion for a tool AutoIt:
AutoIt can simulate key presses and mouse clicks, following a script customarily named with a .aut or a .au3 extension.
Most installers have a sufficiently simple and consistent interface that a very short AutoIt script suffices to automate their installation.
...
AutoIt scripts do have drawbacks.
First, you must be careful when upgrading to new releases of an application, since the installer's UI may have changed.
More worryingly, AutoIt scripts are theoretically unreliable because they do not let you determine when a sub-process has exited. You can tell when AutoIt itself exits, but that is not the same thing at all. For example, an installer's last window might disappear while the installer was still working. Your master script, waiting only for the AutoIt executable, would then proceed, starting another installation or rebooting the machine.
There are other such tools available.

Create Windows service from executable

Is there any quick way to, given an executable file, create a Windows service that, when started, launches it?
To create a Windows Service from an executable, you can use sc.exe:
sc.exe create <new_service_name> binPath= "<path_to_the_service_executable>"
You must have quotation marks around the actual exe path, and a space after the binPath=.
More information on the sc command can be found in Microsoft KB251192.
Note that it will not work for just any executable: the executable must be a Windows Service (i.e. implement ServiceMain). When registering a non-service executable as a service, you'll get the following error upon trying to start the service:
Error 1053: The service did not respond to the start or control request in a timely fashion.
There are tools that can create a Windows Service from arbitrary, non-service executables, see the other answers for examples of such tools.
Use NSSM( the non-Sucking Service Manager ) to run a .BAT or any .EXE file as a service.
http://nssm.cc/
Step 1: Download NSSM
Step 2: Install your sevice with nssm.exe install [serviceName]
Step 3: This will open a GUI which you will use to locate your executable
Extending (Kevin Tong) answer.
Step 1: Download & Unzip nssm-2.24.zip
Step 2: From command line type:
C:\> nssm.exe install [servicename]
it will open GUI as below (the example is UT2003 server), then simply browse it to: yourapplication.exe
More information on: https://nssm.cc/usage
these extras proved useful.. need to be executed as an Administrator
sc create <service_name> binpath= "<binary_path>"
sc stop <service_name>
sc queryex <service_name>
sc delete <service_name>
If your service name has any spaces, enclose in "quotes".
Many existing answers include human intervention at install time. This can be an error-prone process. If you have many executables wanted to be installed as services, the last thing you want to do is to do them manually at install time.
Towards the above described scenario, I created serman, a command line tool to install an executable as a service. All you need to write (and only write once) is a simple service configuration file along with your executable. Run
serman install <path_to_config_file>
will install the service. stdout and stderr are all logged. For more info, take a look at the project website.
A working configuration file is very simple, as demonstrated below. But it also has many useful features such as <env> and <persistent_env> below.
<service>
<id>hello</id>
<name>hello</name>
<description>This service runs the hello application</description>
<executable>node.exe</executable>
<!--
{{dir}} will be expanded to the containing directory of your
config file, which is normally where your executable locates
-->
<arguments>"{{dir}}\hello.js"</arguments>
<logmode>rotate</logmode>
<!-- OPTIONAL FEATURE:
NODE_ENV=production will be an environment variable
available to your application, but not visible outside
of your application
-->
<env name="NODE_ENV" value="production"/>
<!-- OPTIONAL FEATURE:
FOO_SERVICE_PORT=8989 will be persisted as an environment
variable to the system.
-->
<persistent_env name="FOO_SERVICE_PORT" value="8989" />
</service>
Same as Sergii Pozharov's answer, but with a PowerShell cmdlet:
New-Service -Name "MyService" -BinaryPathName "C:\Path\to\myservice.exe"
See New-Service for more customization.
This will only work for executables that already implement the Windows Services API.
I've tested a good product for that: AlwaysUp. Not free but they have a 30 days trial period so you can give it a try...
I created the cross-platform Service Manager software a few years back so that I could start PHP and other scripting languages as system services on Windows, Mac, and Linux OSes:
https://github.com/cubiclesoft/service-manager
Service Manager is a set of precompiled binaries that install and manage a system service on the target OS using nearly identical command-line options (source code also available). Each platform does have subtle differences but the core features are mostly normalized.
If the child process dies, Service Manager automatically restarts it.
Processes that are started with Service Manager should periodically watch for two notification files to handle restart and reload requests but they don't necessarily have to do that. Service Manager will force restart the child process if it doesn't respond in a timely fashion to controlled restart/reload requests.
You can check out my small free utility for service create\edit\delete operations. Here is create example:
Go to Service -> Modify -> Create
Executable file (google drive): [Download]
Source code: [Download]
Blog post: [BlogLink]
Service editor class: WinServiceUtils.cs
Probably all your answers are better, but - just to be complete on the choice of options - I wanted to remind about old, similar method used for years:
SrvAny (installed by InstSrv)
as described here:
https://learn.microsoft.com/en-us/troubleshoot/windows-client/deployment/create-user-defined-service
I have another method, using the open-source library called Topshelf.
I used it in a c# project, but maybe its available in different programming languages.
Here's a video that explains how to use it a little.
https://www.youtube.com/watch?v=y64L-3HKuP0
The crux of this issue for a lot of people is that you can't install any old .exe as a service unless you use the old method that Tomeg used. I couldn't find the windows nt toolkit that's needed to get that to work.
I was stuck in a corner and this was my way out.

Erlang application launch on a Windows server

I have an Erlang application that is deployed on a server with Windows Server 2008.
The way I do this:
Copy application folder in Erlang lib directory.
Open command line (cmd). Execute erl.
Execute application:start(app_name) in Erlang shell.
Are there any better approaches to launch the application? How to make the application to launch on Windows startup?
I have no experience with Windows but...
`1. First of all, you might want to have a look to the concept of release in Erlang. Essentially,
When we have written one or more applications, we might want to create a complete system consisting of these applications and a subset of the Erlang/OTP applications. This is called a release.
`2. Then, you might want to create a script that contains something like:
erl -boot ch_rel-1
Where essentially you're starting Erlang/OTP using a boot script that you created above (just follow the instructions in the releases page)
`3. This article explains how to create startup scripts in Windows Server 2008 (not tested, just googled):
http://technet.microsoft.com/en-us/magazine/dd630947.aspx
Hope this helps. Nice question.
Perhaps rebar might help. It makes building an app skeleton and release quite easy. A nice tutorial is here.
After getting familiar with releases, take a look at manual pages (erl -man ) for start_erl and erlsrv. I used them to start embedded system ( http://www.erlang.org/doc/embedded/embedded_nt.html ) in windows 2003, hope it still works for you in windows 2008.
After creating service with erlsrv it is possible to manage it via standard windows command line and GUI tools, e.g. setting start mode and restart policy.
May be you could start just your application by supplying "-s app_name" as erl/start_erl additional flag, but I didn't try that, as I had to go long route with embedded system release. In that case make sure you have "start() -> application:start(?MODULE)." in your "app_name.erl".

using Eclipse to develop for embedded Linux on a Windows host

I got a question of using Eclipse to develop for embedded Linux on a Windows host
Here are now I have and where I am.
1. a Windows host that have the latest Eclipse + CDT (c/c++ development tools) installed
2. a Ubuntu host (ssh + samba installed) that contains sources and toolschain to build the project. (the windows and ubuntu hosts are sitting within one network segment (In LAN).)
3. I can use the following commands to build this project under Ubuntu.
# chroot dummyroot
# cd /home/project/Build
# sh Build date +%Y%m%d%H%M%S
4. I am now trying to create an eclipse C++ project to achieve the goad of the step 3, but I have been stuck here for a while. any ideas of how it can be done?
Speaking from experience, attempting to develop embedded Linux on a Windows host is a world of pain and frustration. Emphasis on attempting -- I'd like to meet someone who completed a serious project in this way, or who can explain how working in Windows made job easier.
Windows can be a great development environment for many tasks, but it's a lousy, lousy environment for embedded Linux. There are tools out there to help you do this, but everything is much harder compared to working on a Linux host. The toolchains are older and buggier. You will constantly fight with your crosscompilers and GNU autotools trying to get packages to compile. (Wait till you try to compile one of the many packages that needs to build an intermediate binary and then executes that as part of its build process.)
You probably have reasons for keeping your desktop in Windows -- just run a Linux virtual machine.
Eclipse CDT can execute arbitrary commands, such as
ssh username#target build_script
using the external builder. If you are using gcc on the target eclipse cdt can parse the output of the gcc and make from the ssh session and send you to the correct source path (if that path matches the path generated by gcc). Although this might not work windows->linux
With Embedded Linux, I've attempted to run Virtual Machines using Ubunutu, Xubutunu, Debian. I have been developing for a long time. I design hardware and develop low level firmware, to test said hardware. I cannot get anything to work on instructions given, as in an unified IDE and development system such as I am used to (i.e. Codewarrior, MPLAB, Code Composer) If Embedded Linux is so useful and easy how is it I cannot get a single one of instructions from Yocto, Freescale, Timesys, anywhere to work? Every-time there is a directory change, or a directory that no longer exists, or even a file that is not there. Surely there something that I can use..

Resources