Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
multibot
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
social
multibot
Commits
f4cb1c6e
Commit
f4cb1c6e
authored
Oct 27, 2016
by
nextime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Starter
parent
cfdcc86a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
137 additions
and
0 deletions
+137
-0
multibotd
multibotd
+137
-0
No files found.
multibotd
View file @
f4cb1c6e
#!/usr/bin/env python
###########################################################################
# Copyright (c) 2016-2017 Franco (nextime) Lanza <nextime@nexlab.it>
#
# Multibot daemon
#
# This file is part of multibot.
#
# multibot2 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from
twisted.internet
import
epollreactor
epollreactor
.
install
()
import
logging
,
time
,
sys
,
os
CURDIR
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
sys
.
path
.
append
(
CURDIR
+
"/multibot/libs"
)
from
twisted.internet
import
reactor
,
ssl
from
twisted.application
import
service
,
internet
,
app
,
reactors
from
twisted.web
import
server
from
multibot.utils.daemonizer
import
Daemonizer
from
multibot
import
multibot
from
multibot.utils.genutils
import
configFile
from
logging
import
handlers
as
loghandlers
try
:
import
setproctitle
setproctitle
.
setproctitle
(
'multibotd'
)
print
'Setting process title to'
,
sys
.
argv
[
0
]
except
:
pass
loglevels
=
{
'info'
:
logging
.
INFO
,
'warning'
:
logging
.
WARNING
,
'error'
:
logging
.
ERROR
,
'critical'
:
logging
.
CRITICAL
,
'debug'
:
logging
.
DEBUG
}
LOGLEN
=
26214400
# 25 mega
class
MultibotDaemon
(
Daemonizer
):
def
__init__
(
self
):
self
.
curdir
=
CURDIR
log
.
debug
(
"Reading daemon Config file"
)
self
.
daemoncfg
=
configFile
(
self
.
curdir
+
'/conf/multibotd.conf'
)
self
.
daemoncfg
.
readConfig
()
log
.
debug
(
"Daemonizing process"
)
Daemonizer
.
__init__
(
self
,
self
.
curdir
+
'/run/multibotd.pid'
)
def
main_loop
(
self
):
log
.
debug
(
"Main loop called"
)
application
=
service
.
Application
(
"multibotd"
)
MULTIBOTServerService
=
multibot
.
MultibotService
(
'multibotd'
,
curdir
=
self
.
curdir
,
config
=
self
.
daemoncfg
)
serviceCollection
=
service
.
IServiceCollection
(
application
)
MULTIBOTServerService
.
setServiceParent
(
serviceCollection
)
WebAuthServer
=
MULTIBOTServerService
.
getAuthWebServer
()
WebRedirect
=
MULTIBOTServerService
.
getWebRedirect
()
privkey
=
self
.
daemoncfg
.
get
(
'web'
,
'privkey'
)
cacert
=
self
.
daemoncfg
.
get
(
'web'
,
'cacert'
)
if
not
privkey
.
startswith
(
'/'
):
privkey
=
"/"
.
join
([
self
.
curdir
,
privkey
])
if
not
cacert
.
startswith
(
'/'
):
cacert
=
"/"
.
join
([
self
.
curdir
,
cacert
])
sslContext
=
DomoSSLContext
(
privkey
,
cacert
)
if
str
(
self
.
daemoncfg
.
get
(
'web'
,
'enable'
))
.
lower
()
in
[
'yes'
,
'1'
,
'y'
,
'true'
]:
reactor
.
listenSSL
(
int
(
self
.
daemoncfg
.
get
(
'web'
,
'sslport'
)),
WebAuthServer
,
contextFactory
=
sslContext
,
interface
=
str
(
self
.
daemoncfg
.
get
(
'web'
,
'interface'
)))
reactor
.
listenTCP
(
int
(
self
.
daemoncfg
.
get
(
'web'
,
'port'
)),
WebRedirect
,
interface
=
str
(
self
.
daemoncfg
.
get
(
'web'
,
'interface'
)))
log
.
debug
(
"Running reactor"
)
reactor
.
callWhenRunning
(
MULTIBOTServerService
.
isStarted
)
reactor
.
run
()
if
__name__
==
"__main__"
:
# Starting all loggers
# file di log da 100 mega, per 5 rotazioni
formatter
=
logging
.
Formatter
(
'
%(asctime)
s =>
%(name)-12
s:
%(levelname)-8
s
%(message)
s'
)
logdict
=
{
"corelog"
:
{
"file"
:
"multibotd.log"
,
"name"
:[(
"Core"
,
"general"
)]},
"weblog"
:
{
"file"
:
"web.log"
,
"name"
:[(
"Proxy"
,
"proxy"
),(
"Webgui"
,
"web"
)]}
}
for
l
in
logdict
.
keys
():
logdict
[
l
][
"handler"
]
=
loghandlers
.
RotatingFileHandler
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
+
'/logs/'
+
logdict
[
l
][
"file"
],
'a'
,
LOGLEN
,
5
)
logdict
[
l
][
"handler"
]
.
setLevel
(
logging
.
DEBUG
)
logdict
[
l
][
"handler"
]
.
setFormatter
(
formatter
)
logging
.
basicConfig
()
log
=
logging
.
getLogger
(
'DaemonStarter'
)
log
.
addHandler
(
logdict
[
"corelog"
][
"handler"
])
log
.
setLevel
(
logging
.
INFO
)
curdir
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
daemoncfg
=
configFile
(
curdir
+
'/conf/multibotd.conf'
)
daemoncfg
.
readConfig
()
for
l
in
logdict
.
keys
():
for
n
in
logdict
[
l
][
"name"
]:
lh
=
logging
.
getLogger
(
n
[
0
])
lh
.
setLevel
(
loglevels
[
daemoncfg
.
get
(
n
[
1
],
'loglevel'
)]
)
lh
.
addHandler
(
logdict
[
l
][
"handler"
]
)
logging
.
basicConfig
()
# staring the application
if
len
(
sys
.
argv
)
>
1
:
log
.
debug
(
"Starting daemon with option "
+
sys
.
argv
[
1
])
MultibotDaemon
()
.
process_command_line
(
sys
.
argv
)
else
:
print
'Please specify start, stop or debug option'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment