Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I`m using gitlab-ci for deploying .net application on Digitalocean. With gitlab runner I build project on Gitlab, with "dotnet build", with the next step I need to stop somehow the server on Digitalocean to run rsync for the new version.

How can I stop .net if it not inside docker container.

My step looks like:

-
    - "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;'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
321 views
Welcome To Ask or Share your Answers For Others

1 Answer

Systemd files will allow to manage a process by providing start, stop, restart, and log functionalities once you create a process of work called a unit.

Into systemd directory I've created new service sudo nano my.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

In my case, as ConectionString was null, the problem was with directory from where I call dotnet. If you have this problem change the next two lines

WorkingDirectory=/var/www/my-directory/bin/Debug/netcoreapp3.1/publish/
ExecStart=/usr/bin/dotnet MyApplication.dll

And inside 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;'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...