Skip to content

Commit

Permalink
Add failure recovery options
Browse files Browse the repository at this point in the history
  • Loading branch information
koho committed Jun 3, 2020
1 parent 0ad492c commit dcab565
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ optional arguments:
--obj OBJ the account used to run the service
(default=LocalSystem)
--password PASSWORD password of the account
--failure-reset FAILURE_RESET
specifies the length of the period (in seconds) with
no failures after which the failure count should be
reset to 0 (zero).
--failure-command FAILURE_COMMAND
specifies the command-line command to be run when the
specified service fails.
--failure-actions FAILURE_ACTIONS
specifies one or more failure actions and their delay
times (in milliseconds), separated by a forward slash
(/). Valid actions are run, restart, and reboot.
```
When using `--arguments`, make sure you added a double quote around it. Here are some examples:
1. Create a service named `service1` with command line `python test.py log.txt`.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def readall(*args):

setup(
name='srvwrapper',
version='1.4',
version='1.5',
description='srvwrapper wraps any applications to run as Windows Service',
long_description=README,
long_description_content_type="text/markdown",
Expand Down
20 changes: 20 additions & 0 deletions srvwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def main():
parser.add_argument('--depend', dest='depend', help='dependencies(separated by / (forward slash))')
parser.add_argument('--obj', dest='obj', help='the account used to run the service (default=LocalSystem)')
parser.add_argument('--password', dest='password', help='password of the account')
parser.add_argument('--failure-reset', dest='failure_reset', help="specifies the length of the period (in seconds) "
"with no failures after which the failure count "
"should be reset to 0 (zero).", type=int)
parser.add_argument('--failure-command', dest='failure_command', help="specifies the command-line command to be run"
" when the specified service fails.")
parser.add_argument('--failure-actions', dest="failure_actions", help="specifies one or more failure actions and "
"their delay times (in milliseconds), "
"separated by a forward slash (/). "
"Valid actions are run, restart, and reboot.")

args = parser.parse_args()
if os.path.exists(args.program) and os.path.isfile(args.program):
Expand Down Expand Up @@ -56,6 +65,17 @@ def main():
print(command)
subprocess.check_call(command)

if any([args.failure_reset, args.failure_command, args.failure_actions]):
command = "sc failure %s " % args.name
if args.failure_reset:
command += "reset= %d " % args.failure_reset
if args.failure_command:
command += "command= %s " % args.failure_command
if args.failure_actions:
command += "actions= %s " % args.failure_actions
print(command)
subprocess.check_call(command)


if __name__ == '__main__':
main()

0 comments on commit dcab565

Please sign in to comment.