Skip to content

Commit

Permalink
fix openvpn.pid cannot read (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
kota65535 authored Jul 27, 2021
1 parent ac26cea commit 632d8f5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
client_key: ${{ secrets.OVPN_CLIENT_KEY }}
tls_auth_key: ${{ secrets.OVPN_TLS_AUTH_KEY }}
- name: Check if connected
run: curl -v http://172.28.4.187:8080
run: curl -v http://172.28.4.176:8080
Binary file added dist/fsevents.node
Binary file not shown.
13 changes: 5 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,7 @@ if (isPost) {
} else {
// main
try {
const pid = main()
coreCommand.issueCommand('save-state', { name: 'pid' }, pid)
main(pid => coreCommand.issueCommand('save-state', { name: 'pid' }, pid))
} catch (error) {
core.setFailed(error.message)
} finally {
Expand All @@ -794,7 +793,7 @@ const core = __webpack_require__(186)
const exec = __webpack_require__(264)
const Tail = __webpack_require__(824)/* .Tail */ .x

const run = () => {
const run = (callback) => {
const configFile = core.getInput('config_file').trim()
const username = core.getInput('username').trim()
const password = core.getInput('password').trim()
Expand Down Expand Up @@ -847,20 +846,18 @@ const run = () => {
tail.on('line', (data) => {
core.info(data)
if (data.includes('Initialization Sequence Completed')) {
core.info('VPN connected successfully.')
tail.unwatch()
clearTimeout(timer)
const pid = fs.readFileSync('openvpn.pid', 'utf8').trim()
core.info(`VPN connected successfully. Daemon PID: ${pid}`)
callback(pid)
}
})

const timer = setTimeout(() => {
core.setFailed('VPN connection failed.')
tail.unwatch()
}, 15000)

const pid = fs.readFileSync('openvpn.pid', 'utf8').trim()
core.info(`Daemon PID: ${pid}`)
return pid
}

module.exports = run
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ if (isPost) {
} else {
// main
try {
const pid = main()
coreCommand.issueCommand('save-state', { name: 'pid' }, pid)
main(pid => coreCommand.issueCommand('save-state', { name: 'pid' }, pid))
} catch (error) {
core.setFailed(error.message)
} finally {
Expand Down
10 changes: 4 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const core = require('@actions/core')
const exec = require('./exec')
const Tail = require('tail').Tail

const run = () => {
const run = (callback) => {
const configFile = core.getInput('config_file').trim()
const username = core.getInput('username').trim()
const password = core.getInput('password').trim()
Expand Down Expand Up @@ -56,20 +56,18 @@ const run = () => {
tail.on('line', (data) => {
core.info(data)
if (data.includes('Initialization Sequence Completed')) {
core.info('VPN connected successfully.')
tail.unwatch()
clearTimeout(timer)
const pid = fs.readFileSync('openvpn.pid', 'utf8').trim()
core.info(`VPN connected successfully. Daemon PID: ${pid}`)
callback(pid)
}
})

const timer = setTimeout(() => {
core.setFailed('VPN connection failed.')
tail.unwatch()
}, 15000)

const pid = fs.readFileSync('openvpn.pid', 'utf8').trim()
core.info(`Daemon PID: ${pid}`)
return pid
}

module.exports = run

0 comments on commit 632d8f5

Please sign in to comment.