如何在啟動時在/var/run中建立目錄?

如何在啟動時在/var/run中建立目錄?

我需要在 /var/run 中建立一個非 root 擁有的目錄,/etc/init.d 中的啟動腳本將使用該目錄。實現這一目標的正確方法是什麼?我使用的是 Ubuntu 14.04。

答案1

您需要即時執行此操作。/var/run/是一個 tmpfs,因此每次啟動時都會重新建立。

從初始化腳本:

  • 在裡面建立一個目錄/var/run/並更改該使用者的權限。
  • 然後指定使用/var/run/mydaemon而不是/var/run.

如果您想要有關如何進行此檢查的範例(還有更多):

/etc/init.d/ssh
/etc/init.d/bind9
/etc/init/dbus.conf
/etc/init/ssh.conf
/etc/init/cups.conf

他們都有某種東西mkdir在裡面。杯.conf:

mkdir -p /var/run/cups/certs

/etc/init/cups.conf

pre-start script
    [ -x /usr/sbin/cupsd ]

    # load modules for parallel port support
    if [ -r /etc/default/cups ]; then
    . /etc/default/cups
    fi
    if [ "$LOAD_LP_MODULE" = "yes" -a -f /usr/lib/cups/backend/parallel \
     -a -f /proc/modules -a -x /sbin/modprobe ]; then
    modprobe -q -b lp || true
    modprobe -q -b ppdev || true
    modprobe -q -b parport_pc || true
    fi

    mkdir -p /var/run/cups/certs
    if [ -x /lib/init/apparmor-profile-load ]; then
    /lib/init/apparmor-profile-load usr.sbin.cupsd
    fi
end script

相關內容