Skip to content

Commit 258b1bd

Browse files
New script: Dotnet ASP.NET Web Server (#1501)
* Added files * Update dotnetaspwebapi.json * Updated build.func reference back to the original repos one * Update dotnetaspwebapi.json for ubuntu 24.04 * Update dotnetaspwebapi.sh for ubuntu 24.04 * Update dotnetaspwebapi-install.sh for ubuntu 24.04 * Update install/dotnetaspwebapi-install.sh Co-authored-by: Michel Roegl-Brunner <[email protected]> * Updated for review * Fixed FTP authentication * Update dotnetaspwebapi-install.sh Changed the service name to a static one --------- Co-authored-by: Michel Roegl-Brunner <[email protected]>
1 parent 6d4eb9c commit 258b1bd

File tree

3 files changed

+198
-0
lines changed

3 files changed

+198
-0
lines changed

ct/dotnetaspwebapi.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
3+
# Copyright (c) 2021-2025 community-scripts ORG
4+
# Author: Kristian Skov
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-9.0&tabs=linux-ubuntu
7+
8+
# App Default Values
9+
APP="Dotnet ASP Web API"
10+
var_tags="web"
11+
var_cpu="1"
12+
var_ram="1024"
13+
var_disk="8"
14+
var_os="ubuntu"
15+
var_version="24.04"
16+
var_unprivileged="0"
17+
18+
# App Output & Base Settings
19+
header_info "$APP"
20+
base_settings
21+
22+
# Core
23+
variables
24+
color
25+
catch_errors
26+
27+
function update_script() {
28+
header_info
29+
check_container_storage
30+
check_container_resources
31+
if [[ ! -d /var/www ]]; then
32+
msg_error "No ${APP} Installation Found!"
33+
exit
34+
fi
35+
msg_info "Updating ${APP} LXC"
36+
apt-get update &>/dev/null
37+
apt-get -y upgrade &>/dev/null
38+
msg_ok "Updated Successfully"
39+
exit
40+
}
41+
42+
start
43+
build_container
44+
description
45+
46+
msg_ok "Completed Successfully!\n"
47+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
48+
echo -e "${INFO}${YW} Access it using the following IP:${CL}"
49+
echo -e "${TAB}${GATEWAY}${BGN}${IP}:80${CL}"

install/dotnetaspwebapi-install.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2021-2025 community-scripts ORG
4+
# Author: Kristian Skov
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
7+
source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
8+
color
9+
verb_ip6
10+
catch_errors
11+
setting_up_container
12+
network_check
13+
update_os
14+
15+
msg_info "Installing Dependencies"
16+
$STD apt-get update
17+
$STD apt-get install -y \
18+
ssh \
19+
software-properties-common
20+
$STD add-apt-repository -y ppa:dotnet/backports
21+
$STD apt-get install -y \
22+
dotnet-sdk-9.0 \
23+
vsftpd \
24+
nginx
25+
msg_ok "Installed Dependencies"
26+
27+
msg_info "Configure Application"
28+
var_project_name="default"
29+
read -r -p "Type the assembly name of the project: " var_project_name
30+
echo "Target assembly: '${var_project_name}'"
31+
msg_ok "Application Configured"
32+
33+
msg_info "Setting up FTP Server"
34+
useradd ftpuser
35+
FTP_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13)
36+
usermod --password $(echo ${FTP_PASS} | openssl passwd -1 -stdin) ftpuser
37+
mkdir -p /var/www/html
38+
usermod -d /var/www/html ftp
39+
usermod -d /var/www/html ftpuser
40+
chown ftpuser /var/www/html
41+
42+
sed -i "s|#write_enable=YES|write_enable=YES|g" /etc/vsftpd.conf
43+
sed -i "s|#chroot_local_user=YES|chroot_local_user=NO|g" /etc/vsftpd.conf
44+
45+
systemctl restart -q vsftpd.service
46+
47+
{
48+
echo "FTP-Credentials"
49+
echo "Username: ftpuser"
50+
echo "Password: $FTP_PASS"
51+
} >> ~/ftp.creds
52+
53+
msg_ok "FTP server setup completed"
54+
55+
msg_info "Setting up Nginx Server"
56+
rm -f /var/www/html/index.nginx-debian.html
57+
58+
sed "s/\$var_project_name/$var_project_name/g" >myfile <<'EOF' >/etc/nginx/sites-available/default
59+
map $http_connection $connection_upgrade {
60+
"~*Upgrade" $http_connection;
61+
default keep-alive;
62+
}
63+
server {
64+
listen 80;
65+
server_name $var_project_name.com *.$var_project_name.com;
66+
location / {
67+
proxy_pass http://127.0.0.1:5000/;
68+
proxy_http_version 1.1;
69+
proxy_set_header Upgrade $http_upgrade;
70+
proxy_set_header Connection $connection_upgrade;
71+
proxy_set_header Host $host;
72+
proxy_cache_bypass $http_upgrade;
73+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
74+
proxy_set_header X-Forwarded-Proto $scheme;
75+
}
76+
}
77+
EOF
78+
systemctl reload nginx
79+
msg_ok "Nginx Server Created"
80+
81+
msg_info "Creating Service"
82+
cat <<EOF >/etc/systemd/system/kestrel-aspnetapi.service
83+
[Unit]
84+
Description=.NET Web API App running on Linux
85+
86+
[Service]
87+
WorkingDirectory=/var/www/html
88+
ExecStart=/usr/bin/dotnet /var/www/html/$var_project_name.dll
89+
Restart=always
90+
# Restart service after 10 seconds if the dotnet service crashes:
91+
RestartSec=10
92+
KillSignal=SIGINT
93+
SyslogIdentifier=dotnet-${var_project_name}
94+
User=root
95+
Environment=ASPNETCORE_ENVIRONMENT=Production
96+
Environment=DOTNET_NOLOGO=true
97+
98+
[Install]
99+
WantedBy=multi-user.target
100+
EOF
101+
systemctl enable -q --now kestrel-aspnetapi.service
102+
msg_ok "Created Service"
103+
104+
motd_ssh
105+
customize
106+
107+
msg_info "Cleaning up"
108+
$STD apt-get -y autoremove
109+
$STD apt-get -y autoclean
110+
msg_ok "Cleaned"

json/dotnetaspwebapi.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name":"Dotnet ASP Web API",
3+
"slug":"dotnetaspwebapi",
4+
"categories":[
5+
0
6+
],
7+
"date_created":"2025-01-15",
8+
"type":"ct",
9+
"updateable":true,
10+
"privileged":true,
11+
"interface_port":80,
12+
"documentation":"https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-9.0&tabs=linux-ubuntu",
13+
"website":"https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-9.0&tabs=linux-ubuntu",
14+
"logo":"https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Microsoft_.NET_logo.svg/456px-Microsoft_.NET_logo.svg.png",
15+
"description":"Automatically setup a ASP.NET server up, as well as a FTP server so you can publish to this container from Visual Studio.",
16+
"install_methods":[
17+
{
18+
"type":"default",
19+
"script":"ct/dotnetaspwebapi.sh",
20+
"resources":{
21+
"cpu":1,
22+
"ram":1024,
23+
"hdd":8,
24+
"os":"Ubuntu",
25+
"version":"24.04"
26+
}
27+
}
28+
],
29+
"default_credentials":{
30+
"username":null,
31+
"password":null
32+
},
33+
"notes":[
34+
{
35+
"text":"FTP server credentials: `cat ~/ftp.creds`",
36+
"type":"info"
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)