找不到〜/ .init /中的用户upstart作业
运行12.04,我在~/.init/
有以下upstart作业:
# myjob start on net-device-up stop on [!12345] script echo ">> hello from user script" >> ~/tmp/upstart.log end script
重启我的机器后
service myjob start # => myjob: unrecognised service
initctl
确实列出了作业,但是在没有sudo的情况下运行它会引发错误:
initctl start myjob # => initctl: Rejected send message, 1 matched rules; type="method_call", sender=":1.100" (uid=1000 pid=13349 comm="initctl start thunderbird ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
我希望能够在不使用sudo
情况下使用service
或initctl
启动作业。 我误解了什么?
谢谢
几点:
-
默认情况下,Ubuntu中未启用用户作业。 看到:
-
创建任何类型的Upstart作业后,您永远不需要重新启动 – Upstart会自动检测它们(使用inotify)。
-
service
命令不是Upstart的一部分 – 它是操作SysV作业的SystemV工具。 但是,Upstart提供SystemV兼容性,以便Upstart系统作业也可以通过service
进行操作(为方便起见)。 Upstart等效命令是start
,stop
和restart
。 -
对于用户作业,您必须使用
start
,stop
和restart
(或initctl
等效项)。
最后,请注意用户作业目前非常基础。 我们计划在12月10日大幅提升它们,但现在请注意:
- 无论您默认使用哪个shell,Upstart都将使用
/bin/sh -e
运行所有用户作业。 那个-e
也很重要(详见man sh
)。 -
Upstart仅在用户作业环境中设置最小的变量集。 因此,你应该像这样设置像
HOME
这样的变量:env HOME=/home/james
看到: