如果 upstart 脚本中不存在,如何创建文件夹

How to create folder if not exists in upstart script

这是我在 /etc/init/

中的配置文件
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
# Automatically restart service
respawn
respawn limit 99 5
script
    mkdir /var/log/my_task
    <my task which log to /var/log/my_task>
end script

问题是服务每次都会尝试创建文件夹。 仅当文件夹不存在时如何运行命令?

此代码适合您:

   start on local-filesystems
   stop on runlevel [!2345]
   respawn limit 99 5
   script
   if [ ! -e /var/log/my_task ]; then
     /bin/mkdir  /var/log/my_task
   fi
   end script