【问题标题】:PHP program create installable packagePHP程序创建可安装包
【发布时间】:2017-03-15 08:00:40
【问题描述】:

我有以下 PHP 脚本,我想创建一个人们可以轻松安装的包,类似于:

sudo dpkg -i packagename.deb

关于如何做到这一点的任何想法?

/home/script.sh

#!/bin/bash
echo "Starting NAME service"
sudo -u root php -f /home/script.php &

/home/script.php

<?php

// The worker will execute every X seconds:
$seconds = 2;

// We work out the micro seconds ready to be used by the 'usleep' function.
$micro = $seconds * 1000000;

while(true){
 // This is the code you want to loop during the service...
 $myFile = "/home/filephp.txt";
 $fh = fopen($myFile, 'a') or die("Can't open file");
 $stringData = "File updated at: " . time(). "\n";
 fwrite($fh, $stringData);
 fclose($fh);

 // Now before we 'cycle' again, we'll sleep for a bit...
 usleep($micro);
}

/etc/systemd/system/name.service

[Unit]
Description=Crawler cache Service
After=network.target

[Service]
User=root
Restart=always
Type=forking
ExecStart=/home/script.sh

[Install]
WantedBy=multi-user.target

【问题讨论】:

    标签: php linux ubuntu


    【解决方案1】:

    解决了创建以下文件夹树:

    > package_name/
    >> DEBIAN/
    >>> control
    >> usr/
    >>> share/
    >>>> package_name/
    >>>>> script.sh
    >>>>> script.php
    >> etc/
    >>> systemd/
    >>>> system/
    >>>>> name.service
    

    在“控制”文件中,您必须设置一些参数,例如版本号或依赖项。

    Package: package_name
    Version: 0.0.1
    Section: base
    Priority: optional
    Architecture: all
    Depends: php, php-curl
    Maintainer: Marcos Aguayo <marcos@aguayo.es>
    Description: Package description
    

    之后,您只需键入以下命令:

    sudo dpkg-deb --build package_name/
    

    当你有 .deb 包后,如果你想安装它,你可以使用这个命令:

    sudo dpkg -i package_name.deb # --> Install .deb
    systemctl start package_name  # --> Start the service
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多