以下以redis作为案例:
Description=redis-server
After=network.target
[Service]
Type=forking # 这里需要修改自己的配置文件
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
在/etc/init.d目录添加redis文件,然后给+x权限 注意:其中的chkconfig
一行必须要添加写入 chkconfig redis on 必须添加
#! /bin/bash
#
# redis
# chkconfig: 2345 10 90
case "$1" in start)
/usr/local/bin/redis-server /etc/redis/redis.conf > /tmp/redis.log 2>&1 &
;; stop)
redis_pid=$(ps -ef | grep redis-server | grep -v 'grep' | awk '{print $2}')
kill -9 $redis_pid
;; restart)
$0 stop
$0 start
;; status)
redis_pid=$(ps -ef | grep redis-server | grep -v 'grep' | awk '{print $2}')
if [ 0 -lt $redis_pid ]; then
echo "redis pid: ${redis_pid}"
else
echo "redis is dead"
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2 esac
exit
/etc/rc.local 添加+x权限 然后再文件中添加软件启动的命令
sudo redis-server /etc/redis/redis.conf > /tmp/redis.log 2>&1 & \