- Update the index of packages
$ sudo apt update- Update (upgrade) installed packages
$ sudo apt upgrade- Reboot system after package upgrade
$ sudo reboot- Download the package from https://dotnet.microsoft.com/download/dotnet-core/3.1 and get for example https://download.visualstudio.microsoft.com/download/pr/5ed60e45-f93a-4a8b-ab92-4034fcf00618/cf2aafe9bc91f28bd4d7b7436c31e27e/aspnetcore-runtime-3.1.7-linux-arm.tar.gz
- Create
bindirectory of the logged user (e.g. userpi)
$ mkdir ~/bin- Go to the
bindirectory and restore the dotnet package
$ cd ~/bin # got to bin directory
$ tar xzf ~/Downloads/aspnetcore-runtime-3.1.7-linux-arm.tar.gz- Check if dotnet is working
$ cd ~ # go to home directory
$ /home/pi/bin/dotnet --version # check if the executable file id OKHere dotnet is OK but is not visible in the system PATH. When you want to invoke it you have to run the full-path to the executable.
Easier but less clean way is to restore the dotnet in the /usr/bin directory which is included in the system PATH, but there are many other important executable files and it is restricted to super-user
$ cd /usr/bin # go to the system directory
$ tar xzf /home/pi/Downloads/aspnetcore-runtime-3.1.7-linux-arm.tar.gzHere the validation command is just
$ dotnet --version- Build and publish the dotnet wep application as Portable to a specified folder.
- Zip the published files.
- Move the .zip file to the destination server computer (via flash drive, sftp, scp, cloud storage shared link (e.g. Dropbox), etc.).
- Unzip the application to a specified folder on the server. Lets suppose that the folder is
/home/pi/my_application. In this filter there have to be the main application assembly .dll file, i.e. there have to exist the fileApplication.dll.
- Go to the application's folder
$ cd /home/pi/my_applicationThis is required, because the configuration file appsettings.json is the same directory as the main assembly Application.dll
2. Run the application
$ /home/pi/bin/dotnet Application.dllIf the port for the Kestrel is set to 80 there would be some problems with the permissions for starting the endpoints, so super-user privileges are needed
$ sudo /home/pi/bin/dotnet Application.dllHere everything should be OK.
Note
-
The easy way
- Install the Uncomplicated Firewall (UFW)
$ sudo apt install ufw $ sudo apt install gufw # this is GUI for the UFW
- Enable the UFW
$ sudo ufw enable- Add port 80 to the list of the allowed ports
$ sudo ufw allow 80/tcp- Check the status (optional)
$ sudo ufw status -
The not-so-easy way -
iptables(no need of addition software)Read https://www.binarytides.com/open-http-port-iptables-centos/ and https://linux.die.net/man/8/iptables and good luck!
In short
$ sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT $ sudo service iptables save # or sudo /etc/init.d/iptables save
Check of other device in the same network can reach the running web application by typing the IP address in the address bar of the browser.
-
Create shell script file to be executed as service
- Open text editor and create plain text file for the script. For example
/home/pi/bin/run-my-application.sh - The content of the file has to be like
#!/bin/bash cd /home/pi/my_application /home/pi/bin/dotnet Application.dll
- Make this script file executable
$ chmod +x /home/pi/bin/run-my-application.sh - Open text editor and create plain text file for the script. For example
-
Create service file
- Create empty file
$ sudo touch /etc/systemd/system/my_application.service- Edit the file
$ sudo nano /etc/systemd/system/my_application.service- Enter content like
[Unit] Description=My Application Service [Service] ExecStart=sudo /home/pi/bin/run-my-application.sh Type=forking RemainAfterExit=yes Restart=always [Install] WantedBy=multi-user.target
See https://askubuntu.com/questions/814/how-to-run-scripts-on-start-up
See https://www.freedesktop.org/software/systemd/man/systemd.service.html
-
Enable and start the service
$ sudo systemctl daemon-reload $ sudo systemctl enable my_application.service $ sudo systemctl start my_application.service
Reboot the system and the application should run as service.