本文简单讲解如何在centos7中使用systemd管理自定义服务,仅供学习与交流,请勿用于商业用途。
在centos6中,在/etc/rc.local添加自定义可执行脚本,将会在用户登录之后执行
例如,启动编译安装的redis
echo "/usr/local/redis/bin/redis-server" >> /etc/rc.local
在centos7以及之后版本,提供了systemd服务,可以方便的管理各种服务。
而/etc/rc.d/rc.local该文件权限已经被降低,去掉了执行权限,默认无法使用,详细如下。看不懂英语的童鞋请自行使用翻译软件。
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local