PHP source code compilation, installation, and management common scripts

Source: Internet
Author: User
PHP source code compilation, installation, and management common scripts
#! /Bin/sh # compile and install PHPApp = phpAppName = PHPAppBase =/AppAppDir = $ AppBase/$ AppAppProg = $ AppDir/sbin/php-fpmAppIni = $ AppDir/etc/php. iniAppConf = $ AppDir/etc/php-fpm.confExtensionDir = $ ($ AppDir/bin/php-config -- extension-dir) export rcbase =/App/srcAppSrcFile = $ App -*. tar. * export rcdir = $ (find $ export rcbase-maxdepth 1-name "$ export rcfile"-type f 2>/dev/null | sed-e's /. tar. * $ // '-e's/^. \ // ') AppUser = $ (grep "^ [: space:] * use R "$ AppConf 2>/dev/null | awk-F = '{print $2}' | sed-e's/[[: space:] // g'-e's/"// g'-e" s/'// g ") AppGroup = $ (grep" ^ [[: space:] * group "$ AppConf 2>/dev/null | awk-F = '{print $2}' | sed-e's/[[: space:] // g'-e's/"// g'-e" s/'// g ") AppPidDir = $ (dirname $ (grep" ^ [[: space:] * pid "$ AppConf 2>/dev/null | awk-F = '{print $2}' | sed-e's /[[: space:] // g'-e's/"// g'-e" s/'// g ") 2>/dev/null) AppErrorL OgDir = $ (dirname $ (grep "^ [[: space:] * error_log "$ AppConf 2>/dev/null | awk-F = '{print $2}' | sed-e's/[[: space:] // g'-e's/"// g'-e" s/'// g ") 2>/dev/null) required lowlogdir = $ (dirname $ (grep "^ [[: space:] * slowlog "$ AppConf 2>/dev/null | awk-F = '{print $2}' | sed-e's/[[: space:] // g'-e's/"// g'-e" s/'// g ") 2>/dev/null) uploadTmpDir = $ (grep "^ [[: space:] * upload_tmp_dir" $ AppIni 2>/dev/null | awk -F = '{print $2}' | sed-e's/[[: space:] // g'-e's/"// g'-e" s/'// g ") grep" ^ session. save_handler "$ AppIni 2>/dev/null | grep-q" files "[$? -Eq 0] & SessionDir = $ (grep "^ [: space:] * session. save_path "$ AppIni 2>/dev/null | awk-F = '{print $2}' | sed-e's/[[: space:] // g'-e's/"// g'-e" s/'// g ") CacheDir = $ (grep" ^ [[: space:] * eaccelerator. cache_dir "$ AppIni 2>/dev/null | awk-F = '{print $2}' | sed-e's/[[: space:] // g'-e's/"// g'-e" s/'// g ") AppUser =$ {AppUser:-nobody} AppGroup =$ {AppGroup: -nobody} AppPidDir =$ {AppPidDir: = $ AppDir/var/run} AppErrorLogDir =$ {AppErrorLogDir:-$ AppDir/var/log} export lowlogdir =$ {export lowlogdir:-$ AppDir/var/log} RemoveFlag = 0 InstallFlag = 0 # obtain PIDfpid () {AppMasterPid = $ (ps ax | grep "php-fpm: master process" | grep-v "grep" | awk '{print $1}' 2>/dev/null) appWorkerPid = $ (ps ax | grep "php-fpm: pool" | grep-v "grep" | awk '{print $1}' 2>/dev/null )} # Query status fstatus () {fpid if [! -F "$ AppProg"]; then echo "$" else echo "$" if [-z "$ AppMasterPid"] is not installed in AppName. then echo "$ AppName not started" else echo "$ AppName is running" fi} # delete fremove () {fpid RemoveFlag = 1 if [-z "$ AppMasterPid"]; then if [-d "$ AppDir"]; then rm-rf $ AppDir & echo "Delete $ AppName" else echo "$" fi else echo "$ AppName running" & exit fi} # back up fbackup () {Day = $ (date + % Y-% m-% d) BackupFile = $ App. $ Da Y. tgz if [-f "$ AppProg"]; then cd $ AppBase tar zcvf $ BackupFile -- exclude = var/log/* -- exclude = var/run/* $ App -- backup = numbered [$? -Eq 0] & echo "$ AppName backup succeeded" | echo "$ AppName backup failed" else echo "$ AppName not installed" fi} # install finstall () {fpid InstallFlag = 1 if [-z "$ AppMasterPid"]; then test-f "$ AppProg" & echo "$ AppName already installed" [$? -Ne 0] & fupdate & fcpconf else echo "$ AppName is running" fi} # Copy configuration fcpconf () {cp-vf -- backup = numbered $ ScriptDir/php. ini $ AppIni cp-vf -- backup = numbered $ ScriptDir/php-fpm.conf $ AppConf} # Update fupdate () {Operate = "update" [$ InstallFlag-eq 1] & Operate = "install" [$ RemoveFlag-ne 1] & fbackup cd $ your rcbase test-d "$ your rcdir" & rm-rf $ export rcdir tar Jxf $ export rcfile | tar jxf $ export rcfile | tar zxf $ Ap PSrcFile cd $ export rcdir. /configure \ "-- prefix = $ AppDir" \ "-- disable-all" \ "-- enable-fpm" \ "-- enable-opcache" \ "-- enable-pdo "\" -- enable-session "\" -- with-pcre-dir "\" -- with-pdo-mysql = mysqlnd "[$? -Eq 0] & make install if [$? -Eq 0]; then echo "$ AppName $ Operate successful" else echo "$ AppName $ Operate failed" exit 1 fi} # Initialize finit () {echo "initialization $ AppName" id-gn $ AppGroup &>/dev/null if [$? -Ne 0]; then groupadd $ AppGroup & echo "New $ AppName running group: $ AppGroup" else echo "$ AppName running group: $ AppGroup already exists "fi id-un $ AppUser &>/dev/null if [$? -Ne 0]; then useradd-s/bin/false-g $ AppGroup-M $ AppUser if [$? -Eq 0]; then echo "New $ AppName running User: $ AppUser "echo" S0nGPhb693 $ "| passwd -- stdin $ AppUser &>/dev/null fi else echo" $ AppName running User: $ AppUser "fi echo $ AppPidDir | grep-q" ^/"if [$? -Eq 1]; then AppPidDir = $ AppDir/var/$ AppPidDir fi if [! -E "$ AppPidDir"]; then mkdir-p $ AppPidDir & echo "New $ AppName PID file storage directory: $ AppPidDir" else echo "$ AppName PID file storage directory: $ AppPidDir "fi echo $ AppErrorLogDir | grep-q" ^/"if [$? -Eq 1]; then AppErrorLogDir = $ AppDir/var/$ AppErrorLogDir fi if [! -E "$ AppErrorLogDir"]; then mkdir-p $ AppErrorLogDir & echo "New $ AppName error log Directory: $ AppErrorLogDir" else echo "$ AppErrorLogDir error log Directory: $ AppErrorLogDir "fi echo $ export lowlogdir | grep-q" ^/"if [$? -Eq 1]; then lowlogdir = $ AppDir/$ then lowlogdir fi if [! -E "$ export lowlogdir"]; then mkdir-p $ export lowlogdir & echo "New $ AppName slow log Directory: $ export lowlogdir" else echo "$ export lowlogdir slow log Directory: $ define lowlogdir "fi printf" \ n "if [-n" $ UploadTmpDir "]; then echo $ UploadTmpDir | grep-q" ^/"if [$? -Eq 0]; then if [! -E "$ UploadTmpDir"]; then mkdir-p $ UploadTmpDir & echo "New $ AppName file Upload temporary storage directory: $ UploadTmpDir "else echo" $ AppName temporary storage directory for file upload: $ UploadTmpDir already exists "fi chown-R $ AppUser: $ AppGroup $ UploadTmpDir & echo "modify $ AppName file Upload temporary storage directory owner to $ AppUser, the group is $ AppGroup "printf" \ n "fi if [-n" $ SessionDir "]; then echo $ SessionDir | grep-q" ^/"if [$? -Eq 0]; then if [! -E "$ SessionDir"]; then mkdir-p $ SessionDir & echo "New $ AppName session storage directory: $ SessionDir" else echo "$ AppName session storage directory: $ SessionDir "fi chown-R $ AppUser: $ AppGroup $ SessionDir & echo" already exists. modify $ AppName as the owner of the session storage directory to $ AppUser, the group is $ AppGroup "printf" \ n "fi if [-n" $ CacheDir "]; then echo $ CacheDir | grep-q" ^/"if [$? -Eq 0]; then if [! -E "$ CacheDir"]; then mkdir-p $ CacheDir & echo "create an eAccelerator cache Directory: $ CacheDir" else echo "eAccelerator cache Directory: $ CacheDir "fi chown-R $ AppUser: $ AppGroup $ CacheDir & echo" already exists. modify the eAccelerator cache Directory owner to $ AppUser, the group is $ AppGroup "fi sed-I" s | extension_dir. * $ | extension_dir = \ "$ ExtensionDir \" | "$ AppIni} # Check the configuration ftest () {$ AppProg-t & echo "$ correct AppName configuration" | echo "$ AppName configuration error"} # start fstart () {fpid if [-N "$ AppMasterPid"]; then echo "$ AppName is running" else $ AppProg-c $ AppIni & echo "start $ AppName" | echo "$ AppName start failed" fi} # Stop fstop () {fpid if [-n "$ AppMasterPid"]; then kill-INT $ AppMasterPid & echo "stop $ AppName" | echo "$ AppName stop failed" else echo "$ AppName not started" fi} # reload configuration freload () {fpid if [-n "$ AppMasterPid"]; then kill-USR2 $ AppMasterPid & echo "reload $ AppName configuration" | echo "$ AppName reload configuration failed "Else echo" $ AppName not started "fi} # restart frestart () {fpid [-n "$ AppMasterPid"] & fstop & sleep 1 fstart} # terminate the process fkill () {fpid if [-n "$ AppMasterPid"]; then echo "$ AppMasterPid" | xargs kill-9 if [$? -Eq 0]; then echo "terminate $ AppName main process" else echo "terminate $ AppName main process failed" fi else echo "$ AppName main process not running" fi if [-n "$ AppWorkerPid"]; then echo "$ AppWorkerPid" | xargs kill-9 if [$? -Eq 0]; then echo "terminate $ AppName workflow" else echo "terminate $ AppName workflow failed" fi else echo "$ AppName workflow not running" fi} ScriptDir = $ (cd $ (dirname $0 ); pwd) ScriptFile = $ (basename $0) case "$1" in "install") finstall; "update") fupdate; "reinstall") fremove & finstall ;; "remove") fremove; "backup") fbackup; "init") finit; "start") fstart; "stop") fstop; "restart ") frestart; "status") fstatus; "cpconf") fcpconf; "test") ftest; "reload") freload; "kill") fkill ;;*) echo "$ ScriptFile install $ AppName" echo "$ ScriptFile update $ AppName" echo "$ ScriptFile reinstall $ AppName" echo "$ ScriptFile remove delete $ AppName" echo "$ ScriptFile backup $ AppName "echo" $ ScriptFile init initialization $ AppName "echo" $ ScriptFile start $ AppName "echo" $ ScriptFile stop $ AppName "echo" $ ScriptFile restart $ AppName "echo" $ ScriptFile status query $ AppName status "echo" $ ScriptFile cpconf copy $ AppName configuration "echo" $ ScriptFile test Check $ AppName configuration "echo" $ ScriptFile reload $ AppName configuration "echo" $ ScriptFile kill terminate $ AppName process ";; esac

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.