ubuntu 伺服器,嘗試啟動服務/守護程式

ubuntu 伺服器,嘗試啟動服務/守護程式

我按照說明進行操作這裡,但是當我輸入“sudo service mydaemon start”時。我收到“mydaemon:無法識別的服務”。我已經驗證這些文件位於正確的位置,並且我採取了額外的步驟使我的腳本文件(echoHW.sh)可執行,但仍然沒有成功。任何幫助將不勝感激。

答案1

我輸入sudo crontab -e並選擇nano作為我的編輯。它提出了 Nano 並發表了以下評論。我在底部添加了腳本,然後重新啟動。現在,只要係統啟動,我的任務就會運作。

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
@reboot /path/to/script.sh

答案2

您是否找到並嘗試執行/etc/init.d/(服務名稱)中的服務?

我不熟悉在不實際運行位於init.d 資料夾下的shell 程式的情況下調用服務,但我確信如果啟動服務的shell 程式位於init.d 下,那麼它應該是一個簡單的設置,因此您可以這樣呼叫它你希望 - “service mydaemon [指令]”

答案3

如果腳本不可執行,則可能會出現該錯誤

sudo chmod +x /etc/init.d/mydaemon

答案4

您在路由器上設定了連接埠轉送嗎?如果沒有,請設定連接埠轉送和靜態 IP 位址 + DNS(您需要從 DNS 提供者取得或擁有自己的 DNS 伺服器)。轉送連接埠這裡。

相關內容