Github Action Deployment to Cpanel for Nodejs Apps

mssadewa

Registered
Sep 7, 2022
3
1
3
Jakarta
cPanel Access Level
Website Owner
Hello all,

I've scenario as follow.
1. Push Local Git repo to Github.
2. Github action runs deployment to cPanel via uAPI.
3. cPanel pull repo from Github
4. cPanel run .cpanel.yml which is :
  • find PID of current running node apps.
  • kill by its PID
  • run npm start


unfortunately :
1. Task on .cpanel.yml is running before cPanel pull repo from github? I assume this because if the task failed, repo on cPanel is not updated.
2. kill command is mark as Illegal command by cPanel.

What I've try :
- remove task on .cpanel.yml (It's deploy successfully) but still repo on cPanel still didn't updated.

.cpanel.yml
Code:
deployment:
  tasks:
    - /bin/kill -9 $(ps -ef | egrep -i api.sayap.co.id | egrep -i server.js |awk {'print'}) 2> /dev/null
Any suggestion to achieve my scenario?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,352
2,246
363
cPanel Access Level
Root Administrator
Hey there! I think there may be two issues happening here. The first issue is that you likely do not have the correct entries in the cpanel.yml file. Do you have the first line of "---" in the file?

The second issue is that your "ps" command is getting the "illegal" output because it shows many processes that aren't controlled by that user. Can you run that command as the user over SSH outside of Git? I'm guessing you'll also get errors there.

I'm wondering if these tools would be better handled in a Bash script as part of a Cron job, as adding Git to this type of work just seems to add another layer of confusion.
 
  • Like
Reactions: mssadewa

mssadewa

Registered
Sep 7, 2022
3
1
3
Jakarta
cPanel Access Level
Website Owner
Hi cPRex,

Thank you.
The .cpanel.yml actually valid, sorry for not include that dash.
Code:
---
deployment:
  tasks:
  - /bin/kill -9 $(ps -ef | egrep -i api.sayap.co.id | egrep -i server.js |awk {'print'}) 2> /dev/null
for ps, I can execute it over ssh and result with no errors.

Yeah you right. Just trying with bash script.

Here is my currently .cpanel.yml
Code:
---
deployment:
  tasks:
    - cd /home/user/my-repo-path/
    - git fetch && git pull
    - /bin/bash ../mssadewa.sh > /dev/null
Here is the mssadewa.sh
Code:
#!/bin/bash
/bin/kill -9 $(ps -ef | egrep -i api.sayap.co.id | egrep -i server.js |awk {'print'}) 2> /dev/null
source /home/user/nodevenv/api.sayap.co.id/16/bin/activate && cd /home/user/api.sayap.co.id
npm i && npm start &
with above setup, I got an polling iteration in github action.
Any idea?
 

mssadewa

Registered
Sep 7, 2022
3
1
3
Jakarta
cPanel Access Level
Website Owner
I honestly don't have any other ideas about the Git side of things. If you'd like to make a ticket with our team (assuming you have root access to the server) we'd be happy to do some testing with that.
Since I'm not the owner, I don't have root access.
It's okay, I'll trying to get it work with another way.
btw somehow I find you replay mentioning nodejs autostart and register it in application manager here
maybe i just need to update repo in cPanel and register it on application manager.

Thank you and have a nice day.
 
  • Like
Reactions: cPRex