Skip to content

Instantly share code, notes, and snippets.

@VasylShevchenko
Last active December 10, 2020 07:19
Show Gist options
  • Save VasylShevchenko/c33ed2d749cd53b9c5c7cec7d36f5d35 to your computer and use it in GitHub Desktop.
Save VasylShevchenko/c33ed2d749cd53b9c5c7cec7d36f5d35 to your computer and use it in GitHub Desktop.
1) Go to bitbucket add ssh key Known hosts
// Add server id_rsa.pub to this link
https://bitbucket.org/winstrategy/NAME_PROJECT/admin/access-keys/
// Generate SSH pub and private and add pub to server
https://bitbucket.org/winstrategy/NAME_PROJECT/admin/addon/admin/pipelines/ssh-keys
// Add dotnet service
deployer$ sudo vim /etc/systemd/system/dotnet.service
insert dotnet.service
// Restart systemd
deployer$ sudo systemctl daemon-reload
// Check service
$ sudo systemctl start dotnet.service
$ sudo systemctl stop dotnet.service
$ sudo systemctl restart dotnet.service
$ sudo systemctl status dotnet.service
// Enable service
$ sudo systemctl enable dotnet.service
deployer$ sudo visudo
// add
deployer ALL=NOPASSWD: /bin/systemctl restart nginx, /bin/systemctl status nginx
deployer ALL=NOPASSWD: /bin/systemctl restart dotnet.service, /bin/systemctl status dotnet.service
#!/bin/bash
echo "Deploy script start (deploy.sh)"
echo ""
echo "Git fetch ($ git fetch --all && git reset --hard origin/master)"
git fetch --all
git reset --hard origin/master
echo ""
echo "Restart DotNet ($ sudo /bin/systemctl restart name.service)"
sudo /bin/systemctl restart dotnet.service
sudo /bin/systemctl status dotnet.service
echo ""
echo "Restart Nginx ($ sudo /bin/systemctl restart nginx)"
sudo /bin/systemctl restart nginx
sudo /bin/systemctl status nginx
echo "Deploy script finish (deploy.sh)"
image: atlassian/default-image:latest
pipelines:
default:
- step:
deployment: production
script:
# - cat ./deploy.sh | ssh deployer@IP_SERVER
- echo "Deploy"
- ssh deployer@IP_SERVER 'cd /home/deployer/apps/app-name && sh bitbucket-deploy.sh && exit'
- echo "Deploy step finished"
[Unit]
Description=Example .NET Web API App running on Ubuntu
[Service]
WorkingDirectory=/home/deployer/apps/NAME_PROJECT
ExecStart=/usr/bin/dotnet /home/deployer/apps/NAME_PROJECT/NAME_PROJECT.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment