将脚本从 init 转换为 systemd

将脚本从 init 转换为 systemd

我将从 Ubuntu 11 迁移到 16,并且希望转换定制脚本以在 Ubuntu 16 上使用

我已经开始并完成了第一个初始化脚本但需要一些帮助第二个初始化脚本。我已经完成了其中的一部分,但无法在网上找到完成它的示例。

第一个初始化脚本
description "worker process to start multiple consumers - q9 mt03 local queue"
author      "mt dev team"

start on runlevel [2345]
stop on runlevel [!2345]

env NUM_WORKERS=20

pre-start script
  for i in `seq 1 $NUM_WORKERS`
  do
    start consumer-localhost N=$i
  done
end script
系统版本
### BEGIN INIT INFO 
Provides: localqueue 
Default-Start: 2 3 4 5 
Default-Stop: 0 1 6 
Short-Description: start and stop service rabbitmq servers 
Description: worker process to start multiple consumers - q9 mt03 local queue 

Environment NUM_WORKERS=20 
ExecStartPre 
for i in `seq 1 $NUM_WORKERS` 
do 
start consumer-localhost N=$i 
done 
ExecStopPost 
### END INIT INFO
第二个初始化脚本
description "consumer script as a service - q9 local queue"

author "mt dev team"

stop on stopping worker-localhost

instance $N

# Automatically Respawn:

respawn

respawn limit 70 5

pre-start script

# script to run before restart - notify or logging script

/bin/sh /root/consumer_restart_log.sh localhost pre-start

end script

script

exec /usr/bin/php /root/tracking/consumer.php localhost $N >>/var/log/aws_consumer_output.log 2>&1

end script

post-start script

# script to run before restart - notify or logging script

/bin/sh /root/consumer_restart_log.sh localhost post-start

end script
Systemd版本脚本
Description "Consumer script as a service "
author "mt dev"
Conflicts=worker-localhost

相关内容