Pardus:Service Scripts
| Line 1: | Line 1: | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
= Service Scripts = | = Service Scripts = | ||
| Line 13: | Line 5: | ||
Service script, is a Python file like below. There are three methods. Two for starting and stopping service, one for giving status of service. Implementation of these three scripts is up to package maintainer. However, COMAR API package provides Service API, which contains useful methods for writing service scripts. | Service script, is a Python file like below. There are three methods. Two for starting and stopping service, one for giving status of service. Implementation of these three scripts is up to package maintainer. However, COMAR API package provides Service API, which contains useful methods for writing service scripts. | ||
| − | + | <pre>serviceType = "server" | |
| − | serviceDesc = _({ | + | serviceDesc = _({"en": "Server", |
| − | + | "tr": "Sunucu"}) | |
from comar.service import * | from comar.service import * | ||
| Line 21: | Line 13: | ||
@synchronized | @synchronized | ||
def start(): | def start(): | ||
| − | startService(command= | + | startService(command="/usr/bin/myserver", |
| − | args= | + | args="start", |
| − | pidfile= | + | pidfile="/var/run/sunucu.pid", |
donotify=True) | donotify=True) | ||
@synchronized | @synchronized | ||
def stop(): | def stop(): | ||
| − | stopService(command= | + | stopService(command="/usr/bin/myserver", |
| − | args= | + | args="stop", |
donotify=True) | donotify=True) | ||
def status(): | def status(): | ||
| − | return isServiceRunning( | + | return isServiceRunning("/var/run/myserver.pid") |
| − | + | </pre> | |
== serviceType == | == serviceType == | ||
| Line 48: | Line 40: | ||
== serviceDesc == | == serviceDesc == | ||
| − | + | <pre>serviceDesc = _({"en": "My Server", | |
| − | + | "tr": "Sunucum"})</pre> | |
This value is used by System.Service GUIs. '''_()''' is used for localization. | This value is used by System.Service GUIs. '''_()''' is used for localization. | ||
| Line 63: | Line 55: | ||
Arguments: | Arguments: | ||
| − | + | <pre>command : Application to execute [str] | |
args : Arguments (optional) [str] | args : Arguments (optional) [str] | ||
pidfile : PID file for application. (optional) [str] | pidfile : PID file for application. (optional) [str] | ||
| Line 73: | Line 65: | ||
donotify : Emit a System.Service.changed signal and notify all GUIs (optional) [True/False] | donotify : Emit a System.Service.changed signal and notify all GUIs (optional) [True/False] | ||
(This should be used. It's optional because some service scripts start more than one process.) | (This should be used. It's optional because some service scripts start more than one process.) | ||
| − | + | </pre> | |
=== stopService() === | === stopService() === | ||
| Line 79: | Line 71: | ||
Arguments: | Arguments: | ||
| − | + | <pre>pidfile : PID file of the running process (optional) [str] | |
command : Application to stop (optional) [str] | command : Application to stop (optional) [str] | ||
(Scans /proc and kills all running applications having that /path/to/name) | (Scans /proc and kills all running applications having that /path/to/name) | ||
args : Arguments (To stop application by calling it with an argument) (optional) [str] | args : Arguments (To stop application by calling it with an argument) (optional) [str] | ||
| − | (/proc won't be scanned, | + | (/proc won't be scanned, <command args> will be executed) |
chuid : Owner of the process. Format: user:group (optional) [str:str] | chuid : Owner of the process. Format: user:group (optional) [str:str] | ||
user : Username associated with process. (optional) [str] | user : Username associated with process. (optional) [str] | ||
| Line 89: | Line 81: | ||
donotify : Emit a System.Service.changed signal and notify all GUIs (optional) [True/False] | donotify : Emit a System.Service.changed signal and notify all GUIs (optional) [True/False] | ||
(This should be used. It's optional because some service scripts stop more than one process.) | (This should be used. It's optional because some service scripts stop more than one process.) | ||
| − | + | </pre> | |
Latest revision as of 14:10, 30 November 2010
Contents |
Service Scripts
Service scripts are Python scripts used by COMAR to manage system services and comes with PiSi packages. Any System.Service call made to Comar (start, stop, info, ...) will be handled by service scripts.
Service script, is a Python file like below. There are three methods. Two for starting and stopping service, one for giving status of service. Implementation of these three scripts is up to package maintainer. However, COMAR API package provides Service API, which contains useful methods for writing service scripts.
serviceType = "server"
serviceDesc = _({"en": "Server",
"tr": "Sunucu"})
from comar.service import *
@synchronized
def start():
startService(command="/usr/bin/myserver",
args="start",
pidfile="/var/run/sunucu.pid",
donotify=True)
@synchronized
def stop():
stopService(command="/usr/bin/myserver",
args="stop",
donotify=True)
def status():
return isServiceRunning("/var/run/myserver.pid")
serviceType
Possible values:
local: Local services server: Servers script: Scripts
This value is used to group services only.
serviceDesc
serviceDesc = _({"en": "My Server",
"tr": "Sunucum"})
This value is used by System.Service GUIs. _() is used for localization.
@synchronized Decorator
In boot sequence, service scripts can start other services. To prevent any race condition, @synchronized decorator should be used.
Service API
startService()
Arguments:
command : Application to execute [str]
args : Arguments (optional) [str]
pidfile : PID file for application. (optional) [str]
(Application won't be started if it's already running.)
makepid : If application doesn't create any PID file, API creates one. Generally used with ''detach'' argument (optional) [True/False]
nice : Niceness of process (optional) [int]
chuid : Owner of the process. Format: user:group (optional) [str:str]
detach : Fork process (optional) [True/False]
donotify : Emit a System.Service.changed signal and notify all GUIs (optional) [True/False]
(This should be used. It's optional because some service scripts start more than one process.)
stopService()
Arguments:
pidfile : PID file of the running process (optional) [str]
command : Application to stop (optional) [str]
(Scans /proc and kills all running applications having that /path/to/name)
args : Arguments (To stop application by calling it with an argument) (optional) [str]
(/proc won't be scanned, <command args> will be executed)
chuid : Owner of the process. Format: user:group (optional) [str:str]
user : Username associated with process. (optional) [str]
signalno : Signal to be sent to running process (optional) [int]
donotify : Emit a System.Service.changed signal and notify all GUIs (optional) [True/False]
(This should be used. It's optional because some service scripts stop more than one process.)