Browse Source

Update init.d postgresql

lj2007331@gmail.com 6 years ago
parent
commit
7e7cfa8819
8 changed files with 55 additions and 19 deletions
  1. 1 0
      addons.sh
  2. 2 1
      include/check_os.sh
  3. 3 3
      include/openssl.sh
  4. 13 6
      include/postgresql.sh
  5. 31 6
      init.d/postgresql.service
  6. 1 1
      install.sh
  7. 2 2
      versions.txt
  8. 2 0
      vhost.sh

+ 1 - 0
addons.sh

@@ -89,6 +89,7 @@ Install_fail2ban() {
   src_url=http://mirrors.linuxeye.com/oneinstack/src/fail2ban-${fail2ban_ver}.tar.gz && Download_src
   tar xzf fail2ban-${fail2ban_ver}.tar.gz
   pushd fail2ban-${fail2ban_ver}
+  sed -i 's@for i in xrange(50)@for i in range(50)@' fail2ban/__init__.py
   ${python_install_dir}/bin/python setup.py install
   if [ "${PM}" == 'yum' ]; then
     LOGPATH=/var/log/secure

+ 2 - 1
include/check_os.sh

@@ -11,7 +11,8 @@
 if [ -e "/usr/bin/yum" ]; then
   PM=yum
   command -v lsb_release >/dev/null 2>&1 || { yum -y install redhat-lsb-core; clear; }
-elif [ -e "/usr/bin/apt-get" ]; then
+fi
+if [ -e "/usr/bin/apt-get" ]; then
   PM=apt
   command -v lsb_release >/dev/null 2>&1 || { apt-get -y update; apt-get -y install lsb-release; clear; }
 fi

+ 3 - 3
include/openssl.sh

@@ -8,7 +8,7 @@
 #       https://oneinstack.com
 #       https://github.com/lj2007331/oneinstack
 
-Install_openSSL102() {
+Install_openSSL() {
   if [ ! -e "${openssl_install_dir}/lib/libcrypto.a" ]; then
     pushd ${oneinstack_dir}/src > /dev/null
     tar xzf openssl-${openssl_ver}.tar.gz
@@ -19,11 +19,11 @@ Install_openSSL102() {
     make -j ${THREAD} && make install
     popd
     if [ -f "${openssl_install_dir}/lib/libcrypto.a" ]; then
-      echo "${CSUCCESS}openssl-1.0.2 module installed successfully! ${CEND}"
+      echo "${CSUCCESS}openssl installed successfully! ${CEND}"
       /bin/cp cacert.pem ${openssl_install_dir}/cert.pem
       rm -rf openssl-${openssl_ver}
     else
-      echo "${CFAILURE}openssl-1.0.2 install failed, Please contact the author! ${CEND}"
+      echo "${CFAILURE}openssl failed, Please contact the author! ${CEND}"
       kill -9 $$
     fi
     popd

+ 13 - 6
include/postgresql.sh

@@ -20,12 +20,19 @@ Install_PostgreSQL() {
   make install
   chmod 755 ${pgsql_install_dir}
   chown -R postgres.postgres ${pgsql_install_dir}
-  /bin/cp ./contrib/start-scripts/linux /etc/init.d/postgresql
-  sed -i "s@^prefix=.*@prefix=${pgsql_install_dir}@" /etc/init.d/postgresql
-  sed -i "s@^PGDATA=.*@PGDATA=${pgsql_data_dir}@" /etc/init.d/postgresql
-  chmod +x /etc/init.d/postgresql
-  [ "${PM}" == 'yum' ] && { chkconfig --add postgresql; chkconfig postgresql on; }
-  [ "${PM}" == 'apt' ] && update-rc.d postgresql defaults
+  if [ -e /bin/systemctl ]; then
+    /bin/cp ${oneinstack_dir}/init.d/postgresql.service /lib/systemd/system/
+    sed -i "s@=/usr/local/pgsql@=${pgsql_install_dir}@g" /lib/systemd/system/postgresql.service
+    sed -i "s@PGDATA=.*@PGDATA=${pgsql_data_dir}@" /lib/systemd/system/postgresql.service
+    systemctl enable postgresql
+  else
+    /bin/cp ./contrib/start-scripts/linux /etc/init.d/postgresql
+    sed -i "s@^prefix=.*@prefix=${pgsql_install_dir}@" /etc/init.d/postgresql
+    sed -i "s@^PGDATA=.*@PGDATA=${pgsql_data_dir}@" /etc/init.d/postgresql
+    chmod +x /etc/init.d/postgresql
+    [ "${PM}" == 'yum' ] && { chkconfig --add postgresql; chkconfig postgresql on; }
+    [ "${PM}" == 'apt' ] && update-rc.d postgresql defaults
+  fi
   popd
   su - postgres -c "${pgsql_install_dir}/bin/initdb -D ${pgsql_data_dir}"
   service postgresql start

+ 31 - 6
init.d/postgresql.service

@@ -1,14 +1,39 @@
 [Unit]
 Description=PostgreSQL database server
+After=network.target
 
 [Service]
-Type=notify
+Type=forking
+
 User=postgres
-ExecStart=/usr/local/pgsql/bin/postgres -D /data/pgsql
-ExecReload=/bin/kill -HUP $MAINPID
-KillMode=mixed
-KillSignal=SIGINT
-TimeoutSec=0
+Group=postgres
+
+# Where to send early-startup messages from the server (before the logging
+# options of postgresql.conf take effect)
+# This is normally controlled by the global default set by systemd
+# StandardOutput=syslog
+
+# Disable OOM kill on the postmaster
+OOMScoreAdjust=-1000
+# ... but allow it still to be effective for child processes
+# (note that these settings are ignored by Postgres releases before 9.5)
+Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
+Environment=PG_OOM_ADJUST_VALUE=0
+
+# Maximum number of seconds pg_ctl will wait for postgres to start.  Note that
+# PGSTARTTIMEOUT should be less than TimeoutSec value.
+Environment=PGSTARTTIMEOUT=270
+
+Environment=PGDATA=/data/pgsql
+
+ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
+ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
+ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
+
+# Give a reasonable amount of time for the server to start up/shut down.
+# Ideally, the timeout for starting PostgreSQL server should be handled more
+# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
+TimeoutSec=300
 
 [Install]
 WantedBy=multi-user.target

+ 1 - 1
install.sh

@@ -709,7 +709,7 @@ fi
 # openSSL
 . ./include/openssl.sh
 if [[ ${tomcat_option} =~ ^[1-4]$ ]] || [[ ${apache_option} =~ ^[1-2]$ ]] || [[ ${php_option} =~ ^[1-7]$ ]]; then
-  Install_openSSL102 | tee -a ${oneinstack_dir}/install.log
+  Install_openSSL | tee -a ${oneinstack_dir}/install.log
 fi
 
 # Database

+ 2 - 2
versions.txt

@@ -10,7 +10,7 @@ tomcat8_ver=8.5.34
 tomcat7_ver=7.0.91
 tomcat6_ver=6.0.53
 
-apache24_ver=2.4.35
+apache24_ver=2.4.37
 apache22_ver=2.2.34
 pcre_ver=8.42
 apr_ver=1.6.5
@@ -71,7 +71,7 @@ xcache_ver=3.2.0
 apcu_ver=4.0.11
 apcu_for_php7_ver=5.1.12
 eaccelerator_ver=0.9.6.1
-swoole_ver=4.2.1
+swoole_ver=4.2.5
 xdebug_ver=2.6.1
 
 # Ftp

+ 2 - 0
vhost.sh

@@ -246,6 +246,8 @@ EOF
       ~/.acme.sh/acme.sh --install-cert -d ${domain} --fullchain-file ${PATH_SSL}/${domain}.crt --key-file ${PATH_SSL}/${domain}.key --reloadcmd "${Command}" > /dev/null
     else
       echo "${CFAILURE}Error: Create Let's Encrypt SSL Certificate failed! ${CEND}"
+      [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ] && rm -f ${web_install_dir}/conf/vhost/${domain}.conf
+      [ -e "${apache_install_dir}/conf/vhost/${domain}.conf" ] && rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
       exit 1
     fi
   fi