cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5387
Views
5
Helpful
13
Comments
thecrev
Level 1
Level 1
If you are using Cisco's new linux-based Cisco Software Manager server, then you probably want to make sure there is a startup service for it.

I'll assume that you've already installed the CSM server on a systemd-based linux system. The commands given below were used in RedHat/CentOS. For purposes of this post, I'll use `/usr/local` as the csmserver install location, and `/usr/local/csm/csmserver/env` as the Python virtual envrionment location.

Getting started


If you're using a python virtual environment, then you'll need to explicitly tell the CSM server where your environment's python interpreter and gunicorn executable are. If anyone knows how to create the systemd service without having to do this, please share - because my attempts failed. If you aren't using a python virtual environment, you can skip to the next section where we create the systemd service.

- Open the file /usr/local/csm/csmserver/csmserver in your editor.
- Change the following line to include the absolute path to python in your virtual environment. Don't close the file yet.
# for Python interpreter
PYTHON="/usr/local/csm/csmserver/env/bin/python"

 

- Within the same file, add a variable for gunicorn in the appropriate section. Don't close the file yet.

# for gunicorn
GUNICORN="/usr/local/csm/csmserver/env/bin/gunicorn"

 

- In the 'function start_csmserver' and 'function start_secure_csmserver' sections, change each instance of `gunicorn` to `$GUNICORN`, to match our newly created variable. There should be one place to change in each section. Then save and close the csmserver file.

$GUNICORN -w $WORKERS -b $LISTENING_IP:$PORT --timeout $TIMEOUT --log-file=- csmserver:app & $PYTHON csmdispatcher.py &

$GUNICORN -w $WORKERS -b $LISTENING_IP:$PORT --timeout $TIMEOUT --log-file=- --keyfile=$SSLKEY --certfile=$SSLCERT  csmserver:app & $PYTHON csmdispatcher.py &

 

Creating the systemd service


- Create a new file in /usr/lib/systemd/system called csm.service

vi /usr/lib/systemd/system/csm.service


- Add the following to the file. Then save and close the csm.service file.

[Unit]
Description="Cisco Software Manager"
After=mysql.service

[Service]
WorkingDirectory=/usr/local/csm/csmserver
RemainAfterExit=yes
ExecStart=/usr/local/csm/csmserver/csmserver start
ExecStop=/usr/local/csm/csmserver/csmserver stop

[Install]
WantedBy=multi-user.target


- Reload the systemd daemon and set the service to start at boot

systemctl daemon-reload
systemctl enable csm.service


- Start the service. Be sure to verify that the service is active and that you can see the gunicorn and csmdispatcher.py processes.

systemctl start csm.service
systemctl status csm.service



Keep in mind that if you upgrade your CSM server in the future and you use a Python virtual environment, you'll need to go back in to the csmserver file and re-add the appropriate lines in the Getting Started section above.

That should be all you need to create your systemd service for the Cisco Software Manager server!

Comments
jawei
Cisco Employee
Cisco Employee

Hey I am from the CSM team. Thank you for sharing your notes and love it!

 

Can you please share the Centos version and MySQL version of your setup? Let's baseline the effort and see if we can automate it in the next release!

jawei
Cisco Employee
Cisco Employee

Hey Jason, I baselined these steps in both Centos 7.3 and 7.4 with and without virtualenv. They work really well! Thank you for sharing it!

 

Will try to include it in our next release with OVA package.

thecrev
Level 1
Level 1
Hey jawei,

I apologize for not getting back to you earlier.

Just for clarification, I am using CentOS 7.3.1611 and mysql 5.6.37

Thanks for doing this!
alvaro.orrego
Level 1
Level 1

Hello! I am trying to apply this on my ubuntu server 18.04 but I keep getting this  error:

 

oymtdf@csm01uio:/usr/local/csm/csmserver$ sudo systemctl enable csm.service
Synchronizing state of csm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable csm
update-rc.d: error: csm Default-Start contains no runlevels, aborting.

 

I am no linux expert, so any help is greatly appreciated.


Thanks!

jawei
Cisco Employee
Cisco Employee

Hi Alvaro,

 

The steps on Ubuntu 18.04 are nearly identical. The details are given below.

 

(1) Please make sure there is root access:

 

administrator@netbrain:~$ sudo -i
[sudo] password for administrator:
root@netbrain:~#

 

(2) Edit /usr/local/csm/csmserver/csmserver with the absolute paths to python and guicorn.

root@netbrain:/usr/local/csm/csmserver# which python
/usr/bin/python
root@netbrain:/usr/local/csm/csmserver# which gunicorn
/usr/local/bin/gunicorn

 

root@netbrain:/usr/local/csm/csmserver# diff csmserver csmserver~
28c28
< PYTHON="/usr/bin/python"
---
> PYTHON="python"
31d30
< GUNICORN="/usr/local/bin/gunicorn"
56c55
<     $GUNICORN -w $WORKERS -b $LISTENING_IP:$PORT --timeout $TIMEOUT --log-file=- csmserver:app &
---
>     gunicorn -w $WORKERS -b $LISTENING_IP:$PORT --timeout $TIMEOUT --log-file=- csmserver:app &
85c84
<     $GUNICORN -w $WORKERS -b $LISTENING_IP:$PORT --timeout $TIMEOUT --log-file=- --keyfile=$SSLKEY --certfile=$SSLCERT  csmserver:app &
---
>     gunicorn -w $WORKERS -b $LISTENING_IP:$PORT --timeout $TIMEOUT --log-file=- --keyfile=$SSLKEY --certfile=$SSLCERT  csmserver:app &

 

(3) Create /etc/systemd/system/csm.service as follows:

 

root@netbrain:/usr/local/csm/csmserver# cat /etc/systemd/system/csm.service
[Unit]
Description="Cisco Software Manager"

[Service]
WorkingDirectory=/usr/local/csm/csmserver
RemainAfterExit=yes
ExecStart=/usr/local/csm/csmserver/csmserver start
ExecStop=/usr/local/csm/csmserver/csmserver stop

[Install]
WantedBy=multi-user.target

 

(4) root@netbrain:/usr/local/csm/csmserver# systemctl daemon-reload
(5) root@netbrain:/usr/local/csm/csmserver# systemctl enable csm.service
Created symlink /etc/systemd/system/multi-user.target.wants/csm.service → /etc/systemd/system/csm.service.
(6) root@netbrain:/usr/local/csm/csmserver# systemctl start csm.service
(7) root@netbrain:/usr/local/csm/csmserver# systemctl status csm.service
● csm.service - "Cisco Software Manager"
   Loaded: loaded (/etc/systemd/system/csm.service; enabled; vendor preset: enabled)
   Active: active (exited) since Fri 2018-06-29 18:34:02 PDT; 8s ago
  Process: 15490 ExecStart=/usr/local/csm/csmserver/csmserver start (code=exited, status=0/SUCCESS)
 Main PID: 15490 (code=exited, status=0/SUCCESS)
    Tasks: 67 (limit: 4915)
   CGroup: /system.slice/csm.service
           ├─15494 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- csms
           ├─15495 /usr/bin/python csmdispatcher.py
           ├─15499 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- csms
           ├─15502 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- csms
           ├─15503 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- csms
           ├─15506 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- csms
           ├─15510 /usr/bin/python csmdispatcher.py
           ├─15514 /usr/bin/python csmdispatcher.py
           ├─15515 /usr/bin/python csmdispatcher.py
           ├─15516 /usr/bin/python csmdispatcher.py
           ├─15517 /usr/bin/python csmdispatcher.py
           ├─15520 /usr/bin/python csmdispatcher.py
           ├─15521 /usr/bin/python csmdispatcher.py
           ├─15534 /usr/bin/python csmdispatcher.py
           ├─15541 /usr/bin/python csmdispatcher.py
           ├─15548 /usr/bin/python csmdispatcher.py
           ├─15549 /usr/bin/python csmdispatcher.py
           ├─15550 /usr/bin/python csmdispatcher.py
           ├─15551 /usr/bin/python csmdispatcher.py
           ├─15552 /usr/bin/python csmdispatcher.py
           ├─15554 /usr/bin/python csmdispatcher.py
           ├─15557 /usr/bin/python csmdispatcher.py
           ├─15558 /usr/bin/python csmdispatcher.py
           ├─15571 /usr/bin/python csmdispatcher.py
           ├─15572 /usr/bin/python csmdispatcher.py
           ├─15573 /usr/bin/python csmdispatcher.py
           ├─15616 /usr/bin/python csmdispatcher.py
           ├─15626 /usr/bin/python csmdispatcher.py
           ├─15636 /usr/bin/python csmdispatcher.py
           ├─15637 /usr/bin/python csmdispatcher.py
           ├─15638 /usr/bin/python csmdispatcher.py
           ├─15640 /usr/bin/python csmdispatcher.py
           ├─15641 /usr/bin/python csmdispatcher.py
           ├─15642 /usr/bin/python csmdispatcher.py
           ├─15691 /usr/bin/python csmdispatcher.py
           ├─15705 /usr/bin/python csmdispatcher.py
           ├─15718 /usr/bin/python csmdispatcher.py
           ├─15719 /usr/bin/python csmdispatcher.py
           ├─15721 /usr/bin/python csmdispatcher.py
           └─15743 /usr/bin/python csmdispatcher.py

 

 

alvaro.orrego
Level 1
Level 1

Hello jawei

 

Thanks for the update! I followed your instructions, but unfortunately I still get the same "run-levels" error:

 

root@csm01uio:/usr/local/csm/csmserver# systemctl enable csm.service
Synchronizing state of csm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable csm
update-rc.d: error: csm Default-Start contains no runlevels, aborting.

 

 

I don't use a virtual environment. I do use https to access my csm server, so I replaced the ExecStart value with this:

 

ExecStart=/usr/local/csm/csmserver/csmserver start secure

 

When i do the systemctl start csm.service it does start manually and csm server works, but it fails to register to launch at boot. Maybe the code for ubuntu needs some run-level info that I (we) are not aware of?

 

Any other insight on what might be failing here? I appreciate any help you can give me. Thanks!

jawei
Cisco Employee
Cisco Employee

Hi Alvaro,

 

It looks to me the csm.service fails to come up after the Linux server reboot is because CSM server depends on mysqld, so that mysql.service has to be running first. Please add 'After=mysql.service' in /etc/systemd/system/csm.service and try again.

 

administrator@netbrain:/etc/systemd/system$ cat csm.service
[Unit]
Description="Cisco Software Manager"
After=mysql.service

[Service]
WorkingDirectory=/usr/local/csm/csmserver
RemainAfterExit=yes
ExecStart=/usr/local/csm/csmserver/csmserver start
ExecStop=/usr/local/csm/csmserver/csmserver stop

[Install]
WantedBy=multi-user.target

alvaro.orrego
Level 1
Level 1

Hi jawei,

 

I did exactly what you suggested, but I keep getting the following error when I try to enable the service on systemctl.

 

root@csm01uio:~# systemctl enable csm.service
Synchronizing state of csm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable csm
update-rc.d: error: csm Default-Start contains no runlevels, aborting.

 

I am not sure where the error is, but something is preventing me to enable it to run on boot, but not to run it manually:

 

root@csm01uio:~# systemctl start csm.service
root@csm01uio:~# systemctl is-active csm.service
active
root@csm01uio:~# systemctl status csm.service
● csm.service - "Cisco Software Manager"
Loaded: loaded (/etc/systemd/system/csm.service; disabled; vendor preset: enabled)
Active: active (exited) since Tue 2018-07-03 11:35:15 -05; 11s ago
Process: 1906 ExecStart=/usr/local/csm/csmserver/csmserver start secure (code=exited, status=0/SUCCESS)
Main PID: 1906 (code=exited, status=0/SUCCESS)
Tasks: 75 (limit: 4915)
CGroup: /system.slice/csm.service
├─1928 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- --keyfile=ssl.key --certfile=ssl.cert csmserver:app
├─1929 /usr/bin/python csmdispatcher.py
├─1934 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- --keyfile=ssl.key --certfile=ssl.cert csmserver:app
├─1935 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- --keyfile=ssl.key --certfile=ssl.cert csmserver:app
├─1936 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- --keyfile=ssl.key --certfile=ssl.cert csmserver:app
├─1937 /usr/bin/python /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 --log-file=- --keyfile=ssl.key --certfile=ssl.cert csmserver:app
├─1949 /usr/bin/python csmdispatcher.py
├─1953 /usr/bin/python csmdispatcher.py
├─1954 /usr/bin/python csmdispatcher.py
├─1956 /usr/bin/python csmdispatcher.py
├─1959 /usr/bin/python csmdispatcher.py
├─1963 /usr/bin/python csmdispatcher.py
├─1967 /usr/bin/python csmdispatcher.py
├─1971 /usr/bin/python csmdispatcher.py
├─1974 /usr/bin/python csmdispatcher.py
├─1978 /usr/bin/python csmdispatcher.py
├─1981 /usr/bin/python csmdispatcher.py
├─1982 /usr/bin/python csmdispatcher.py
├─1991 /usr/bin/python csmdispatcher.py
├─1998 /usr/bin/python csmdispatcher.py
├─2005 /usr/bin/python csmdispatcher.py
├─2006 /usr/bin/python csmdispatcher.py
├─2007 /usr/bin/python csmdispatcher.py
├─2012 /usr/bin/python csmdispatcher.py
├─2014 /usr/bin/python csmdispatcher.py
├─2038 /usr/bin/python csmdispatcher.py
├─2048 /usr/bin/python csmdispatcher.py
├─2058 /usr/bin/python csmdispatcher.py
├─2060 /usr/bin/python csmdispatcher.py
├─2062 /usr/bin/python csmdispatcher.py
├─2068 /usr/bin/python csmdispatcher.py
├─2075 /usr/bin/python csmdispatcher.py
├─2082 /usr/bin/python csmdispatcher.py
├─2090 /usr/bin/python csmdispatcher.py
├─2098 /usr/bin/python csmdispatcher.py
├─2124 /usr/bin/python csmdispatcher.py
├─2132 /usr/bin/python csmdispatcher.py
├─2136 /usr/bin/python csmdispatcher.py
├─2160 /usr/bin/python csmdispatcher.py
├─2173 /usr/bin/python csmdispatcher.py
├─2186 /usr/bin/python csmdispatcher.py
├─2187 /usr/bin/python csmdispatcher.py
├─2189 /usr/bin/python csmdispatcher.py
└─2224 /usr/bin/python csmdispatcher.py 

 

Thanks a lot for all your help!

jawei
Cisco Employee
Cisco Employee

Hi Alvaro,

 

I received a different message when I enabled csm.service:

 

root@netbrain:~# systemctl enable csm.service
Created symlink /etc/systemd/system/multi-user.target.wants/csm.service → /etc/systemd/system/csm.service.

Please make sure that you have created 'csm.service' in '/etc/systemd/system/', and not in '/usr/lib/systemd/system', as the original post had Centos/RHEL while your current platform is Ubuntu 18.04.

 

The other place to look for is to make sure that systemd init is not confused with the old SysV init script (/etc/init.d). It is hard for me to pinpoint the exact root cause. Please see if the following article is helpful?

 

https://serverfault.com/questions/849507/systemctl-doesnt-recognize-my-service-default-start-contains-no-runlevels-abo

alvaro.orrego
Level 1
Level 1

Hello jawei,

 

I finally made it work! After reviewing all the info you sent and reading the other post you recommended I found out that in my previous attempt (long time ago) to make csm run at boot, I created a csm file on /etc/init.d/ and never got rid of it. Once I did, it worked like a charm!

 

Thank you for all your help to this non linux expert :) It was much appreciated!

DAZN_Network
Level 1
Level 1

Hi,

 

I have an issue with csmdispatcher.py not starting when the system boots (I'm using virtualenv btw).

 

if after rebooting I manually run "sudo systemctl stop csm.service" and "sudo systemctl start csm.service" the csmdispatcher.py instances start fine and everything works.

 

Doesn't seem to be permission related.

 

Any idea what could be wrong?

 

Thanks


Rocco

thecrev
Level 1
Level 1

Hey @DAZN_Network

 

Are you running Ubuntu, RedHat, something else?

 

Did you check out some of jawei's comments? (especially if you are running Ubuntu)

 

 

 

DAZN_Network
Level 1
Level 1

Hello @thecrev,

 

I'm using CentOS 7.5, I just fixed the issue by adding "After=mysql.service" to the csm.service file.

 

Thanks for bringing that to my attention.

 

Regards

 

Rocco

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links