@@ -1629,62 +1629,6 @@ sub get_php_fcgi_server_command
1629
1629
return ($cmd , \%envs_to_set , $log , $pidfile , $basecmd );
1630
1630
}
1631
1631
1632
- # start_php_fcgi_server_command(&domain, cmd, &envs, logfile, pidfile)
1633
- # Actually start the PHP fcgid server for a domain
1634
- sub start_php_fcgi_server_command
1635
- {
1636
- my ($d , $cmd , $envs_to_set , $log , $pidfile ) = @_ ;
1637
- my $pid = fork ();
1638
- if (!$pid ) {
1639
- untie (*STDIN ); untie (*STDOUT ); untie (*STDERR );
1640
- close (STDIN ); close (STDOUT ); close (STDERR );
1641
- my @u = getpwnam ($d -> {' user' });
1642
- &switch_to_unix_user(\@u );
1643
- open (STDOUT , " >>" , " $log " );
1644
- open (STDERR , " >" , " &STDOUT" );
1645
- &clean_environment();
1646
- foreach my $e (keys %$envs_to_set ) {
1647
- $ENV {$e } = $envs_to_set -> {$e };
1648
- }
1649
- exec ($cmd );
1650
- exit (1);
1651
- }
1652
- my $fh = " PIDFILE" ;
1653
- &virtual_server::open_tempfile_as_domain_user($d , $fh , " >$pidfile " );
1654
- &print_tempfile($fh , $pid ." \n " );
1655
- &virtual_server::close_tempfile_as_domain_user($d , $fh );
1656
- }
1657
-
1658
- # stop_php_fcgi_server_command(&domain, [delete-dir])
1659
- # Kills the running PHP server process for a domain
1660
- sub stop_php_fcgi_server_command
1661
- {
1662
- my ($d , $deletedir ) = @_ ;
1663
- my (undef , undef , undef , $pidfile ) =
1664
- &get_php_fcgi_server_command($d , $d -> {' nginx_php_port' });
1665
- my $pid = &check_pid_file($pidfile );
1666
- if ($pid ) {
1667
- if (&virtual_server::has_domain_user($d )) {
1668
- &virtual_server::run_as_domain_user(
1669
- $d , " kill " .quotemeta ($pid ));
1670
- }
1671
- else {
1672
- &kill_logged(' TERM' , $pid );
1673
- }
1674
- sleep (1); # Give it time to exit cleanly
1675
- }
1676
-
1677
- # Delete PID file
1678
- &virtual_server::unlink_file_as_domain_user($d , $pidfile );
1679
-
1680
- # Delete socket file, if any
1681
- if ($d -> {' nginx_php_port' } =~ / ^(\/\S +)\/ socket$ / ) {
1682
- my $domdir = $1 ;
1683
- &unlink_file($d -> {' nginx_php_port' });
1684
- &unlink_file($domdir ) if ($deletedir );
1685
- }
1686
- }
1687
-
1688
1632
# setup_php_fcgi_server(&domain)
1689
1633
# Starts up a PHP process running as the domain user, and enables it at boot.
1690
1634
# Returns an OK flag and the port number selected to listen on.
@@ -1748,30 +1692,29 @@ sub setup_php_fcgi_server
1748
1692
return (0, &text(' fcgid_ecmdb' , " <tt>$basecmd </tt>" ));
1749
1693
}
1750
1694
1751
- # Launch it, and save the PID
1752
- &start_php_fcgi_server_command($d , $cmd , $envs_to_set , $log , $pidfile );
1753
-
1754
1695
# Create init script
1755
1696
&foreign_require(" init" );
1756
1697
my $old_init_mode = $init::init_mode ;
1757
- if ($init::init_mode eq " upstart" ||
1758
- $init::init_mode eq " systemd" ) {
1698
+ if ($init::init_mode eq " upstart" ) {
1759
1699
$init::init_mode = " init" ;
1760
1700
}
1761
- my $name = " php-fcgi-$d ->{'dom'}" ;
1762
- my $oldname = $name ;
1763
- $name =~ s /\. / -/ g ;
1701
+ my $name = &init_script_name($d );
1764
1702
my $envs = join (" " , map { $_ ." =" .$envs_to_set -> {$_ } } keys %$envs_to_set );
1765
1703
&init::enable_at_boot($name ,
1766
1704
" Start Nginx PHP fcgi server for $d ->{'dom'}" ,
1767
1705
&command_as_user($d -> {' user' }, 0,
1768
1706
" $envs $cmd >>$log 2>&1 </dev/null & echo \$ ! >$pidfile " ),
1769
1707
&command_as_user($d -> {' user' }, 0,
1770
1708
" kill `cat $pidfile `" )." ; sleep 1" ,
1709
+ undef ,
1710
+ { ' fork' => 1,
1711
+ ' pidfile' => $pidfile },
1771
1712
);
1772
- &init::disable_at_boot($oldname );
1773
1713
$init::init_mode = $old_init_mode ;
1774
1714
1715
+ # Launch it, and save the PID
1716
+ &init::start_action($name );
1717
+
1775
1718
return (1, $port );
1776
1719
}
1777
1720
@@ -1782,39 +1725,44 @@ sub delete_php_fcgi_server
1782
1725
my ($d ) = @_ ;
1783
1726
1784
1727
# Stop the server
1785
- &stop_php_fcgi_server_command($d , 1);
1728
+ &foreign_require(" init" );
1729
+ my $name = &init_script_name($d );
1730
+ &init::stop_action($name );
1786
1731
1787
1732
# Delete init script
1788
- &foreign_require(" init" );
1789
1733
my $old_init_mode = $init::init_mode ;
1790
- if ($init::init_mode eq " upstart" ||
1791
- $init::init_mode eq " systemd" ) {
1734
+ if ($init::init_mode eq " upstart" ) {
1792
1735
$init::init_mode = " init" ;
1793
1736
}
1737
+ &init::disable_at_boot($name );
1738
+ &init::delete_at_boot($name );
1739
+ $init::init_mode = $old_init_mode ;
1740
+
1741
+ # Previously we created init scripts under system
1742
+ if ($init::init_mode eq " systemd" ) {
1743
+ my $old_init_mode = $init::init_mode ;
1744
+ $init::init_mode = " init" ;
1745
+ &init::disable_at_boot($name );
1746
+ &init::delete_at_boot($name );
1747
+ $init::init_mode = $old_init_mode ;
1748
+ }
1749
+
1750
+ # Delete socket file, if any
1751
+ if ($d -> {' nginx_php_port' } =~ / ^(\/\S +)\/ socket$ / ) {
1752
+ my $domdir = $1 ;
1753
+ &unlink_file($d -> {' nginx_php_port' });
1754
+ &unlink_file($domdir );
1755
+ }
1756
+ }
1757
+
1758
+ # init_script_name(&domain)
1759
+ # Returns the name of the init script for the FCGId server
1760
+ sub init_script_name
1761
+ {
1762
+ my ($d ) = @_ ;
1794
1763
my $name = " php-fcgi-$d ->{'dom'}" ;
1795
- my $oldname = $name ;
1796
1764
$name =~ s /\. / -/ g ;
1797
- foreach my $n ($name , $oldname ) {
1798
- &init::disable_at_boot($n );
1799
- if ($init::init_mode eq " init" ) {
1800
- my $fn = &init::action_filename($n );
1801
- foreach my $l (&init::action_levels(' S' , $n )) {
1802
- if ($l =~ / ^(\S +)\s +(\S +)\s +(\S +)$ / ) {
1803
- &init::delete_rl_action($n , $1 , ' S' );
1804
- }
1805
- }
1806
- foreach my $l (&init::action_levels(' K' , $n )) {
1807
- if ($l =~ / ^(\S +)\s +(\S +)\s +(\S +)$ / ) {
1808
- &init::delete_rl_action($n , $1 , ' K' );
1809
- }
1810
- }
1811
- &unlink_logged($fn );
1812
- }
1813
- elsif ($init::init_mode eq " rc" ) {
1814
- &init::delete_rc_script($n );
1815
- }
1816
- }
1817
- $init::init_mode = $old_init_mode ;
1765
+ return $name ;
1818
1766
}
1819
1767
1820
1768
# find_php_fcgi_server(&domain)
0 commit comments