4

jsvc を使用してデーモン プロセスを作成しようとしていますが、特定のことを root として実行できるようです (たとえば、Tomcat は明らかに特権ポートにバインドできます)。私が疑問に思っているのは、それをどのように行うかです。

私の単純なデーモン プログラムでは、プロセス中にルートとしてのみ読み取り可能ないくつかのファイルを開こうとしますがinit()、それまでに選択したユーザー (私の場合は "nobody") として既に実行されています。Tomcat が特権ポートにバインドできる場合、ルート所有の構成ファイルを開くことができるはずです。

jsvc が意図していないことをしようとしているのですか、それとも単に何かが足りないのですか?

私のコード:

public class MediaProcessorDaemon implements Daemon {

    ClassPathXmlApplicationContext spring = null;

    /*- (non-Javadoc)
     * @see org.apache.commons.daemon.Daemon#init(org.apache.commons.daemon.DaemonContext)
     */
    @Override
    public void init(DaemonContext context) throws DaemonInitException, Exception {
        /* This next line throws an exception */
        this.spring = new ClassPathXmlApplicationContext("/META-INF/spring/media-processor-context.xml");
    }

    /*- (non-Javadoc)
     * @see org.apache.commons.daemon.Daemon#start()
     */
    @Override
    public void start() throws Exception {
        this.spring.start();
    }

    /*- (non-Javadoc)
     * @see org.apache.commons.daemon.Daemon#stop()
     */
    @Override
    public void stop() throws Exception {
        if (this.spring != null) {
            this.spring.stop();
        }
    }

    /*- (non-Javadoc)
     * @see org.apache.commons.daemon.Daemon#destroy()
     */
    @Override
    public void destroy() {
        if (this.spring != null) {
            this.spring.close();
        }
    }
}

そしてエラーメッセージ:

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: /etc/media/media-processor.properties (Permission denied)
        at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:663)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:638)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at com.mycompany.mediaprocessor.MediaProcessorDaemon.init(MediaProcessorDaemon.java:24)
[snip]

init()、ルート (/etc/media/media-processor.properties) のみが読み取り可能なファイルを開こうとすると、「許可が拒否されました」というメッセージが表示されます。

私は次のように実行します:

sudo jsvc -debug -user nobody -cp $classPath com.mycompany.MediaProcessorDaemon
4

0 に答える 0