服务及业务模块开机自启动脚本
进入/lib/systemd/system目录, 创建nacos.service文件;
nacos.service:
[Unit] Description=nacos After=network.target After=network-online.target Wants=network-online.target [Service] Type=forking ExecStart=/bin/bash /data/nacos/bin/startup.sh ExecReload=/bin/bash /data/nacos/bin/shutdown.sh ExecStop=/bin/bash /data/nacos/bin/shutdown.sh PrivateTmp=true [Install] WantedBy=multi-user.target
执行命令(通用):
1. 重新加载所有service服务 systemctl daemon-reload 2. 开机启动nacos.service systemctl enable nacos.service 3. 查看该service是否开机启用 systemctl is-enabled nacos.service 4. 启动该服务 systemctl start nacos.service 5. 查看该服务状态 systemctl status nacos.service
nginx.service:
[Unit] Description=nginx service After=network.target After=network-online.target Wants=network-online.target [Service] Type=forking ExecStart=/data/nginx/sbin/nginx ExecReload=/data/nginx/sbin/nginx -s reload ExecStop=/data/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
redis.service:
[Unit] Description=The redis-server Process Manager After=syslog.target network.target After=network-online.target Wants=network-online.target [Service] Type=forking User=root PIDFile=/run/redis_6380.pid ExecStart=/data/redis_cluster/6380/bin/redis-server /data/redis_cluster/6380/bin/redis.conf ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target
业务模块自启动:
#!/bin/bash #chkconfig: 234 99 01 #description: nstc export JAVA_HOME=/data/jdk1.8.0_201_linux export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin /bin/bash /data/nsg/bin/start.sh /bin/bash /data/gts-service/bin/restart.sh
添加配置:
--业务服务自启动
#赋权 chmod +x /etc/init.d/autoStart
#添加到服务列表 chkconfig --add autoStart
#查看服务列表 chkconfig --list
#开启权限 chkconfig --level 2345 autoStart on