diff --git a/composer.json b/composer.json index ba0c179..f02d5c1 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "zendframework/zend-expressive-skeleton", - "description": "Zend expressive skeleton. Begin developing PSR-15 middleware applications in seconds!", + "name": "mtas/mtas-tv-backend", + "description": "MTAS-TV backend api", "type": "project", - "homepage": "https://github.com/zendframework/zend-expressive-skeleton", + "homepage": "https://gogs.ragnarok.yvan.hu/MTAS/mtas-tv-backend", "license": "BSD-3-Clause", "keywords": [ "skeleton", @@ -63,7 +63,8 @@ "zendframework/zend-json": "^3.1", "zendframework/zend-log": "^2.10", "zendframework/zend-servicemanager": "^3.3", - "zendframework/zend-stdlib": "^3.1" + "zendframework/zend-stdlib": "^3.1", + "ext-posix": "*" }, "require-dev": { "phpunit/phpunit": "^7.0.1", diff --git a/deploy-local-build.php b/deploy-local-build.php new file mode 100644 index 0000000..cc0c7fb --- /dev/null +++ b/deploy-local-build.php @@ -0,0 +1,79 @@ +stage('production') + ->user('edvidan') + ->forwardAgent() + ->set('deploy_path', '/proj/webdocs/mtoolbox/root/mtastv-inst/backend'); + + +task('build', function() { + run('composer install --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader'); + run('composer archive --file=release-pkg'); + run('tar -czf vendor-pkg.tar.gz vendor'); +})->local(); + +task('upload', function() { + upload('release-pkg.tar', '{{release_path}}'); + upload('vendor-pkg.tar.gz', '{{release_path}}'); + cd('{{release_path}}'); + run('tar -xf release-pkg.tar'); + run('tar -xzf vendor-pkg.tar.gz'); +}); + +task('clean-uploaded', function() { + cd('{{release_path}}'); + run('rm -f release-pkg.tar vendor-pkg.tar.gz'); +}); + +task('restore-dev', function() { + run('composer install --verbose --no-progress --no-interaction'); +})->local(); + +task('release', [ + 'deploy:lock', + 'deploy:prepare', + 'deploy:release', + 'upload', + 'clean-uploaded', + 'deploy:shared', + 'deploy:writable', + 'deploy:symlink', + 'deploy:unlock', +]); + +desc('Deploy your project'); +task('deploy', [ + 'build', + 'release', + 'cleanup', + 'restore-dev', + 'success', +]); diff --git a/deploy.php b/deploy.php index b0179f9..d6280b4 100644 --- a/deploy.php +++ b/deploy.php @@ -23,14 +23,6 @@ set('keep_releases', 3); set('default_stage', 'production'); -// Servers - mtas : esekivws5222a.rnd.ki.sw.ericsson.se -host('mtas') - ->stage('production') - ->user('edvidan') - ->forwardAgent() - ->set('php_service_name', 'php7.1-fpm') - ->set('deploy_path', '/proj/webdocs/mtoolbox/root/mtastv-api'); - host('vasgyuro.tsp') ->stage('staging') ->user('edvidan') @@ -45,7 +37,7 @@ task('php-fpm:reload', function () { // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service run('sudo service {{php_service_name}} reload'); }); -after('deploy:symlink', 'php-fpm:reload')->onlyOn('vasgyuro.tsp'); +after('deploy:symlink', 'php-fpm:reload'); desc('Deploy your project'); diff --git a/src/App/Command/UpdatePageCachesCommand.php b/src/App/Command/UpdatePageCachesCommand.php index 698e3ca..4a8dc80 100755 --- a/src/App/Command/UpdatePageCachesCommand.php +++ b/src/App/Command/UpdatePageCachesCommand.php @@ -6,6 +6,7 @@ namespace App\Command; use App\Service\JiraCollectorService; use App\Service\TeamService; +use LosMiddleware\LosLog\StaticLogger; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -66,11 +67,10 @@ class UpdatePageCachesCommand extends Command /** * Create the lock file - * @return bool */ - private function createLock(): bool + private function createLock(): void { - return touch(self::LOCK_FILE); + file_put_contents(self::LOCK_FILE, posix_getpid()); } /** @@ -83,11 +83,26 @@ class UpdatePageCachesCommand extends Command } /** - * Check if lock file exists + * Check if lock file exists, also removes stale lock * @return bool + * @throws \LosMiddleware\LosLog\Exception\InvalidArgumentException */ private function isLocked(): bool { - return file_exists(self::LOCK_FILE); + if (!file_exists(self::LOCK_FILE)) { + return false; + } + StaticLogger::save("[1] LOCK file exists."); + + $pid = (int)file_get_contents(self::LOCK_FILE); + if (posix_getpgid($pid)) { + StaticLogger::save("[2] PID is running"); + $binPath = readlink("/proc/${pid}/exe"); + $binName = basename($binPath); + return substr($binName, 0, 3) === 'php'; + } + + StaticLogger::save("[2] No process found."); + return false; } }