Skip to content

Commit c38d9fe

Browse files
committed
Handle the server name in _expand_user_vars
1 parent 56602aa commit c38d9fe

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

systemdspawner/systemdspawner.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class SystemdSpawner(Spawner):
5353
).tag(config=True)
5454

5555
unit_name_template = Unicode(
56-
'jupyter-{USERNAME}-singleuser',
56+
'jupyter-{USERNAME}-singleuser-{SERVERNAME}',
5757
help="""
5858
Template to use to make the systemd service names.
5959
60-
{USERNAME} and {USERID} are expanded}
60+
{USERNAME}, {SERVERNAME}, and {USERID} are expanded}
6161
"""
6262
).tag(config=True)
6363

@@ -137,13 +137,6 @@ class SystemdSpawner(Spawner):
137137
"""
138138
).tag(config=True)
139139

140-
append_name = Bool(
141-
True,
142-
help="""
143-
Append -{self.name} to the unit if using c.JupyterHub.allow_named_servers
144-
"""
145-
).tag(config=True)
146-
147140
slice = Unicode(
148141
None,
149142
allow_none=True,
@@ -158,8 +151,6 @@ def __init__(self, *args, **kwargs):
158151
super().__init__(*args, **kwargs)
159152
# All traitlets configurables are configured by now
160153
self.unit_name = self._expand_user_vars(self.unit_name_template)
161-
if self.append_name and self.name:
162-
self.unit_name = self.unit_name + '-' + self.name
163154

164155
self.log.debug('user:%s Initialized spawner with unit %s', self.user.name, self.unit_name)
165156

@@ -170,11 +161,14 @@ def _expand_user_vars(self, string):
170161
Currently expands:
171162
{USERNAME} -> Name of the user
172163
{USERID} -> UserID
164+
{SERVERNAME} -> Name of the server (self.name)
173165
"""
166+
# Strip the trailing - if we don't have a name.
174167
return string.format(
175168
USERNAME=self.user.name,
176169
USERID=self.user.id
177-
)
170+
SERVERNAME=self.name
171+
).rstrip('-')
178172

179173
def get_state(self):
180174
"""

0 commit comments

Comments
 (0)