使用Solaris SMF作为非root用户运行Java应用程序

时间:2014-07-14 09:28:58

标签: java solaris solaris-10 smf

我正在使用Solaris SMF作为Non Root用户运行我的应用程序,我按照以下步骤进行操作

1-创建如下文件

    <?xml version='1.0'?>
    <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
    <service_bundle type="manifest" name="myapp">
         <service name="application/management/myapp" type="service" version="1">
    <create_default_instance enabled="false" />
    <single_instance />
    <dependency name="multi-user-server" type="service" grouping="require_all" restart_on="none">
    <service_fmri value="svc:/milestone/multi-user-server" />
    </dependency>             
    <exec_method type="method" name="start"     exec="/opt/bin/myapp.sh start" timeout_seconds="-1">
    <method_context>
       <method_credential user='myuser' group='other' />
           <method_environment>
    <envvar name='PATH' value='/usr/bin:/usr/sbin:/usr/ccs/bin:/usr/local/bin:/usr/local/sbin:/usr/sfw/bin' />
    <envvar name='JAVA_HOME' value='/usr/java/' />
       </method_environment>
    </method_context>
    </exec_method>

    <exec_method type="method" name="stop"      exec="/opt/bin/myapp.sh stop" timeout_seconds="-1">
    <method_context>
    <method_credential user='myuser' group='other' />
      <method_environment>
    <envvar name='PATH' value='/usr/bin:/usr/sbin:/usr/ccs/bin:/usr/local/bin:/usr/local/sbin:/usr/sfw/bin' />
    <envvar name='JAVA_HOME' value='/usr/java/' />
      </method_environment>
    </method_context>
    </exec_method>

    <property_group name='start' type='method'>
    <propval name='action_authorization' type='astring' value='solaris.smf.manage.myapp'      />
    <propval name='modify_authorization' type='astring' value='solaris.smf.manage.myapp' />
    <propval name='value_authorization'  type='astring'  value='solaris.smf.manage.myapp' />
    </property_group>
    <property_group name='stop' type='method'>
    <propval name='action_authorization' type='astring' value='solaris.smf.manage.myapp'  />
    <propval name='modify_authorization' type='astring' value='solaris.smf.manage.myapp'   />
    <propval name='value_authorization'  type='astring' value='solaris.smf.manage.myapp'  />
    </property_group>
    <property_group name='general' type='framework'>
    <propval name='action_authorization' type='astring' value='solaris.smf.manage.myapp' />
    <propval name='value_authorization'  type='astring' value='solaris.smf.manage.myapp' />
    <propval name='modify_authorization' type='astring' value='solaris.smf.manage.myapp' />
    </property_group>
    <stability value="Unstable" />
    <template>
    <common_name>
    <loctext xml:lang='C'>My Application</loctext>
    </common_name>
    </template>
         </service>
    </service_bundle>

2- svccfg验证myapp-smf.xml

3-在/ etc / security / auth_attr中添加行 solaris.smf.manage.myapp ::: MyApp Management ::

4- usermod -A solaris.smf.manage.myapp myuser(确保myuser未登录)

5- svccfg import /opt/smf/myapp-smf.xml

现在以myuser身份登录并使用以下命令验证/启动/停止应用程序

svcs -l myapp

svcadm enable myapp
svcadm disable myapp

现在问题是第二天当我尝试从我的用户启用/禁用我得到权限被拒绝错误。

我再次运行usermod -A solaris.smf.manage.myapp myuser,它开始工作,我正在寻找永久修复。

此致

1 个答案:

答案 0 :(得分:0)

usermod -A solaris.smf.manage。* myuser将解决问题