Last active
July 5, 2019 08:18
-
-
Save Dzoge/8adb0c80aabb12309c030663247a230a to your computer and use it in GitHub Desktop.
Create .NET Core 2.2 runtime production environment on Centos 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# for a quick installation of this script run the following command | |
# bash <(curl -L https://gist.github.com/Dzoge/8adb0c80aabb12309c030663247a230a/raw) | |
# Update Packages | |
yum upgrade -y | |
# Install dotnet runtime | |
rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm | |
yum update -y | |
yum install dotnet-sdk-2.2 -y | |
dotnet --list-runtimes | |
runtimes_count=$(dotnet --list-runtimes | grep Microsoft.AspNetCore | wc -l) | |
if [ $runtimes_count = "0" ]; then | |
echo "Error: DotNet core runtimes not found" 1>&2 | |
exit 1 | |
fi | |
# Preapare infrastructure for web application | |
useradd www | |
mkdir /var/www | |
cd /var/www | |
printf "\n\nEnter your web application name\n" | |
read -p "(this is the main dll file of your app without dll suffix): " app_name | |
printf "\n\nEnter TCP Port number for the kestel listener\n" | |
read -p "(default is 5000): " -i 5000 -e listener_port | |
if [[ -n ${listener_port//[0-9]/} ]]; then | |
echo "Error: Invalid listener port number" 1>&2 | |
exit 2 | |
fi | |
mkdir $app_name | |
chown -R www:www /var/www | |
printf "\n\nYou should copy your web application files into the following folder:\n" | |
echo /var/www/$app_name | |
printf "\n\n" | |
# Create service for dotnet web application process | |
printf "\ | |
[Unit]\n\ | |
Description=$app_name - .NET Core web application\n\ | |
\n\ | |
[Service]\n\ | |
WorkingDirectory=/var/www/$app_name\n\ | |
ExecStart=/usr/bin/dotnet /var/www/$app_name/$app_name.dll\n\ | |
Restart=always\n\ | |
RestartSec=10\n\ | |
SyslogIdentifier=$app_name\n\ | |
User=www\n\ | |
Environment=ASPNETCORE_URLS="http://*:$listener_port" | |
Environment=ASPNETCORE_ENVIRONMENT=Production\n\ | |
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false\n\ | |
Environment=DOTNET_CLI_TELEMETRY_OPTOUT=false\n\ | |
\n\ | |
[Install]\n\ | |
WantedBy=multi-user.target\n" > /etc/systemd/system/$app_name.service | |
firewall-cmd --permanent --add-port=$listener_port/tcp | |
firewall-cmd --reload | |
firewall-cmd --list-ports | grep $listener_port | |
systemctl enable $app_name | |
#systemctl start $app_name | |
#sleep 5 | |
#systemctl status $app_name | |
#service_check=$(systemctl status $app_name | grep "active (runing)" | wc -l) | |
#if [ $service_check <> "0" ]; then | |
# echo "Error: Service $appname is not running" 1>&2 | |
# exit 1 | |
#fi | |
# Request homepage content | |
#printf "\n" | |
#curl -v -s http://127.0.0.1:$listener_port 1> /dev/null | |
#printf "\n" | |
# Install performance tools | |
# https://github.com/iovisor/bcc/blob/master/INSTALL.md#centos---source | |
yum install -y kernel-devel perf epel-release | |
yum update -y | |
yum groupinstall -y "Development tools" | |
yum install -y elfutils-libelf-devel cmake3 git bison flex ncurses-devel luajit luajit-devel | |
yum install -y cmake | |
yum install -y centos-release-scl | |
yum-config-manager --enable rhel-server-rhscl-7-rpms | |
yum install -y devtoolset-7 llvm-toolset-7 llvm-toolset-7-llvm-devel llvm-toolset-7-llvm-static llvm-toolset-7-clang-devel | |
source scl_source enable devtoolset-7 llvm-toolset-7 | |
printf "\ | |
#!/bin/bash\n\ | |
\n\ | |
source scl_source enable devtoolset-7 llvm-toolset-7\n\ | |
\n" > /etc/profile.d/devtools-enable-sclsource.sh | |
chmod +x /etc/profile.d/devtools-enable-sclsource.sh | |
cd ~/ | |
git clone https://github.com/iovisor/bcc.git | |
mkdir bcc/build | |
cd bcc/build | |
cmake .. -DCMAKE_INSTALL_PREFIX=/usr | |
make | |
make install | |
cd ~/ | |
rm -rf bcc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment