使用gitlab ci停止digitalocean ubuntu.net上的服务器

使用gitlab ci停止digitalocean ubuntu.net上的服务器,.net,gitlab,gitlab-ci,digital-ocean,.net,Gitlab,Gitlab Ci,Digital Ocean,我正在使用gitlab ci在Digitalocean上部署.net应用程序。使用gitlab runner,我在gitlab上构建项目,使用“dotnet build”,下一步我需要停止Digitalocean上的服务器以运行新版本的rsync 如果.net不在docker容器中,我如何停止它 我的步骤如下所示: - - "dotnet build" - cd .. - ssh $SERVER_USER@$PROD_SERVER_IP ' -

我正在使用gitlab ci在Digitalocean上部署.net应用程序。使用gitlab runner,我在gitlab上构建项目,使用“dotnet build”,下一步我需要停止Digitalocean上的服务器以运行新版本的rsync

如果.net不在docker容器中,我如何停止它

我的步骤如下所示:

-
    - "dotnet build"
    - cd ..
    - ssh $SERVER_USER@$PROD_SERVER_IP '
    - /home/myproject
    // here needs step for stoping
    - rsync -az ./server/bin/ $SERVER_USER@$PROD_SERVER_IP:/home/myproject
    # Non interactive ssh gracefully reloads server
    - ssh $SERVER_USER@$PROD_SERVER_IP '.
      /etc/profile;
      systemctl restart nginx;'

一旦您创建了一个名为
单元的工作流程,Systemd文件将允许通过提供
启动、停止、重新启动和记录
功能来管理流程

进入
systemd
目录,我创建了新服务
sudo nano我的.service

[Unit]
Description=My application

[Service]
WorkingDirectory=/var/www/my-directory
ExecStart=/usr/bin/dotnet /var/www/my-directory/bin/Debug/netcoreapp3.1/publish/MyApplication.dll
Restart=always
RestartSec=10
SyslogIdentifier=movie
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target
在我的例子中,由于ConectionString为null,问题在于我调用
dotnet
的目录。如果您有此问题,请更改下两行

WorkingDirectory=/var/www/my-directory/bin/Debug/netcoreapp3.1/publish/
ExecStart=/usr/bin/dotnet MyApplication.dll
和内部
gitlab ci

-
    - "dotnet build"
    - cd ..
    - ssh $SERVER_USER@$PROD_SERVER_IP '
    - /home/myproject
    # stop step
    - ssh $SERVER_USER@$PROD_SERVER_IP '.
      /etc/profile;
      systemctl stop my.service;'
    - rsync -az ./server/bin/ $SERVER_USER@$PROD_SERVER_IP:/home/myproject
    # Non interactive ssh gracefully reloads server
    - ssh $SERVER_USER@$PROD_SERVER_IP '.
      /etc/profile;
      systemctl start my.service;
      systemctl restart nginx;'