Centos7下源編譯安裝Postgresql 並設置開機自動啟動postgresql.serivce 服務相關研究


 

編寫開機自動啟動服務腳本:

# cat >> /usr/lib/systemd/system/postgresql.service >> EOF

[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking

User=postgres
Group=postgres

# Port number for server to listen on
Environment=PGPORT=5432

# Location of database directory
Environment=PGDATA=/usr/local/pgsql9.4/data

# 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

#ExecStartPre=/usr/local/pgsql9.4/bin/postgresql-check-db-dir ${PGDATA}
ExecStart=/usr/local/pgsql9.4/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/usr/local/pgsql9.4/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pgsql9.4/bin/pg_ctl reload -D ${PGDATA} -s

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

[Install]
WantedBy=multi-user.target

EOF

 

添加可執行權限:

chmod 754 /usr/lib/systemd/system/postgresql.service

 

設置為開機自啟動:

systemctl enable postgresql.service

 

常用指令(以postgresql服務為例):

啟動某服務: 

systemctl  start  postgresql.service

停止某服務:

systemctl stop postgresql.service

重啟某服務:

systemctl restart postgresql.service
service postgresql restart

使某服務自動啟動(如tomcat服務):

systemctl enable postgresql.service

使某服務不自動啟動:

systemctl disable postgresql.service

檢查服務狀態:

systemctl   status  postgresql.service (服務詳細信息)
systemctl   is-active postgresql.service(僅顯示是否Active)

顯示所有已啟動的服務:

systemctl   list-units --type=service

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM