承接 brunonatali/install 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brunonatali/install

Composer 安装命令:

composer require brunonatali/install

包简介

Provide installation capability to a repository.

README 文档

README

Provide installation capability to a repository.

Table of Contents

Before start

Before you begin, consider reviewing your code and understanding that this is a tool for automating the installation of an application made in PHP to run on the CLI or as a service in a Linux environment.

Observe that if service was instaled this component will update .service file and perform a daemon-reload, and if is active (runing) before install starts, service will be autoatically started after instalation is finished.

Note. Not supported on Windows.

Folder structure

Prepare the folder structure as shown below:

+-- installation
|   +-- install.php
|   +-- install-instructions.json
+-- pbin
|   +-- my_program_executable
+-- src
|   +-- YourClass.php
+-- post-install
|   +-- myScript.sh
+-- composer.json

Note. If you are unsure how to create your 'my_program_executable' go to Executable program.

Quickstart example

Individual

A common use is the individual installation of the application, for that, consider having the folder structure as shown in Folder structure.

  • Let's create a simple configuration file, "installation / install-instructions.json":
{
    "sys-bin-files" : [
        "my_program_executable"
    ],
    "service" : [
        {
            "name" : "My1stProgram",
            "bin" : "my_program_executable",
            "control-by-pid" : true,
            "restart-on-abort" : true
        }
    ],
    "require" : [
        "program1",
        "program2"
    ],
    "post-installation" : "/../post-install/myScript.sh"
}
  • Let's add a script for auto installation "installation / install.php":
use BrunoNatali\Install\Factory;

$myApp = new Factory( ["dir" => __DIR__] );

$myApp->install();
  • Finally perform the installation:
$ php vendor/myname/appname/installation/install.php

This will make the contents of the "pbin" folder become executable, as well as create a service on the system with the name "My1stProgram" that will execute the file "my_program_executable".
At the end will call script myScript.sh (under /post-install), to do some adjusts that you need, like call other aplication, change some file attribute or remove. Learn more
An "require" is a array that tell which apps your app depends.
Note that a symlink is created in "/usr/sbin", that way you can run the application by typing in the terminal:

$ my_program_executable

All apps

In this example, it is assumed that the folder structure shown in Folder structure and at least the configuration file "install-instructions.json" is created within all the applications you intend to install.

Within the Factory class there is a static function to make the installation of several applications very easy:

\BrunoNatali\Install\Factory::installAll()

The simplest and most direct way to perform the installation of all applications is to run the following command on the terminal:

$ sudo php -r "require 'vendor/autoload.php'; \BrunoNatali\Install\Factory::installAll();"

Is possible to skip some app installation (partially or entirely).
To do this, you need to pass an array with app name in key, as follows:

/**
 * Installation will be made in basic mode, no services or post scripts 
 *  are done in this mode
*/
\BrunoNatali\Install\Factory::installAll( null, array(
    'appToNotInstall' => true  // Don`t metter the value
) );

/**
 * Installation will be entirely skipped
*/
\BrunoNatali\Install\Factory::installAll( null, array(
    'appToNotInstall' => 'force'  // Set value to 'force'
) );

Note. The need to run as root, as it will interact with systemd and create / update processes within the system.

Executable program

An executable program considered for this tool basically contains:

#!/usr/bin/php

<?php

require __DIR__ . '/../../../autoload.php';

use VendorName\AppName\Service;

$myService = new Service();

$myService->start();

Post install script

You can create a bash script to run after installation. For now, this script could do anything.
To help localization, an environment variable 'INSTALL_DIR' has been added.

#!/bin/bash

echo "Installing from: $INSTALL_DIR";

$ Installing from: /opt/myapp/vendor/vendor-name/rep-name/installation

Use pid file

Could be configured to use a pid file to control service.
For this, place an "control-by-pid" in service config:

"service" : [
        {
            "name" : "MyApp",
            "bin" : "my_app_executable",
            "control-by-pid" : true
        }
    ]

An pid file is created in \var\run\MyApp.pid when start and removed when stops.

Select shell to use

To help service load / run using all configs, linux shell is called on execution and "sh" is used for default.
Just one config is allowed, to change this, place an "shell" in service config with "bash":

"service" : [
        {
            "name" : "MyApp",
            "bin" : "my_app_executable",
            "shell" : "bash"
        }
    ]

Restart on failure

Systemd could restart service if service fails.
For this, place an "restart-on-abort" in service config:

"service" : [
        {
            "name" : "MyApp",
            "bin" : "my_app_executable",
            "restart-on-abort" : true
        }
    ]

Kill child process

Seting "kill-child" to false will make systemd to let all child of the main process alive on stop / restart.
For this, place an "kill-child" in service config:

"service" : [
        {
            "name" : "MyApp",
            "bin" : "my_app_executable",
            "kill-child" : false
        }
    ]

Remember to manually kill all remaining process to prevent system mem overflow.

Require app

With "require" set in your config.json you could set which app your application depends.
Ex. If you have application called "myCar", you can set "require", like this:

{
    "require" : [
        "engine",
        "wheelsNtires"
    ]
}

With this, Install whill install "engine" and "wheelsNtires" before install "myCar"
Note 1. This will be handled automatically when called from \BrunoNatali\Install\Factory::installAll().

To handle manually, an 'require-installed' must be passed to install()

/**
 * engine.php
*/
use BrunoNatali\Install\Factory;
$myApp = new Factory( ["dir" => __DIR__] );
$myApp->install();
/**
 * wheelsNtires.php
*/
use BrunoNatali\Install\Factory;
$myApp = new Factory( ["dir" => __DIR__] );
$myApp->install();
/**
 * car.php
*/
use BrunoNatali\Install\Factory;
$myApp = new Factory( ["dir" => __DIR__] );
$myApp->install( array(
    'require-installed' => array(
        "engine" => '', // See note 2
        "wheelsNtires" => true,
        "stuff" => 'ok'
    )
));

Note 2. In the above example, don't matther what is the value of require-installed item (*EXCEPT FOR 'force' that is reserved internally), just need to be registered as a key.

Require service

Configures systemd.unit 'Requires' to defined service

{
    "service" : [
        {
            "require-service" : "require-this.service"
        }
    ]
}

After service

Configures systemd.unit 'After' specific service

{
    "service" : [
        {
            "exec-only-after" : "after-this.service"
        }
    ]
}

Install

The recommended way to install this library is through Composer. New to Composer?

This project follows SemVer. This will install the latest supported version:

$ composer require brunonatali/install:^1.0

This project aims to run on Linux and thus does not require any PHP extensions, but actually not tested in all environments. If you find a bug, please report.

License

MIT, see LICENSE file.

brunonatali/install 适用场景与选型建议

brunonatali/install 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 06 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 brunonatali/install 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 brunonatali/install 我们能提供哪些服务?
定制开发 / 二次开发

基于 brunonatali/install 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 46
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-03