我有以下的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