简体   繁体   中英

Write process id to file in Gitlab CI/CD script

After building front- and backend with Gitlab CI/CD jobs I try to copy executables on server and rerun backend server.

Expected behaviour: kill process with pid from file /var/run/backend.pid, then run new one process in background and write new pid to same file.

Actual behaviour: everything is well, but file /var/run/backend.pid is empty (actually only new line character)

script:  
  - ssh root@draft.<...project name...>.tech "pkill -F /var/run/<...project name...>-backend.pid;rm /var/run/<...project name...>-backend.pid;/var/www/<...project name...>/backend/bin/backend > /var/log/<...project name...>-backend.log 2>&1 & disown;echo $! > /var/run/<...project name...>-backend.pid"

Please help me with my deploy. I do not know what cann be wrong, because locally same command works well.

Try and check if the file is created in the first place, by running only the first part of your command:

ssh root@draft.<...project name...>.tech  "pkill -F /var/run/<...project name...>-backend.pid"

That will validate that:

  • gitlab-ci runs with an account which is able to do the ssh root@draft.<...project name...>.tech
  • and the pkill command does actually generate a non-empty backend.pid file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM