idk atp #131
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SFTP Deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
name: Deploy to SFTP | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
- name: SFTP Upload | |
uses: wlixcc/[email protected] | |
with: | |
username: ${{ secrets.SFTP_USERNAME }} | |
server: node2.sear.host | |
port: 2022 | |
password: ${{ secrets.SFTP_PASSWORD }} | |
local_path: './backend/*' | |
remote_path: '.' | |
sftp_only: true | |
sftpArgs: '-r' | |
- name: Create restart script | |
run: | | |
cat > restart-server.js << 'EOF' | |
const https = require('https'); | |
const API_KEY = process.env.PTERODACTYL_API_KEY; | |
const SERVER_UUID = process.env.PTERODACTYL_SERVER_UUID; | |
if (!API_KEY || !SERVER_UUID) { | |
console.error('Required environment variables are missing'); | |
process.exit(1); | |
} | |
function restartServer() { | |
return new Promise((resolve, reject) => { | |
const data = JSON.stringify({ | |
signal: "restart" | |
}); | |
const options = { | |
hostname: 'panel.sear.host', | |
path: `/api/client/servers/${SERVER_UUID}/power`, | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', | |
'Authorization': `Bearer ${API_KEY}`, | |
'Content-Length': data.length | |
} | |
}; | |
const req = https.request(options, (res) => { | |
let responseData = ''; | |
res.on('data', (chunk) => { | |
responseData += chunk; | |
}); | |
res.on('end', () => { | |
if (res.statusCode >= 200 && res.statusCode < 300) { | |
console.log('Server restart initiated successfully'); | |
resolve(); | |
} else { | |
reject(new Error(`Failed to restart server: ${res.statusCode} ${responseData}`)); | |
} | |
}); | |
}); | |
req.on('error', (error) => { | |
reject(error); | |
}); | |
req.write(data); | |
req.end(); | |
}); | |
} | |
restartServer().catch(error => { | |
console.error('Error:', error); | |
process.exit(1); | |
}); | |
EOF | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Restart Pterodactyl Server | |
run: node restart-server.js | |
env: | |
PTERODACTYL_API_KEY: ${{ secrets.PTERODACTYL_API_KEY }} | |
PTERODACTYL_SERVER_UUID: ${{ secrets.PTERODACTYL_SERVER_UUID }} |