Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

PID 13,28 is not alive. #2

Open
JamesKid opened this issue May 18, 2022 · 1 comment
Open

PID 13,28 is not alive. #2

JamesKid opened this issue May 18, 2022 · 1 comment

Comments

@JamesKid
Copy link

JamesKid commented May 18, 2022

when I type in "node wather.js " it return :
PID 13,28 is not alive.

php: 8.1.3
node: 12.22

@glowfisch8lan
Copy link

watcher.js

let fs = require('fs')
let chokidar = require('chokidar')
let colors = require('colors/safe')
let isRunning = require('is-running')

// Define our watching parameters
let basePath = process.cwd()
let pidPath = basePath + '/storage/logs/swoole_http.pid'
let pid = fs.readFileSync(pidPath, 'utf8').split(',')
let ready = false

let logger = (color, message, level = 'log', skipSignal = false) => {
    console[level](colors[color](message))

    if (ready && !skipSignal) {
        sendSignal()
    }
}

let sendSignal = () => {
    pid.forEach((pid) => {
        if (!isRunning(pid)) {
            ready = false
            logger('red', `PID ${pid} is not alive. Close watcher process.`, 'error')
            process.exit()
        }

        process.kill(pid, 'SIGUSR1')
        logger('green', `Reloading process PID ${pid}...`, 'log', true)
    })
}

pid.forEach((pid) => {
    if (!isRunning(pid)) {
        logger('red', `PID ${pid} is not alive.`, 'error')
        return
    } else {
        logger('green', `PID ${pid} is alive, start watching process...`)
    }
})

// Initialize watcher.
// Define your paths here.
let watcher = chokidar.watch([
    basePath + '/app',
    basePath + '/resources',
    basePath + '/routes'
], {
    ignored: /(^|[\/\\])\../,
    persistent: true
})

// Add event listeners.
watcher
    .on('add', path => logger('yellow', `File ${path} has been added.`))
    .on('change', path => logger('yellow', `File ${path} has been changed.`))
    .on('unlink', path => logger('yellow', `File ${path} has been removed.`))
    .on('addDir', path => logger('yellow', `Directory ${path} has been added.`))
    .on('unlinkDir', path => logger('yellow', `Directory ${path} has been removed.`))
    .on('error', error => logger('red', `Watcher error: ${error}`))
    .on('ready', () => {
        logger('green', 'Initial scan is finished. Ready for watching changes...')
        ready = true
    })

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants