Can not use the start/stop service template

Hi i was trying to start/stop a service but returned errors:

CloseError: Service ‘service_name (service_name)’ cannot be stopped due to the following error: Cannot open service_name service on computer ‘.’.

i checked the connection is healthy
i checked no event in the event viewer
i checked the log file nothing captured
i used the start-service PS to start the service and it worked in my server with PS
i used the stop-service PS to stop the service and it worked in my server with PS

but they not working with OD. but once in the past it used to work.

Please suggest or provide a file sharing port so i can attach the event log

Good morning @rachel.dong,

Thank you for contacting Octopus Support and sorry to hear you are struggling to perform a PS command in Octopus.

You mentioned you tested this outside of Octopus and this worked, did you run the PowerShell session under the same account as your Octopus Tentacle is running on? I would hazard a guess that the account you are using for your Octopus Tentacle does not have the correct permissions to start or stop a service on that machine.

I have created you a secure link here you can send the task logs to, let me know once you have sent them over and I can take a look for you.

Kind Regards,
Clare

hi Clare, i uploaded the file…

Hey @rachel.dong,

Thank you for uploading the log and sorry it took some time to get back to you.

I took a look at the task log and unfortunately the only information it gives is what you have put in the original post:

CloseError: Service ‘service_name (service_name)’ cannot be stopped due to the following error: Cannot open service_name service on computer ‘.’.

I did some googling at this is not an Octopus error it is a windows error and it does seem like you need to run PowerShell or command prompt as an administrator (ie with elevated privileges) to start / stop a service, this is one of the articles I found.

I tested this on my local machine with my local admin account and if I don’t run the PowerShell session with elevated privileges I get the same error as you are seeing, if I ‘Run As Administrator’ it does stop the service.

Unfortunately there is not an easy way to change permissions of the session within the initial PowerShell window (ie Octopus itself will not run the PowerShell commands as an administrator) and it is very difficult to change a normal PowerShell session into an administrative one unless you do it within Windows itself (ie right click PowerShell and select Run As Administrator).

We have come across this a few times and we have not found a clean way of doing this (its a common bug bear on the internet) so unfortunately this is going to take some playing around on your end to get this to work.

Even if the service account you are using has Local Admin permissions on that machine you still need to run the PowerShell session as administrator in order to start / stop a service.

I did find this article (specifically near the end where it mentions Running PowerShell as Administrator with the Command Line, Creating a Batch File to Run PowerShell as Administrator and also Creating a Scheduled Task to Run PowerShell as Administrator, the latter seems to work for some people but you would need to speak to your security team as it may affect a security audit).

I do send that article to customers that have this issue so hopefully you find something useful in there but that is all I can provide I am afraid as this is a PowerShell limitation not Octopus.

I also found these three articles which mentions installing a tool and changing permissions of that individual service on that machine but I have not tested this. Check if you are allowed to download third party tools on your network.

I am sorry I cannot help you further here but hopefully some tinkering with the script will get you on the right track, if you do manage to get it working let us know as it will benefit other customers.

Kind Regards,
Clare

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.