Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 25169  / 2 Years ago, wed, march 2, 2022, 3:47:10

I'm new to systemd and would like to know what is the best strategy for restarting my web application whenever I deploy new version.



Currently I start my service on boot and it just sits there, however I would like it to restart automatically whenever I change the files since whenever I push to master on gitlab the runner gets the files, compiles and copies it to correct directory. Then I want to restart it or close it however I don't know how since to restart it requires sudo.



Here is my service file



[Unit]
After=mongod.service

[Service]
WorkingDirectory=/var/app/mywebsite/Web
Environment="HOME=/home/stan"
Environment="DOTNET_CLI_TELEMETRY_OPTOUT=1"
Environment="DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1"
ExecStart=/usr/bin/dotnet run -c Release -p /var/app/mywebsite/Web/project.json

[Install]
WantedBy=multi-user.target


Here is my ci file to be more specific



before_script:
- set DOTNET_CLI_TELEMETRY_OPTOUT=1
- set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
- set HOME=/home/stan
- cd Web
- dotnet restore
- dotnet build -c Release
- cd ..
copy:
script:
- cp -R ./* /var/app/mywebsite/ # After this I would like to restart the website service

More From » systemd

 Answers
2

  1. open sudo visudo

  2. add gitlab-runner ALL=(ALL) NOPASSWD: /bin/systemctl restart myapp

  3. now you can do sudo /bin/systemctl restart myapp and it will not prompt for password


[#13528] Thursday, March 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iething

Total Points: 49
Total Questions: 127
Total Answers: 112

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;