CentOS7系统服务脚本编写

    最近开始把玩CentOS 7,发现之前的部分服务启动脚本在新版OS中运行异常(报错),特意摸索了下,个人感觉7的服务自启动脚本编写非常简单方便。
# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx – high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
# systemctl status nginx.service 查看服务当前状态
# systemctl enable nginx.service 设置开机自启动
# systemctl list-units –type=service 查看所有已启动的服务

# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
#PrivateTmp=true
[Install]
WantedBy=multi-user.target
# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm start
ExecReload=/usr/local/php/sbin/php-fpm restart
ExecStop=/usr/local/php/sbin/php-fpm stop
#PrivateTmp=true
[Install]
WantedBy=multi-user.target

Leave a Comment

Your email address will not be published. Required fields are marked *

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据