您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“PHP源碼編譯安裝管理常用的腳本”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
#!/bin/sh # 編譯安裝管理PHP App=php AppName=PHP AppBase=/App AppDir=$AppBase/$App AppProg=$AppDir/sbin/php-fpm AppIni=$AppDir/etc/php.ini AppConf=$AppDir/etc/php-fpm.conf ExtensionDir=$($AppDir/bin/php-config --extension-dir) AppSrcBase=/App/src AppSrcFile=$App-*.tar.* AppSrcDir=$(find $AppSrcBase -maxdepth 1 -name "$AppSrcFile" -type f 2> /dev/null | sed -e 's/.tar.*$//' -e 's/^.\///') AppUser=$(grep "^[[:space:]]*user" $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) AppErrorLogDir=$(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) AppSlowLogDir=$(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} AppSlowLogDir=${AppSlowLogDir:-$AppDir/var/log} RemoveFlag=0 InstallFlag=0 # 獲取PID fpid() { 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) } # 查詢狀態(tài) fstatus() { fpid if [ ! -f "$AppProg" ]; then echo "$AppName 未安裝" else echo "$AppName 已安裝" if [ -z "$AppMasterPid" ]; then echo "$AppName 未啟動(dòng)" else echo "$AppName 正在運(yùn)行" fi fi } # 刪除 fremove() { fpid RemoveFlag=1 if [ -z "$AppMasterPid" ]; then if [ -d "$AppDir" ]; then rm -rf $AppDir && echo "刪除 $AppName" else echo "$AppName 未安裝" fi else echo "$AppName 正在運(yùn)行" && exit fi } # 備份 fbackup() { Day=$(date +%Y-%m-%d) BackupFile=$App.$Day.tgz if [ -f "$AppProg" ]; then cd $AppBase tar zcvf $BackupFile --exclude=var/log/* --exclude=var/run/* $App --backup=numbered [ $? -eq 0 ] && echo "$AppName 備份成功" || echo "$AppName 備份失敗" else echo "$AppName 未安裝" fi } # 安裝 finstall() { fpid InstallFlag=1 if [ -z "$AppMasterPid" ]; then test -f "$AppProg" && echo "$AppName 已安裝" [ $? -ne 0 ] && fupdate && fcpconf else echo "$AppName 正在運(yùn)行" fi } # 拷貝配置 fcpconf() { cp -vf --backup=numbered $ScriptDir/php.ini $AppIni cp -vf --backup=numbered $ScriptDir/php-fpm.conf $AppConf } # 更新 fupdate() { Operate="更新" [ $InstallFlag -eq 1 ] && Operate="安裝" [ $RemoveFlag -ne 1 ] && fbackup cd $AppSrcBase test -d "$AppSrcDir" && rm -rf $AppSrcDir tar Jxf $AppSrcFile || tar jxf $AppSrcFile || tar zxf $AppSrcFile cd $AppSrcDir ./configure \ "--prefix=$AppDir" \ "--disable-all" \ "--enable-fpm" \ "--enable-opcache" \ "--enable-pdo" \ "--enable-session" \ "--with-pcre-dir" \ "--with-pdo-mysql=mysqlnd" [ $? -eq 0 ] && make && make install if [ $? -eq 0 ];then echo "$AppName $Operate成功" else echo "$AppName $Operate失敗" exit 1 fi } # 初始化 finit() { echo "初始化 $AppName" id -gn $AppGroup &> /dev/null if [ $? -ne 0 ]; then groupadd $AppGroup && echo "新建 $AppName 運(yùn)行組:$AppGroup" else echo "$AppName 運(yùn)行組:$AppGroup 已存在" fi id -un $AppUser &> /dev/null if [ $? -ne 0 ]; then useradd -s /bin/false -g $AppGroup -M $AppUser if [ $? -eq 0 ]; then echo "新建 $AppName 運(yùn)行用戶:$AppUser" echo "S0nGPhb693$" | passwd --stdin $AppUser &> /dev/null fi else echo "$AppName 運(yùn)行用戶:$AppUser 已存在" fi echo $AppPidDir | grep -q "^/" if [ $? -eq 1 ]; then AppPidDir=$AppDir/var/$AppPidDir fi if [ ! -e "$AppPidDir" ]; then mkdir -p $AppPidDir && echo "新建 $AppName PID文件存放目錄:$AppPidDir" else echo "$AppName PID文件存放目錄:$AppPidDir 已存在" fi echo $AppErrorLogDir | grep -q "^/" if [ $? -eq 1 ]; then AppErrorLogDir=$AppDir/var/$AppErrorLogDir fi if [ ! -e "$AppErrorLogDir" ]; then mkdir -p $AppErrorLogDir && echo "新建 $AppName 錯(cuò)誤日志目錄:$AppErrorLogDir" else echo "$AppErrorLogDir 錯(cuò)誤日志目錄:$AppErrorLogDir 已存在" fi echo $AppSlowLogDir | grep -q "^/" if [ $? -eq 1 ]; then AppSlowLogDir=$AppDir/$AppSlowLogDir fi if [ ! -e "$AppSlowLogDir" ]; then mkdir -p $AppSlowLogDir && echo "新建 $AppName 慢日志目錄:$AppSlowLogDir" else echo "$AppSlowLogDir 慢日志目錄:$AppSlowLogDir 已存在" fi printf "\n" if [ -n "$UploadTmpDir" ]; then echo $UploadTmpDir | grep -q "^/" if [ $? -eq 0 ]; then if [ ! -e "$UploadTmpDir" ]; then mkdir -p $UploadTmpDir && echo "新建 $AppName 文件上傳臨時(shí)存儲(chǔ)目錄:$UploadTmpDir" else echo "$AppName 文件上傳臨時(shí)存儲(chǔ)目錄:$UploadTmpDir 已存在" fi chown -R $AppUser:$AppGroup $UploadTmpDir && echo "修改 $AppName 文件上傳臨時(shí)存儲(chǔ)目錄擁有者為 $AppUser,屬組為 $AppGroup" printf "\n" fi fi if [ -n "$SessionDir" ]; then echo $SessionDir | grep -q "^/" if [ $? -eq 0 ]; then if [ ! -e "$SessionDir" ]; then mkdir -p $SessionDir && echo "新建 $AppName 會(huì)話存儲(chǔ)目錄:$SessionDir" else echo "$AppName 會(huì)話存儲(chǔ)目錄:$SessionDir 已存在" fi chown -R $AppUser:$AppGroup $SessionDir && echo "修改 $AppName 會(huì)話存儲(chǔ)目錄擁有者為 $AppUser,屬組為 $AppGroup" printf "\n" fi fi if [ -n "$CacheDir" ]; then echo $CacheDir | grep -q "^/" if [ $? -eq 0 ]; then if [ ! -e "$CacheDir" ]; then mkdir -p $CacheDir && echo "新建 eAccelerator 緩存目錄:$CacheDir" else echo "eAccelerator 緩存目錄:$CacheDir 已存在" fi chown -R $AppUser:$AppGroup $CacheDir && echo "修改 eAccelerator 緩存目錄擁有者為 $AppUser,屬組為 $AppGroup" fi fi sed -i "s|extension_dir.*$|extension_dir = \"$ExtensionDir\"|" $AppIni } # 檢查配置 ftest() { $AppProg -t && echo "$AppName 配置正確" || echo "$AppName 配置錯(cuò)誤" } # 啟動(dòng) fstart() { fpid if [ -n "$AppMasterPid" ]; then echo "$AppName 正在運(yùn)行" else $AppProg -c $AppIni && echo "啟動(dòng) $AppName" || echo "$AppName 啟動(dòng)失敗" fi } # 停止 fstop() { fpid if [ -n "$AppMasterPid" ]; then kill -INT $AppMasterPid && echo "停止 $AppName" || echo "$AppName 停止失敗" else echo "$AppName 未啟動(dòng)" fi } # 重載配置 freload() { fpid if [ -n "$AppMasterPid" ]; then kill -USR2 $AppMasterPid && echo "重載 $AppName 配置" || echo "$AppName 重載配置失敗" else echo "$AppName 未啟動(dòng)" fi } # 重啟 frestart() { fpid [ -n "$AppMasterPid" ] && fstop && sleep 1 fstart } # 終止進(jìn)程 fkill() { fpid if [ -n "$AppMasterPid" ]; then echo "$AppMasterPid" | xargs kill -9 if [ $? -eq 0 ]; then echo "終止 $AppName 主進(jìn)程" else echo "終止 $AppName 主進(jìn)程失敗" fi else echo "$AppName 主進(jìn)程未運(yùn)行" fi if [ -n "$AppWorkerPid" ]; then echo "$AppWorkerPid" | xargs kill -9 if [ $? -eq 0 ]; then echo "終止 $AppName 工作進(jìn)程" else echo "終止 $AppName 工作進(jìn)程失敗" fi else echo "$AppName 工作進(jìn)程未運(yùn)行" 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 刪除 $AppName" echo "$ScriptFile backup 備份 $AppName" echo "$ScriptFile init 初始化 $AppName" echo "$ScriptFile start 啟動(dòng) $AppName" echo "$ScriptFile stop 停止 $AppName" echo "$ScriptFile restart 重啟 $AppName" echo "$ScriptFile status 查詢 $AppName 狀態(tài)" echo "$ScriptFile cpconf 拷貝 $AppName 配置" echo "$ScriptFile test 檢查 $AppName 配置" echo "$ScriptFile reload 重載 $AppName 配置" echo "$ScriptFile kill 終止 $AppName 進(jìn)程" ;; esac
“PHP源碼編譯安裝管理常用的腳本”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。