<? xml version = "1.0"?>
<! DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type = 'manifest' name = 'nginx'>
<service
name = 'network / nginx'
type = 'service'
version = '1'>
<create_default_instance enabled = 'false' />
<single_instance />
<dependency name = 'loopback'
grouping = 'require_all'
restart_on = 'error'
type = 'service'>
<service_fmri value = 'svc: / network / loopback: default' />
</ dependency>
<dependency name = 'physical'
grouping = 'optional_all'
restart_on = 'error'
type = 'service'>
<service_fmri value = 'svc: / network / physical: default' />
</ dependency>
<dependency name = 'multiuser-server'
grouping = 'require_all'
restart_on = 'error'
type = 'service'>
<service_fmri value = 'svc: / milestone / multi-user-server: default' />
</ dependency>
<exec_method
type = 'method'
name = 'start'
exec = '/ opt / nginx / svc / nginx start'
timeout_seconds = '60 '/>
<exec_method
type = 'method'
name = 'stop'
exec = ': kill -QUIT'
timeout_seconds = '60 '/>
<exec_method
type = 'method'
name = 'refresh'
exec = '/ opt / nginx / svc / nginx refresh'
timeout_seconds = '60 '/>
<property_group name = 'nginx' type = 'application'>
<propval name = 'config' type = 'astring'
value = '/ opt / nginx / etc / nginx.conf' />
<propval name = 'pid' type = 'astring'
value = '/ opt / nginx / var / run / nginx.pid' />
</ property_group>
<property_group name = 'startd' type = 'framework'>
<! - core process dumps shouldn't restart
session ->
<propval name = 'ignore_error' type = 'astring'
value = 'core, signal' />
</ property_group>
<template>
<common_name>
<loctext xml: lang = 'C'>
Nginx HTTP server
</ loctext>
</ common_name>
<documentation>
<manpage title = 'nginx' section = '1M' />
<doc_link name = 'nginx.org'
uri = 'http: //www.nginx.org/' />
</ documentation>
</ template>
</ service>
</ service_bundle>
#! / sbin / sh
#
. /lib/svc/share/smf_include.sh
# SMF_FMRI is the name of the target service. This allows multiple instances
# to use the same script.
if [-z $ SMF_FMRI]; then
echo "SMF framework variables are not initialized."
exit $ SMF_EXIT_ERR
fi
getproparg () {
val = `svcprop -p $ 1 $ SMF_FMRI`
[-n "$ val"] && echo $ val
}
NGINX_HOME = / opt / nginx
HTTPD = "$ {NGINX_HOME} / sbin / nginx"
CONF_FILE = `getproparg nginx / config`
PIDFILE = `getproparg nginx / pid`
if [-z $ CONF_FILE]; then
echo "nginx / config property is not set"
exit $ SMF_EXIT_ERR_CONFIG
fi
if [-z $ PIDFILE]; then
echo "nginx / pid property is not set"
exit $ SMF_EXIT_ERR_CONFIG
fi
if [! -f $ {CONF_FILE}]; then
echo "nginx / config: could not find config file"
exit $ SMF_EXIT_ERR_CONFIG
fi
case "$ 1" in
start)
$ HTTPD -t -c $ {CONF_FILE} 2> & 1
if [$? -ne 0]; then
exit $ SMF_EXIT_ERR_CONFIG
fi
$ HTTPD -c $ {CONF_FILE} 2> & 1
;;
refresh)
if [-f "$ PIDFILE"]; then
/ usr / bin / kill -HUP `/ usr / bin / cat $ PIDFILE`
fi
;;
stop)
if [-f "$ PIDFILE"]; then
/ usr / bin / kill -KILL `/ usr / bin / cat $ PIDFILE`
fi
;;
*)
echo "Usage: $ 0 {start | stop | refresh}"
exit 1
;;
esac
exit $ SMF_EXIT_OK
# svccfg -v import nginx.xml svccfg: Taking "initial" snapshot for svc: / network / nginx: default. svccfg: Taking "last-import" snapshot for svc: / network / nginx: default. svccfg: Refreshed svc: / network / nginx: default. svccfg: Successful import.
# svcs nginx STATE STIME FMRI disabled 19:11:07 svc: / network / nginx: default
# svcadm -v enable nginx svc: / network / nginx: default enabled.
# svcs nginx STATE STIME FMRI maintenance 19:26:28 svc: / network / nginx: default
# svcs -x nginx
svc: / network / nginx: default (Nginx HTTP server)
State: maintenance since Thu Mar 24 19:26:28 2011
Reason: Start method exited with $ SMF_EXIT_ERR_CONFIG.
See: http://sun.com/msg/SMF-8000-KS
See: nginx (1M)
See: /var/svc/log/network-nginx:default.log
Impact: This service is not running.
[Mar 24 19:26:28 Enabled. ]
[Mar 24 19:26:28 Executing start method ("/ opt / nginx / svc / nginx start")]
nginx / config: could not find config file
[Mar 24 19:26:28 Method "start" exited with status 96]
# svcadm clear nginx
# svcs -x nginx
svc: / network / nginx: default (Nginx HTTP server)
State: online since Thu Mar 24 19:40:03 2011
See: nginx (1M)
See: /var/svc/log/network-nginx:default.log
Impact: None.
# ps -fe | grep nginx
root 5864 1 0 19:40:04? 0:00 / opt / nginx / sbin / nginx -c /opt/nginx/etc/nginx.conf
nobody 5865 5864 0 19:40:04? 0:00 / opt / nginx / sbin / nginx -c /opt/nginx/etc/nginx.conf
[Mar 24 19:40:03 Leaving maintenance because clear requested. ]
[Mar 24 19:40:03 Enabled. ]
[Mar 24 19:40:03 Executing start method ("/ opt / nginx / svc / nginx start")]
the configuration file /opt/nginx/etc/nginx.conf syntax is ok
configuration file /opt/nginx/etc/nginx.conf test is successful
[Mar 24 19:40:03 Method "start" exited with status 0]
[Mar 24 19:42:25 Stopping because all processes in service exited. ]
[Mar 24 19:42:25 Executing stop method (: kill)]
[Mar 24 19:42:25 Executing start method ("/ opt / nginx / svc / nginx start")]
the configuration file /opt/nginx/etc/nginx.conf syntax is ok
configuration file /opt/nginx/etc/nginx.conf test is successful
[Mar 24 19:42:25 Method "start" exited with status 0]
<instance name = 'default' enabled = 'false'>
<property_group name = 'nginx' type = 'application'>
<propval name = 'config' type = 'astring'
value = '/ opt / nginx / etc / nginx.conf' />
<propval name = 'pid' type = 'astring'
value = '/ opt / nginx / var / run / nginx.pid' />
</ property_group>
<property_group name = 'startd' type = 'framework'>
<! - core process dumps shouldn't restart
session ->
<propval name = 'ignore_error' type = 'astring'
value = 'core, signal' />
</ property_group>
</ instance>
# svccfg -v import nginx.xml svccfg: Taking "previous" snapshot for svc: / network / nginx: default. svccfg: Upgrading properties of svc: / network / nginx according to instance "default". svccfg: svc: / network / nginx: Deleting property group "nginx". svccfg: svc: / network / nginx: Deleting property group "general". svccfg: svc: / network / nginx: Deleting property group "startd". svccfg: Taking "last-import" snapshot for svc: / network / nginx: default. svccfg: Refreshed svc: / network / nginx: default. svccfg: Successful import.
<instance name = 'monitoring' enabled = 'false'>
<property_group name = 'nginx' type = 'application'>
<propval name = 'config' type = 'astring'
value = '/ opt / nginx / etc / nginx-munin.conf' />
<propval name = 'pid' type = 'astring'
value = '/ opt / nginx / var / run / nginx-munin.pid' />
</ property_group>
<property_group name = 'startd' type = 'framework'>
<! - core process dumps shouldn't restart
session ->
<propval name = 'ignore_error' type = 'astring'
value = 'core, signal' />
</ property_group>
</ instance>
# svccfg -v import nginx.xml svccfg: Taking "previous" snapshot for svc: / network / nginx: default. svccfg: Taking "previous" snapshot for new service svc: / network / nginx: monitoring. svccfg: Upgrading properties of svc: / network / nginx according to instance "default". svccfg: Taking "initial" snapshot for svc: / network / nginx: monitoring. svccfg: Taking "last-import" snapshot for svc: / network / nginx: monitoring. svccfg: Taking "last-import" snapshot for svc: / network / nginx: default. svccfg: Refreshed svc: / network / nginx: monitoring. svccfg: Refreshed svc: / network / nginx: default. svccfg: Successful import.
# svcs nginx STATE STIME FMRI disabled 20:16:31 svc: / network / nginx: monitoring online 20:16:31 svc: / network / nginx: default
# svcadm enable nginx svcadm: Pattern 'nginx' matches multiple instances: svc: / network / nginx: monitoring svc: / network / nginx: default # svcadm -v enable nginx: monitoring svc: / network / nginx: monitoring enabled.
# svccfg -s nginx add phpfpm # svccfg -s nginx: phpfpm addpg nginx application # svccfg -s nginx: phpfpm setprop nginx / config = astring: /opt/nginx/etc/fpm.conf # svccfg -s nginx: phpfpm setprop nginx / pid = astring: /opt/nginx/run/fpm.pid # svcadm disable nginx: phpfpm # This will add system properties automatically # svcs nginx STATE STIME FMRI disabled 20:37:30 svc: / network / nginx: phpfpm online 20:16:31 svc: / network / nginx: default online 20:21:09 svc: / network / nginx: monitoring
<method_context> <method_credential user = 'munin' group = 'munin' /> </ method_context>In the description of an instance or a separate method (if you only need to run a method from another user):
# ps -fe | grep nginx munin 6254 1 0 21:10:52? 0:00 / opt / nginx / sbin / nginx -c /opt/nginx/etc/nginx-munin.conf munin 6255 6254 0 21:10:52? 0:00 / opt / nginx / sbin / nginx -c /opt/nginx/etc/nginx-munin.conf root 5884 1 0 19:42:25? 0:00 / opt / nginx / sbin / nginx -c /opt/nginx/etc/nginx.conf nobody 6015 5884 0 21:05:04? 0:00 / opt / nginx / sbin / nginx -c /opt/nginx/etc/nginx.conf
# echo "solaris.munin ::: Munin authrization ::" >> / etc / security / auth_attr # usermod -A solaris.munin munin
munin @ sol2 $ / usr / sbin / svcadm restart nginx: monitoring svcadm: svc: / network / nginx: monitoring: Permission denied. munin @ sol2 $ / usr / sbin / svcadm disable nginx: monitoring svcadm: svc: / network / nginx: monitoring: Permission denied.
# svccfg -s nginx: monitoring setprop general / action_authorization = astring: solaris.munin # svcadm refresh nginx: monitoring
munin @ sol2 $ / usr / sbin / svcadm -v restart nginx: monitoring Action restart set for svc: / network / nginx: monitoring. munin @ sol2 $ / usr / sbin / svcadm -v disable nginx: monitoring svcadm: svc: / network / nginx: monitoring: Could not modify "general" property group (permission denied).
# svccfg -s nginx: monitoring setprop general / value_authorization = astring: solaris.munin # svcadm refresh nginx: monitoring
munin @ sol2 $ / usr / sbin / svcadm -v disable nginx: monitoring svc: / network / nginx: monitoring disabled. munin @ sol2 $ / usr / sbin / svcadm -v enable nginx: monitoring svc: / network / nginx: monitoring enabled.
Source: https://habr.com/ru/post/116224/
All Articles